top of page

Random Walk

For this practice, I am trying to simulate the growth of a plant. This means on the y-axis, it grows higher and longer, while on the x-axis,  it twists a little, so the plant is not a straight stick. 

STEP 1. Grow🌱

It keeps generating new dots based on the last dot's position. For every new dot, y-1, x plus a random value between -3 and 3. So, it has an equal chance to twist to left or right. 

螢幕截圖 2023-02-01 下午9.45.21.png

STEP 2. Cluster

I used array function to generate multiple plants, and  randomGaussian function to make the majority of plants gather at the center of bottom bar. 

STEP 3. Flow

Now the plants grow at the same pace into random shapes. What if they are aquatic plants and are shaped by the water flow? Can I apply the mouse position to influence where (to left or to right) the plants are growing?

Previously, the range of x value change was between -3 and 3. When the difference of x is>0, it grows to the right, and when the difference of is <0, it grows to the left. It picks a random float number between -3 and 3, so the chance to grow left or right is equal.

For the new version, I detect the position of the mouse. If mouseX is at the left half of the canvas (check if  mouseX-width/2 is larger than 0), the plants grow left, and vice versa. According to how far the mouse is from the central, you get a lean value between -2 and 2. The further the mouse is from the center, the further the lean is from 0. Then the change range of the next x will be random (lean-3, lean+3). So, if the mouse is at the right side edge of the canvas, you may get a lean = 1.99. The range of x change will be random(lean-3, lean+3), which is random(-1.01, 4.99), you will have a higher chance to get a number >0, and the plant has a higher possibility to grow to lean right.

It does not seem so natural if the range of x change stays the same. I hope it to lean crazier if the mouse if further from the center. So, I changed it to this.x=this.x+random(lean-3*abs(lean),lean+3*abs(lean));

螢幕截圖 2023-02-01 下午10.49.08.png

Reflection🪺

Now, the mouse flow only influences the very new dot. Previous dots stay still. How can I make all the dots connect to each other and move along to the flow as a whole plant? 

bottom of page