top of page

Assignment 4: Loops

  • Writer: Kiya Brown
    Kiya Brown
  • Mar 8, 2021
  • 2 min read

For this week's assignment I created a mountain landscape. Similar to last week, this was an assignment that I had a different idea for, but came to the conclusion that I bit off more than I could chew and made a more simple version. I knew that I wanted to do something with the sky and with stars. I originally planned to do a sky of stars that were "twinkling" or growing/fading away to create the appearance of "twinkling". In the end I just decided to create a mountain scene that I could turn from day to night using the mousePressed function as well as "for" loops.

I wanted to create trees at the bottom of the mountains using a "while" loop but for some reason whenever I tried to create the loop, p5 stopped working for me and the whole website stopped responding. Luckily, I saved my project so it wasn't too much of a hassle to recover, but every time I tried, the same thing happened. I would make it to "while ( x < width..." and it would freeze up on me.


I used "for" loops to create the different "stars" (which are actually just greyscale points scattered all over the canvas). But without the loop it would be very tedious to try and create all of the little stars. The for loop allowed me to declare a variable and set the parameters to create the look that I wanted. The loop also randomized the stars at every click from day to night.


Something different that I tried out was using example code from the p5 library. I wanted to create a sunset look using a gradient effect for the background. I played around with colormaps and different tools, but ultimately I couldn't get it to perform the way I wanted. So, I looked up "gradient on p5js" and I was able to use their example to get the sunset/sky look that I wanted. If you click the screen, the scene will turn from night to day- changing the color of the sky and the moon to a sun.


I think that there is a lot more that I could add to this project to make it better, but for now I am proud of it and am excited to learn more to create better designs!




Comments


© 2023 by Kiya Brown

bottom of page