Created
October 2, 2015 15:16
-
-
Save chrisallick/dfc82be6580a904ff4b9 to your computer and use it in GitHub Desktop.
Variables - initialize and assign.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function setup() { | |
| createCanvas(640, 480); | |
| // use anti-aliasing | |
| smooth(); | |
| // no stroke on my shapes | |
| noStroke(); | |
| /* | |
| use upper left corner | |
| not the center | |
| */ | |
| ellipseMode( CORNER ); | |
| // just run the draw cycle 1 time :) | |
| noLoop(); | |
| } | |
| function draw() { | |
| background( 247, 250, 248 ); | |
| /* | |
| this is why we use variables. | |
| variables can hold a value and we can use | |
| basic mathematic operations to change the value. | |
| */ | |
| var x = 20; | |
| fill( 46,213,101 ); | |
| ellipse( x, 20, 20, 20 ); | |
| console.log( "[example 2] value of x: " + x ); | |
| /* | |
| when we use '+' or "=" these are called operators | |
| there are many types of operators and they do | |
| different things | |
| */ | |
| x = x + 30; | |
| fill( 41,49,119 ); | |
| ellipse( x, 20, 20, 20 ); | |
| console.log( "[example 2] value of x: " + x ); | |
| x = x + 30; | |
| fill( 253,209,60 ); | |
| ellipse( x, 20, 20, 20 ); | |
| console.log( "[example 2] value of x: " + x ); | |
| x = x + 30; | |
| fill( 174,129,255 ); | |
| ellipse( x, 20, 20, 20 ); | |
| console.log( "[example 2] value of x: " + x ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment