Skip to content

Instantly share code, notes, and snippets.

View ybakos's full-sized avatar
💭
the machine stops the machine stops the machine stops

Yong Joseph Bakos ybakos

💭
the machine stops the machine stops the machine stops
View GitHub Profile
@ybakos
ybakos / translator.py
Created March 27, 2014 15:56
The Hack VM in Python, step 1: parsing command-line arguments and preparing filenames.
#!/usr/bin/env python3
# Yong Bakos
# A Python implementation of the Hack VM Translator. Whee!
import sys
import os
class Translator:
float theta = 0.0;
void setup() {
size(750, 300, P3D);
}
void draw() {
background(33);
stroke(0);
fill(200);
void drawTriangles(int size) {
beginShape(TRIANGLES);
fill(150, 0, 0, 127);
vertex(-size, -size, -size);
vertex(size, -size, -size);
vertex(0, 0, size);
fill(0, 150, 0, 127);
vertex(size, -size, -size);
vertex(size, size, -size);
vertex(0, 0, size);
// Learning Processing Exercise 16-7. Finding the average location of motion, indicated with a circle.
import processing.video.*;
Capture video;
PImage previousFrame;
final float THRESHOLD = 100.0;
void setup() {
size(640, 480);
// YOUR NAME
// Homework 23: ArrayList of Pyramids.
final int NUMBER_OF_PYRAMIDS = 100;
Pyramid[] pyramids;
void setup() {
size(displayWidth, displayHeight, P3D);
pyramids = new Pyramid[NUMBER_OF_PYRAMIDS];
// TIP: Nothing needs to change in this class in order to meet
// the assignment requirements. But feel free...
class Pyramid {
int x;
int y;
int size;
float theta;
float rotationSpeed;
@ybakos
ybakos / gist:3791dd6b752aca4a88cf
Created October 15, 2014 15:14
Early iteration of the Hack Assembler.
puts "Hack Assembler!"
def args_valid?
ARGV[0] && ARGV[0].end_with?(".asm") && File.file?(ARGV[0])
end
abort("Usage: ruby assembler.rb filename.asm") unless args_valid?
class Assembler
@@dest = {
nil => 0,
'M' => 1,
'D' => 2,
'MD' => 3,
'A' => 4,
'AM' => 5,
'AD' => 6,
'AMD' => 7
}
@ybakos
ybakos / assembler.rb
Created October 22, 2014 21:22
A simple almost-working assembler for Hack.
class Assembler
attr_accessor :instructions
def initialize(asm_commands)
@asm_commands = asm_commands
@instructions = []
@symbol_table = {}
@instruction_address = 0
end
@ybakos
ybakos / assembler.rb
Created October 22, 2014 21:26
An almost-working assembler for Hack.
require_relative './code'
class String
def is_numeric?
true if Float(self) rescue false
end
end
puts "Hack Assembler!"