Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| p5js-week-04 [2023/06/26 00:02] – reina.chen | p5js-week-04 [2023/07/22 20:43] (current) – renick | ||
|---|---|---|---|
| Line 21: | Line 21: | ||
| The picture above reminds me of where I'm from (Texas!); it's a pan of Texas toast being buttered. You'll be on your way to representing such things after this lesson. Let's take a look at these topics so we can make such lists of toast and other things. | The picture above reminds me of where I'm from (Texas!); it's a pan of Texas toast being buttered. You'll be on your way to representing such things after this lesson. Let's take a look at these topics so we can make such lists of toast and other things. | ||
| - | - arrays | + | - [[p5js-week-04# |
| - | - index/ | + | - [[p5js-week-04# |
| - | - push | + | - [[p5js-week-04# |
| - | - pop | + | - [[p5js-week-04# |
| - | - concat | + | - [[p5js-week-04# |
| - | - Math.floor | + | - [[p5js-week-04# |
| - | - pick | + | - [[p5js-week-04# |
| That's a lot of topics to cover, so let's get started. | That's a lot of topics to cover, so let's get started. | ||
| Line 58: | Line 58: | ||
| </ | </ | ||
| | | ||
| - | We can find out how many items are in an array using a technique we haven' | + | We can find out how many items are in an array using a technique we haven' |
| listOfToast.length | listOfToast.length | ||
| Line 87: | Line 87: | ||
| {{: | {{: | ||
| - | That's great for that list of toast, but what happens when we have a new piece of toast that we need to put into the list? In such a case, we need to use the <color black/yellow> | + | That's great for that list of toast, but what happens when we have a new piece of toast that we need to put into the list? In such a case, we need to use the <color black/pink> |
| We can add some pieces of toast like this. The <color black/ | We can add some pieces of toast like this. The <color black/ | ||
| Line 131: | Line 131: | ||
| {{: | {{: | ||
| - | Nobody wants to eat that really burnt piece of toast. Let's get rid of it! In a similar way to push, we can also remove items __from the end__ of an array using the <color black/yellow> | + | Nobody wants to eat that really burnt piece of toast. Let's get rid of it! In a similar way to push, we can also remove items __from the end__ of an array using the <color black/pink> |
| listOfToast.pop() | listOfToast.pop() | ||
| Line 149: | Line 149: | ||
| {{: | {{: | ||
| - | Push always puts our toast at the end of the list. What if we want to put it at the beginning? The <color black/yellow> | + | Push always puts our toast at the end of the list. What if we want to put it at the beginning? The <color black/pink> |
| listOfToast.unshift(" | listOfToast.unshift(" | ||
| Line 169: | Line 169: | ||
| </ | </ | ||
| - | We can join (connect) two arrays using the <color black/yellow> | + | We can join (connect) two arrays using the <color black/pink> |
| < | < | ||
| Line 272: | Line 272: | ||
| ==== translated toast ==== | ==== translated toast ==== | ||
| - | We know how to choose the position of a shape that we draw by giving arguments for the x position and y position. There' | + | We know how to choose the position of a shape that we draw by giving arguments for the x position and y position. There' |
| < | < | ||
| Line 292: | Line 292: | ||
| ==== rotated toast ==== | ==== rotated toast ==== | ||
| - | In the same way, we can use the <color black/yellow> | + | In the same way, we can use the <color black/pink> |
| One thing that is really important to remember is that in p5js, there are two different types of numbers that can be used to rotate things: degrees and radians. Probably in school you have learned about degrees but not radians. That's OK; we just need to be sure to tell p5js that we are using __degrees__. To do that, you should make sure that your setup function has this inside: | One thing that is really important to remember is that in p5js, there are two different types of numbers that can be used to rotate things: degrees and radians. Probably in school you have learned about degrees but not radians. That's OK; we just need to be sure to tell p5js that we are using __degrees__. To do that, you should make sure that your setup function has this inside: | ||
| Line 338: | Line 338: | ||
| ====resetMatrix==== | ====resetMatrix==== | ||
| - | One reason it's hard to use translate and rotate is that the changes accumulate. Sometimes this is useful, but sometimes it's confusing. If you're feeling confused, you can call <color black/yellow> | + | One reason it's hard to use translate and rotate is that the changes accumulate. Sometimes this is useful, but sometimes it's confusing. If you're feeling confused, you can call <color black/pink> |
| < | < | ||
| Line 419: | Line 419: | ||
| Now, can you use these things to make a better drawing of rainbow toast? | Now, can you use these things to make a better drawing of rainbow toast? | ||
| - | ===== your next improved drawing ===== | + | ===== your assignment: an improved drawing |
| Now that you can make arrays, translate things, and rotate them, **let' | Now that you can make arrays, translate things, and rotate them, **let' | ||