Last active
August 29, 2015 14:03
-
-
Save tildebyte/1ee9fa341335e7615f80 to your computer and use it in GitHub Desktop.
Processing `constrain()` tests.
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
float x = 0; | |
float y = 0; | |
float speed = 0.9; | |
void setup(){ | |
} | |
void draw(){ | |
x = x + speed; | |
y = y + speed; | |
float prevx = x; | |
float prevy = y; | |
x = constrain(x, 0, width); | |
y = constrain(y, 0, height); | |
if (x != prevx || y != prevy){ | |
speed = speed * -1; | |
} else { | |
println("x: " + x, "prevx: " + prevx); | |
println("y: " + y, "prevy: " + prevy); | |
} | |
ellipse(x, y, 15, 15); | |
} |
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
x = 0.0 | |
y = 0.0 | |
speed = 0.9 | |
def setup(): | |
pass | |
def draw(): | |
x += speed | |
y += speed | |
prevx = x | |
prevy = y | |
x = constrain(x, 0, width) | |
y = constrain(y, 0, height) | |
if x != prevx or y != prevy: | |
print('x: {0}, prevx: {1}'.format(x, prevx)) | |
print('y: {0}, prevy: {1}'.format(y, prevy)) | |
speed *= -1 | |
ellipse(x, y, 15, 15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment