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 › 2 questions from a beginner ...
Page Index Toggle Pages: 1
2 questions from a beginner ... (Read 487 times)
2 questions from a beginner ...
Nov 29th, 2007, 2:20pm
 
Hi,

I would like to know get advice how to do the following:

With a forloop: How do I continuously change the values of the actual forloop - i.e. if the forloop controls the amount of lines drawn, then there could be more or less lines:
for(int j=0; j<50; j+=lines) {   }

- I have tried the above, but nothing is drawn to the screen - the variable lines has to be a set number (set in the setup) that does not change over time ...

this doesn't really work:

for(int j=0; j<50; j+=mouseX) {   }


2) How do I make a non-linear counter?

cnt = cnt + ( speed * countdir ); // here the speed is linear, because it is a set value ...

   if (cnt > maxVal || cnt < 0) {
     countdir *= -1;
   }

Thank you so much for your help!
Amelia






























Re: 2 questions from a beginner ...
Reply #1 - Nov 29th, 2007, 2:58pm
 
a: Code:
int lines=25; //draw 25 lines.
for(int j=0;j<lines;j++)
{
// draw a line
}


b: I'm not quite sure what you mean....
Re: 2 questions from a beginner ...
Reply #2 - Nov 29th, 2007, 6:04pm
 
Hi,

Try with the random method :
http://processing.org/reference/random_.html

For example :
Code:
 for(int j=0; j<50; j+=(int)(1+random(2))) {   } 



The same method applies to the counter as well ;-)
Re: 2 questions from a beginner ...
Reply #3 - Nov 29th, 2007, 6:49pm
 
One way would be to:

void setup()
{
 size(500, 500);
 background(255);
}


void draw()
{
 background(255);
 stroke(255, 0, 0);
 
 //dont't change the increment step, change the loop's
 //outer limit

 for(int i = 0; i<mouseX/5; i++)
 {
   line(i*5, 0, 0, i*5);
 }
}
Re: 2 questions from a beginner ...
Reply #4 - Nov 30th, 2007, 10:52am
 
Thank you, that was useful! However, I still don't know how to solve the problem of the distance between the lines:

for(int j=0; j<mouseX/10; j+3) // here the number 3 could be a variable distance between the lines ...

How do I make the distance between the lines happen realtime?

Tnx, amelia
Re: 2 questions from a beginner ...
Reply #5 - Nov 30th, 2007, 11:13am
 
If you don't want random spaces between line, but real time, user defined spaces, you cannot do that in a for loop.

Try with a global variable you increment at each frame :

Code:
int x = 0;

void setup() {
background(255);
stroke(0);
frameRate(5);
}

void draw() {
if (x < width) {
x += (int)(mouseX/10);
line(x, 0, x, height);
}
}
Page Index Toggle Pages: 1