Cedric
Re: 2 Basic Programs
Reply #6 - May 7th , 2009, 7:14pm
alright, here it is. You really should take a look at what ive done. and maybe check the OOP tutorial. there are also some little things you should change about your programming language like naming variables ( use camelCase) and your for loops for example. anyway, here it is: int Rank = 12; int SqSide = 20; Circles[] circle = new Circles[Rank*Rank]; int Side = SqSide * Rank; color White = color(255, 255, 255), Red = color(255, 0, 0), Green = color(0, 255, 0), Blue = color(0, 0, 255), Yellow = color(255, 255, 0), Black = color(0, 0, 0); color BG = Yellow; void setup() { size(Side, Side); smooth(); background(BG); for (int i=0; i< circle.length;i++) { circle[i] = new Circles(); } } void draw() { background(BG); for (int i=0; i< Rank;i++) { for (int j=0; j< Rank;j++) { circle[i+(j*Rank)].check(); circle[i+(j*Rank)].show(i * SqSide + SqSide/2, j*SqSide + SqSide /2); } } } class Circles{ float x; float y; boolean circleON; Circles() { circleON = true; } void ranCol() { } void check(){ if (mousePressed == true) { if(dist(mouseX,mouseY,x,y)<=SqSide/2)circleON = false; } } void show(float _x, float _y){ x= _x; y= _y; float co; co = random(5); int n; n = (int) co; if (n == 0) { fill (Green); } else { if (n == 1) { fill (Blue); } else { if (n == 2) { fill (Red); } else { if (n == 3) { fill (Yellow); } else { if (n == 4) { fill (White); } else { if (n == 5) { fill (Black); } } } } } } if(circleON){ ellipse(x,y,SqSide,SqSide); } } }