From the course: Coding for Visual Learners: Learning JavaScript from Scratch
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Push and pop functions - JavaScript Tutorial
From the course: Coding for Visual Learners: Learning JavaScript from Scratch
Push and pop functions
- [Narrator] The current shortcoming with this approach and with the usage of transformation functions in general is that, everything we draw from this point onwards, will be using this new origin points. The way to fix this, is using the push & pop p5.js functions. The p5.js push function allows us to create a new drawing state, and the pop function restores the state to the previous conditions. This allows us to have a completely different settings applied to individual shapes without worrying if those settings will affect the shapes that come after, as long as we do everything in between a push and the pop function. Is easier to illustrate this with an example. In our current setup, everything we draw after the translate and rotate functions, will have 45 degrees of rotation applied to them. So if I were to draw another rectangle here at position of zero, zero of the size 75, 75, and I will make the prior rectangle a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.