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 › Why there is no color change precise every cycle
Page Index Toggle Pages: 1
Why there is no color change precise every cycle? (Read 520 times)
Why there is no color change precise every cycle?
Oct 5th, 2009, 1:52pm
 
Please, try to love and solve this shifting
Why there is a shifting from the point where the color changes?
Is it an int/float problem?
I just want the color change precise every cycle.

Code:

int x;
int myStrokeColor;
int counter;

void setup(){
}

void draw(){
background(204);
x = x + 1;
strokeWeight(2);
counter = frameCount;
if(counter % width==0){
myStrokeColor = int (random(111,255));
}
if (x < width){
stroke(myStrokeColor);
line(x,0,x,height);
}
if (x > width){
x = 0;
}
}
Re: Why there is no color change precise every cycle?
Reply #1 - Oct 5th, 2009, 2:29pm
 
i dont get the counter, framecounter part. why dont you just do it this way. then there is no shifting

int x;
int myStrokeColor;
int counter;

void setup(){
}

void draw(){
 background(204);
 x = x + 1;
 strokeWeight(2);

 if(x % width==0){
   myStrokeColor = int (random(111,255));
 }
 if (x < width){
   stroke(myStrokeColor);
   line(x,0,x,height);
 }
 if (x > width){
   x = 0;
 }
}
Re: Now how to manage word-change precise every cycle?
Reply #2 - Oct 5th, 2009, 3:12pm
 
Thanx a lot for cleaning my code. works.
Now I like to go further and change words with different length precise at every cycle.
What I don't see is where to put the textWidth, so that the text starts at width minus textWidth and disappear not until the end of width.
When I start at width minus textWidth, the width wil not expand.
I have to expand the width?

Code:

float x;
int index;
String[] myTextFile = {"sun","sonic","summer","solution","sensibility"};
String s;
float wordWidth;

void setup(){
size(200,100);
textFont(createFont("",24));
}

void draw(){
background(204);
x = (x + 1);
s = myTextFile[index];
wordWidth = textWidth(s);
if(x % width==0){
index = int(random(myTextFile.length));
}
if (x < width){
text (myTextFile[index],x,40);
}
if (x > (width + wordWidth)){
x = 0 - wordWidth;
}
}
Page Index Toggle Pages: 1