import netscape.javascript.*; // for JSObject int count; int bg = 255; JSObject window; // the window void setup() { size(200, 200); background(bg); count = 5; smooth(); window = JSObject.getWindow(this); } public int toggleBG() { if(bg == 255) bg = 0; else bg = 255; window.eval( "message(\" bg toggled to " + bg + " \")" ); return bg; } public void setCount(int c) { count = c; window.eval( "message(\" count set to " + count + " \")" ); } public void setColour(int c) { bg = c; window.eval( "message(\" bg set to " + bg + " \")" ); } void draw() { background(bg); randomSeed(0); for (int i = 0 ; i < count; i++) { ellipse(random(0, width), random(0, height), 5, 5); } } public int incrementIt() { count++; window.eval( "message(\" incremented \")" ); return count; } public int decrementIt() { count--; window.eval( "message(\" decremented \")" ); return count; } public void keyPressed() { window.eval( "message(\"" + key + "\")" ); }