Hey, I'm playing around with processing 2 and the javascript mode.
I've gotten some of my sketches to load in the browser without any editing. But the code here doesn't seem to work. Anyone know why?
- int area = 440; //colums * rows, yields number of dots
- Dot dots[] = new Dot[area];
- int radius, diameter;
- int cols, rows;
- int index;
- void setup() {
- size(968, 220);
- smooth();
- fill(255);
- background(200);
- diameter = height/10;
- cols = width/diameter;
- rows = 10;
- radius = diameter/2;
- //setup grid
- for(int i = 0; i < cols; i++) {
- for(int j = 0; j < rows; j++) {
- int x = i*diameter;
- int y = j*diameter;
- dots[index] = new Dot(x+radius,y+radius,diameter, index);
- index++;
- }
- }
- initial();
- }
- void draw()
- {
- background(0);
- for(int i = 0; i < area; i++) {
- dots[i].reDraw();
- }
- }
- void initial() {
- /*
- String[] init = loadStrings("coord.txt");
- for(int i = 0; i < init.length; i++) {
- int tIndex = int(init[i]);
- dots[tIndex].switcher();
- }
- */
- }
- void mousePressed() {
- for(int i = 0; i < area; i++) {
- dots[i].mouseTest();
- }
- }
- class Dot {
- int x, y, dia;
- boolean filled = false;
- int index; //holds the index value of the encapsulating array
- Dot(int x1, int y1, int dim, int in) {
- x = x1;
- y = y1;
- dia = dim;
- index = in;
- fill(0,0);
- stroke(255);
- ellipse(x, y, dia, dia);
- }
- void mouseTest() {
- //test to see if the circle has been clicked
- if(mouseX >= (x - dia/2) && mouseX <= (x + dia/2)
- && mouseY >= (y - dia/2) && mouseY <= (y + dia/2)) {
- switcher();
- println(index);
- }
- }
- void switcher() {
- if (filled == false) {
- filled = true;
- }
- else if(filled == true) {
- filled = false;
- }
- }
- void reDraw() {
- if (filled == true) {
- fill(255, 255);
- noStroke();
- ellipse(x, y, dia, dia);
- }
- else if(filled == false) {
- fill(255,0);
- stroke(255);
- ellipse(x, y, dia, dia);
- }
- }
- }
1