Skip to content

Instantly share code, notes, and snippets.

@msurguy
Created June 26, 2018 18:18
Show Gist options
  • Save msurguy/62d670943b3f18cb4fe4b7ec05fd2acf to your computer and use it in GitHub Desktop.
Save msurguy/62d670943b3f18cb4fe4b7ec05fd2acf to your computer and use it in GitHub Desktop.
Processing Sketch for synth project
float t = 0;
Circle myCircle;
boolean pressedKeys[] = new boolean [4];
void setup() {
size(600, 600);
pixelDensity(2);
colorMode(HSB, 360, 100, 100);
myCircle = new Circle(width / 2, height / 2, 100, 148);
}
void draw() {
background(255);
if (keyPressed) {
myCircle.incrementT();
if (key == 'a') pressedKeys[0] = true;
if (key == 's') pressedKeys[1] = true;
if (key == 'd') pressedKeys[2] = true;
if (key == 'f') pressedKeys[3] = true;
}
if (pressedKeys[0]) {
myCircle.pulsatePosition();
}
if (pressedKeys[1]) {
myCircle.pulsateSize();
}
if (pressedKeys[2]) {
myCircle.pulsateOpacity();
}
if (pressedKeys[3]) {
myCircle.pulsateHue();
}
myCircle.display();
}
void keyReleased() {
if (key == 'a') pressedKeys[0] = false;
if (key == 's') pressedKeys[1] = false;
if (key == 'd') pressedKeys[2] = false;
if (key == 'f') pressedKeys[3] = false;
}
class Circle {
float originalXpos;
float originalYpos;
float xpos;
float ypos;
int orbitRange = 50;
float originalDiameter;
int growthRange = 50;
float diameter;
int opacity = 255;
int opacityRange = 80;
int originalHue;
int hue;
int hueRange = 80;
float t = 0;
float speed = 0.06;
Circle(float tempXpos, float tempYpos, float tempDiameter, int tempHue) {
originalHue = tempHue;
hue = originalHue;
originalXpos = tempXpos;
originalYpos = tempYpos;
xpos = originalXpos;
ypos = originalYpos;
originalDiameter = tempDiameter;
diameter = originalDiameter;
}
void incrementT() {
t += speed;
}
void pulsateSize() {
diameter = originalDiameter + growthRange * sin(t);
}
void pulsatePosition() {
ypos = originalXpos + orbitRange * cos(t*2);
}
void pulsateOpacity() {
opacity = int(170 + opacityRange * sin(t));
}
void pulsateHue() {
hue = int(originalHue + hueRange * sin(t));
}
void display() {
fill(hue, 100, 100, opacity);
ellipse(xpos, ypos, diameter, diameter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment