Last active
December 2, 2015 22:01
-
-
Save daytona1/ceedb8a825dbeff43ad8 to your computer and use it in GitHub Desktop.
Help for Vicki's "Timepiece" project
This file contains 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
// need to declare the `circleScale` var up top | |
var circleScale; | |
var maxScale = 100; | |
/** | |
* Setup the sketch | |
*/ | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
// set our scale to 1 for starters | |
circleScale = 1; | |
} | |
/** | |
* Main animation loop | |
*/ | |
function draw() { | |
// set background to black | |
background(0); | |
stroke(255, 204, 0); | |
strokeWeight(2); | |
noFill(); | |
// try commenting out these different functions | |
// to see two different approaches | |
drawCircleUsingRadius(); | |
drawCircleUsingScale(); | |
// every frame we are increasing the scale by 0.5 | |
circleScale = circleScale + 0.5; | |
// helpful to output to the console so we can see what's happening | |
console.log('circleScale: '+circleScale); | |
// you had: | |
// if(circleScale > 600){ | |
// what you really want to do here is reset the | |
// circle scale once it's greater thn a certain value | |
if(circleScale > maxScale){ | |
// reset to 1 | |
circleScale = 1; | |
} | |
} | |
/** | |
* This function draws an ellipse using `circleScale` as | |
* its radius | |
*/ | |
function drawCircleUsingRadius() { | |
// draw the ellipse in the middle of the screen | |
ellipse(width/2, height/2, circleScale, circleScale); | |
} | |
/** | |
* This function uses the `scale` and `transform` functions to move and | |
* resize the ellipse, which we are drawing a 0, 0 with a set radius. | |
*/ | |
function drawCircleUsingScale() { | |
push(); | |
translate(width/2, height/2); | |
scale(circleScale, circleScale); | |
ellipse(0, 0, 50, 50); | |
pop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment