I want to create random circle walking how would I do this?

Hello Processing People,

I am having some trouble doing a basic thing. I would like to have circle walking like this on screen. If you look at the link, he has written code for the art which I am using but it is somehow incorrect in Processing. I am struggling with the output of this code. All I get is a circle once I run the code. Could you guys please help me figure out what I’m doing wrong.

float x = 200;
float y = 200;
float s = 50;
float m = 5;


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

void draw(){
  ellipse(50,50,75,75);
  
  x = x + random(350);
  y = y + random(350);
  
}  

Hello,

You wrote in draw:

ellipse(50,50,75,75);

So it keeps drawing an ellipse at coordinates (50, 50).
You want to use your x and y variables for it to move around.

1 Like

Thank you :see_no_evil: really basic but makes more sense. Can I use frame rate to speed up the circles?

1 Like

Hi

Random path or random path and size ??


float x = 200;
float y = 200;
float s = 50;
float m = 5;


void setup(){
  size(700,700);
  background(255,255,255);
   frameRate(4);
}

void draw(){
 background (0);
  ellipse(1+y,1+x,75,75);
  
  x = x + random(35);
  y = y + random(35);
  
}

Thank you, just random path please if this is it I appreciate it.

1 Like

Try 400 here instead of 4

2 Likes

Yes increasing frame rate increase the speed but I used it to show him how it’s moving randomly in slow speed
Using this value

x = x + random(350);
  y = y + random(350);

Making the path too fast at normal frame rate

Thanks for your attention

1 Like

We also need negative values for random!!

So random (-35,35)

(Which makes it possible that 0 occurs or very small values. There is a workaround with random 3,35 and then use a 2nd random to make that negative in 50 % of the cases. But here it’s okay to have 0 values)

1 Like

Hello @anche-jpg,

Take a look at the source code again and compare it to your version.

There are resources (tutorials, references, examples, etc.) here:
https://processing.org/

For starters:
https://processing.org/reference/random_.html
https://processing.org/reference/ellipse_.html
https://processing.org/reference/circle_.html

Also look at references for setup(), size() and draw().

Also a good resource:
https://happycoding.io/ < There is an example in there that may be of interest.

Once you understand this code take a step back and start with a blank sketch and write your code from scratch. This will help develop your programming skills and this is a nice simple example to start with.

:)