PFont font; String[ ] machCode = new String[40]; int ex = 100; int wy = 100; int goldx = 260; int goldy = 420; int xdir = 1; int ydir = 0; int justDoIt = 0; int temp; int pc = 0; String pgm = ""; String explain = "Type commands: s, r or l"; String[] instr = {"x"}; void setup( ){ size(500, 600); background(16, 100, 8); smooth(); frameRate(20); font = loadFont("DialogInput-24.vlw"); textFont(font); for (int i = 0; i < 40; i++) { machCode[i] = str('p'); } world(); turtle(ex, wy); } void draw( ) { world( ); turtle(ex, wy); } void turtle(int x, int y) { if (x == goldx && y == goldy) { fill(lerpColor(color(0,255,0),color(255,255,0),0.33)); } else { fill(54, 224, 32); } ellipse(x-15, y-12, 10, 10); ellipse(x+15, y-12, 10, 10); ellipse(x-15, y+12, 10, 10); ellipse(x+15, y+12, 10, 10); ellipse(x, y, 40, 40); if (xdir != 0){ ellipse(x+(xdir*20), y, 15, 15); } else { ellipse(x, y+(ydir*20), 15, 15); } } void world( ) { background(16, 100, 8); fill(0); rect(0, height-100, width, height); fill(0, 255, 0); rect(5, 505, 30, 70); fill(255); text("r", 15, 524); text("u", 15, 544); text("n", 15, 570); stroke(255,0,0);strokeWeight(3); line(40, height-96, 40, height-25); text(explain, 45, 544); stroke(0,255,0);strokeWeight(1); for (int i = 0; i < 8; i++){ line(20+i*80, 0, 20+i*80, height-100); } for (int i = 0; i < 8; i++){ line(0, 20+i*80, width, 20+i*80); } noStroke(); fill(0,0,255); ellipse(100, 180, 60, 60); ellipse(180, 180, 60, 60); ellipse(340, 180, 60, 60); ellipse(260, 340, 60, 60); fill(255, 255, 0); ellipse(260, 420, 60, 60); stroke(0); } String[] compile(String code) { String[ ] inst = splitTokens(code, ", ;"); String[ ] ocode = {"x"}; for (int i=0; i < inst.length; i++) { if (inst[i].equals("s")) { ocode = splice(ocode, machCode, ocode.length); } else { ocode = splice(ocode, inst[i], ocode.length); } } return ocode; }