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 & HelpPrograms › Simple beginner question
Page Index Toggle Pages: 1
Simple beginner question (Read 498 times)
Simple beginner question
Oct 1st, 2007, 6:11am
 
The following code only seems to draw to the screen every time the central fill colur (fillColour) changes in the for loop in draw(), and yet in draw() I call myDrawing() on every loop of the for().  I also note that when fillColour2 is printed to the console it comes twice, like this is being called twice, when I only expect it to be called once per iteration of the for().  Could someone more experienced than I with Processing point out the error of my ways?  I want to draw all 4 ellipses every cycle, changing the fill and  stroke colours for each ellipse, with the exception of the  inner ellipse which I want to change the fill colour for only every "centreCycles" around.  Thanks  in advance, Garth



float x;
 int centreY;
 int centreX;
 float fillColour = 0;
 int centreCycles = 50;


void setup() {
 size(1200, 800);
 x = width/4.5;
 centreY = height/2;
 centreX = width/2;
 background(0);
 //frameRate(12);
 
}



void draw() {
 smooth();
 strokeWeight(8);
   
 for (int i = 0; i < centreCycles; i++) {
   if (i < (centreCycles - 1)) {
       myDrawing();
       //println("fillColour: " + fillColour);
       
 } else {
     myDrawing();
     fillColour = (random(255));
     println("fillColour2: " + fillColour);}
 }
}


void myDrawing() {
   for (int i = 4; i > 0; i--) {
     stroke(204, random(255), 0);
     fill(204, random(255), 0);
     ellipse(centreX, centreY, x*i, x*(i-1));}
 
     stroke(random(255), 102, 0);
     fill(fillColour);
     ellipse(centreX, centreY, x, x);  }
Re: Simple beginner question
Reply #1 - Oct 1st, 2007, 1:31pm
 
i'm having a little trouble following what you're trying to do, but my guess is that you might be missing one of two points:

1. unless you have background() at the beginning of draw(), the screen will not be cleared, therefore all geometry will still be there, and you'll just build up the image.

2. changing the fill/stroke color will only affect those things that are drawn after it--it's not reset on each frame. this means that the fillColour that is randomly set at the end of draw() will affect the first half of your if() statement inside draw() the next time that draw() runs.

not sure if either are what's tripping you up, but those are two guesses based on what you're doing.
Page Index Toggle Pages: 1