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.
Page Index Toggle Pages: 1
Random Points (Read 355 times)
Random Points
Jan 20th, 2009, 6:42pm
 
Hi,
this is my second day with processing.
Sorry for this question but i don't understand the random value for change position of my points.


With this:







size (700, 700);
background (255);




smooth();
strokeWeight(10);  

for (int i = 0; i <= 700; i = i+10) {

 
 for (int j = 0; j <= 700; j = j+10) {
   
   
   
   
   
   
   point(i, j);
   
   
 


}



}



I generate points with 10px of distance but...for generate random points?


Thanks.
Re: Random Points
Reply #1 - Jan 20th, 2009, 6:57pm
 
If I understand you correctly, you want to create random points?

Check out the random() function.

http://processing.org/reference/random_.html
Re: Random Points
Reply #2 - Jan 20th, 2009, 7:06pm
 
it's ok with this code or not?








size (700, 700);
background (255);




smooth();


strokeWeight(5);  





for (int i = 0; i <= 700; i = i+60) {

   float r = random(0,700);

   
 for (int j = 0; j <= 700; j = j+60) {
   
   float b = random(700);
   
   
   
   
   point(r, b);
   
   
 


}



}

Re: Random Points
Reply #3 - Jan 20th, 2009, 8:25pm
 
Could you describe what the end result should be like? End why is there so many white space between your lines of code?

Here is a simple commented example, I'm a beginner so I don't know whether it's optimal.

Quote:
int amount = 20; //amount of points to draw

void setup(){
  size(200,200);
  smooth();
}

void draw(){
  background(255);
  stroke(0);
  strokeWeight(5);
  
  for (int i = 0; i < amount; i++){ //as long as i is smaller than the amount to be drawn
    float xpos = random(0, width); //random value between 0 and width
    float ypos = random(0, height);//idem. between 0 and height
    point(xpos,ypos); //draw point
  }
  noLoop();//run draw() just once
}



Re: Random Points
Reply #4 - Jan 20th, 2009, 11:16pm
 
Thanks thanks.

i modify your code and i work with Lines.
I move this and i'm really happy.

this is my fisrt day with processing.

Next step?Smiley
Page Index Toggle Pages: 1