whereSquareIs and set its value to -90 (see Tutorial1-4: Variables).-90 in square() with whereSquareIs and press 'play'.draw() and after square(), type whereSquareIs = whereSquareIs + 1;.1 to the x-parameter of square() every loop, the square moves to the right.whereSquareIs = whereSquareIs + 1; in words: whereSquareIs in the next loop = whereSquareIs in the current loop + 1.whereSquareIs = whereSquareIs + 1; is whereSquareIs += 1; (addition assignment).1 in whereSquareIs += 1; with any value that isn't 1 and press 'play'. Repeat this several times with whole, decimal and negative numbers.whereSquareIs += value;:
whereSquareIs += squareSpeedAndDirection; that makes the square speed up.0.03) to squareSpeedAndDirection every loop makes the square speed up.squareSpeedAndDirection += some value; with squareSpeedAndDirection += a variable of your creation;. What will you call it? Assign it a value and press 'play'.squareSpeedAndDirectionChangePerLoop:
squareSpeedAndDirection squareSpeedAndDirectionChangePerLoop < 0 and squareSpeedAndDirection < 0)whereSquareIs, squareSpeedAndDirection and squareSpeedAndDirectionChangePerLoop.showSampleSituation from false to true and press 'play'. Maybe you came up with something similar.showSampleSituation = true; only provides context and enhanced visual appeal. With a little imagination and an understanding of the motion itself, it isn't necessary.
whereSquareIs has been used to describe where the square is, relative to the origin. Physics already has a term for this: position (\(\vec{d}\)). whereSquareIs, use squarePosition.squareSpeedAndDirection has been used to describe the square's speed and direction of motion (that is, how the square's position changes every loop). Physics already has a term for this: squareSpeedAndDirection, use squareVelocity.squareSpeedAndDirectionChangePerLoop has been used to describe how the square's speed and direction change every loop (that is, how the square's velocity changes every loop). Physics already has a term for this: acceleration (\(\vec{a}\)). squareSpeedAndDirectionChangePerLoop, use squareAcceleration.squareVelocity += squareAcceleration;, type: if (squarePosition < 100 && squareVelocity < 0) {
noLoop();
}
noLoop() prevents the code in draw() from running over and over again.true requires the logical AND operator (&&).| Reference | Example | Example Description |
|---|---|---|
| createCanvas(x,y) | createCanvas(400, 250) |
Creates a canvas thatβs 400 pixels wide and 250 pixels tall. |
| background(color) | background('green') |
Colours the entire canvas green. (n.b. Colors can be defined a number of different ways.) |
| translate(x, y) | translate(100, 200) |
Moves the origin to 100 pixels from the left of the canvas and 200 pixels from the top of the canvas. |
| circle(x, y, diameter) | circle(10,20,30) |
Draws a circle with a 30 pixel diameter 10 pixels to the right of the origin and 20 pixels below the origin. more shapes |
| let | let animalType = "fox"; |
Creates a variable called animalType (and assigns a value of "fox" to it). |
| if statement | |
If the variable t is greater than \(10\), the canvas will be painted green. |
| += (addition assignment) | x += 1; |
Takes the current value of x and adds 1 to it. |
| noLoop() | noLoop(); |
Stops all the code in draw() from looping over and over again. |
| && (logical AND) | |
If the variable t is greater than \(10\) AND the variable x is greater than or equal to \(0\), the canvas will be painted blue. |