6.R Objects and Arrays
Dandelions
Demo
Coding
Fabrication
1. Sketching Dandelion:
At first, I only sketched one seed and tried different stem lengths, circle diameters, and flying and stretching effects on it.
A failure I encountered when trying to use createVector() to stretch the stem:
Then, I rotated the seed and adjusted the parameter (lowering the denominator under PI) in for loop to increase the number of seeds.
I then tried to create multiple layers of seeds using nested for loop in the seed method:
2. Flying the seeds
I made the xSpd and ySpd (the parameters that update the positions of the seed) zero so that the seeds are still when the mouse is not pressed. Then, I defined methods “fly()” and “whetherfly()” to change the xSpd and ySpd when the mouse is pressed, so that the seeds’ movements are triggered by users.
When I pressed my mouse, all seeds moved as a whole and didn’t scatter in the right way:
I found that this is because I put the for loops in the seed method so that the combination of seeds became an object. Also, I felt that the pattern looked like a corona virus instead of a dandelion…
Therefore, I moved the deleted outer for loops and move the loop to draw function.
And the result is satisfying. However, the seeds scattered in a weird way as if they were blown by all sides:
I added a random function to make seeds fly in the same direction:
And this is the result:
3. failure to stretch the stems:
I attempted to stretch the stems when the mouse moves above the seeds. But for some reason, I didn’t succeed. Due to the time limit and complexity concerns, I abandoned this attempt.
Here’re several attempts:
4. Creating multiple dandelions:
I defined a dandelion function and created three arrays for seeds.
But I forgot to change the “j” value when calling functions and the result was this:
Then, I tried to add variation in the number of seeds in each dandelion by adjusting the denominator of the parameter in the for loop:
I found that when I was adjusting the number of seeds in each array, the times of iteration remained 30, and running the code resulted in exceeding the array length. I changed my code into this and succeeded:
Reflection
This sketch is inspired by my failure to create a dandelion in project one. At that time, I was using particle systems without the knowledge of Object-oriented Programming (OOP). This time, after having a better understanding of the arrays and OOP, I successfully create the effect I want (though the stretching effect is still to be explored). However, the modularity is not good enough, as the dandelions are created using functions and the parameters of seeds have to be manually adjusted and passed into the for loop. In the future, I will try to:
- create a new class “Dandelion” and increase the modularity of my codes;
- explore new interaction mode (e.g. let users blow to the computer to trigger the seeds’ flying. A possible way is to use the p5 sound library to measure the amplitude of microphone input);
- add more changeable features such as colors and finesse the shape of the dandelions;
- make the dandelions’ seeds stretch when the mouse moves above them
- make the flying effect more natural by further controlling the moving directions of each seed.