Skip to content

Instantly share code, notes, and snippets.

@Battleroid
Last active December 14, 2015 14:58
Show Gist options
  • Save Battleroid/5104208 to your computer and use it in GitHub Desktop.
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.
// 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