Last active
December 14, 2015 14:58
-
-
Save Battleroid/5104208 to your computer and use it in GitHub Desktop.
Super dooper pulsating circle object that DOES work. http://youtu.be/bB02W9DUqJE For Processing.
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
// init | |
pulseSquare follower = new pulseSquare(160, height/2, 50, 50, 50); | |
boolean going = true; // false is left, true is right | |
void setup() { | |
size(640, 360); | |
noStroke(); | |
ellipseMode(CENTER); | |
} | |
void draw() { | |
background(0); // black | |
// Loops the circle left and right in the range of 160-480 | |
if (going) { | |
if (follower.getX() < 480) { | |
going = true; | |
} else if (follower.getX() >= 480) { | |
going = false; | |
} | |
} else { | |
if (follower.getX() <= 160) { | |
going = true; | |
} | |
} | |
if (going) { | |
follower.updatePosition(follower.getX()+1, height/2); | |
} else if (!going) { | |
follower.updatePosition(follower.getX()-1, height/2); | |
} | |
follower.render(); | |
} | |
class pulseSquare { | |
// init | |
float x, y; | |
float w, h; | |
float angle; | |
// constructor | |
pulseSquare (float x, float y, float w, float h, float angle) { | |
// do not use temp vars, just use this.* | |
this.x = x; | |
this.y = y; | |
this.w = w; | |
this.h = h; | |
this.angle = angle; | |
} | |
float getX() { | |
return this.x; | |
} | |
float getY() { | |
return this.y; | |
} | |
// slowly change color | |
void oscillate() { | |
angle += 0.05; | |
} | |
void updatePosition(float x, float y) { | |
this.x = x; | |
this.y = y; | |
} | |
// create color | |
void render() { | |
// this.updatePosition(mouseX, mouseY); | |
this.oscillate(); | |
fill(127+127*sin(angle)); | |
ellipse(x, y, w, h); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment