Skip to content

Instantly share code, notes, and snippets.

@tildebyte
Last active August 29, 2015 14:03
Show Gist options
  • Save tildebyte/1ee9fa341335e7615f80 to your computer and use it in GitHub Desktop.
Save tildebyte/1ee9fa341335e7615f80 to your computer and use it in GitHub Desktop.
Processing `constrain()` tests.
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);
}
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