We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › not drawing objects
Page Index Toggle Pages: 1
not drawing objects (Read 528 times)
not drawing objects
Feb 18th, 2010, 5:23am
 
basically ive written some simple code to make a few bouncing circles, ive been trying to learn arrays.

there must be something ive forgotten because when i run the program it shows nothing just white

heres the code

Code:
int numcircles;

float[] x = new float[numcircles];
float[] y = new float[numcircles];
float[] diameter = new float[numcircles];
int maxdiameter = 30;
float[] xspeed = new float[numcircles];
float[] yspeed = new float[numcircles];
color[] circlecolour = new color[numcircles];

int i;



void setup(){
 
 size(600,600);
 createcircles();
 smooth();
 
 
}
 
void draw(){
 
 background(255);
 movecircles();
 drawcircles();
 
 
}

void createcircles(){
 
 for( i = 0; i < numcircles; i++){
   
   x[i] = random(width);
   y[i] = random(height);
   diameter[i] = random(maxdiameter)*2;
 
   xspeed[i] = random(5);
   yspeed[i] = random(5);
   
 }
 
}

void drawcircles(){
 
 for(i = 0; i < numcircles; i++) {
 
 
 ellipse(x[i],y[i],diameter[i],diameter[i]);
 
 
 
 }
 
}

void movecircles(){
 
 for (i = 0; i < numcircles; i++){
   
   x[i] += xspeed[i];
   y[i] += yspeed[i];
   
   if (x[i] - diameter[i] <= 0 || x[i] + diameter[i] >= width) {

xspeed[i] *= -1;

   }
   
   if (y[i] - diameter[i] <= 0 || y[i] + diameter[i] >= width) {

yspeed[i] *= -1;

   }

 }
 
}


 
   


can anyone see anything wrong with this?
Re: not drawing objects
Reply #1 - Feb 18th, 2010, 5:41am
 
what colour are your circles?
Re: not drawing objects
Reply #2 - Feb 18th, 2010, 5:48am
 
in your very first line you have to give your numcircles variable a value. Like:   int numcircles = 4;
Page Index Toggle Pages: 1