ICM- Refactoring Party in p5.js

Ok, so I’ve felt kinda bad about my code lately. I feel like I’m spending more time on trying to grasp the concepts behind it than actually making something nice to look at. I took this week as an opportunity to, not refactor old code, but write new code while keeping my functions out of “draw” and setup”. I tried to keep the “setup” and “draw” functions clean. I will say, I called “drawTree” quite a bit- not sure if there’s a more efficient way to organize it in the future.

Nicolas was unbelievably helpful in helping me work through the math and logic behind, not only using rectMode (CENTER), but also how to use local variables. He showed me how it’s best to sketch it out on paper when doing the math. My love of geometry is slowly coming back to me!

Riffing off of the robot example, I thought I’d do a forest of trees and vary the trunk height. Nicolas helped me take it one step further and add a variable for the range of how many leaves a tree could have (as an aside, I sincerely hope I’ll be able to help him with something in the future!). I need to train my brain to be able to summon the logic as quickly as he does. Hopefully with more practice.

The logic I’m still wrapping my head around: push/pop and translate. I’m going to try and make it a point to use the functions I have limited understanding of in my sketches to gain more experience with them while I read McCarthy’s book on p5.js.

Also I learned a fun new thing this week, which is strokeJoin(ROUND);. Thanks to my readings, now I can round the corners of more than just rect();. This was a revelation!

I’ve used GithubGist to copy in my code below, so I have officially graduated from janky screenshots. Huzzah!



Leave a Reply

Your email address will not be published. Required fields are marked *