Created
November 30, 2015 12:11
-
-
Save cansik/78a5f2f501d3be293263 to your computer and use it in GitHub Desktop.
Point Wave 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
import controlP5.*; | |
// ui | |
ControlP5 cp5; | |
Group g1; | |
//vars | |
int offset = 15; | |
int orbitRadius = 20; | |
int radius = 1; | |
int waveStrengthHorizontal= 5; | |
int waveStrengthVertical= 5; | |
float speed = 1; | |
void setupUI() | |
{ | |
cp5 = new ControlP5(this); | |
int space = 15; | |
int cy = 0; | |
int bx = 5; | |
int by = 5; | |
g1 = cp5.addGroup("Parameter") | |
.setPosition(100,100) | |
.setWidth(250) | |
.setBackgroundHeight(100) | |
.setBackgroundColor(color(255,50)); | |
cp5.addSlider("offset") | |
.setPosition(by, bx + space * cy++) | |
.setRange(0,30) | |
.setGroup(g1); | |
cp5.addSlider("orbitRadius") | |
.setPosition(by, bx + space * cy++) | |
.setRange(0,30) | |
.setGroup(g1); | |
cp5.addSlider("radius") | |
.setPosition(by, bx + space * cy++) | |
.setRange(0,30) | |
.setGroup(g1); | |
cp5.addSlider("waveStrengthHorizontal") | |
.setPosition(by, bx + space * cy++) | |
.setRange(0,30) | |
.setGroup(g1); | |
cp5.addSlider("waveStrengthVertical") | |
.setPosition(by, bx + space * cy++) | |
.setRange(0,30) | |
.setGroup(g1); | |
cp5.addSlider("speed") | |
.setPosition(by, bx + space * cy++) | |
.setRange(0,30) | |
.setGroup(g1); | |
g1.setPosition(10, height - 120 + 10); | |
} | |
void setup() | |
{ | |
size(500, 500, P2D); | |
setupUI(); | |
background(50); | |
} | |
void draw() | |
{ | |
background(50); | |
int vCount = height / offset; | |
int uCount = width / offset; | |
for(int v = 0; v < vCount; v++) | |
{ | |
for(int u = 0; u < uCount; u++) | |
{ | |
float ox = u * offset; | |
float oy = v * offset; | |
float strength = u * waveStrengthHorizontal + v * waveStrengthVertical; | |
int finalSpeed = (int)(360 / speed); | |
float angle = (float)((((frameCount + strength) % finalSpeed) * Math.PI) / 90); | |
float x = (float)(orbitRadius * Math.cos(angle)); | |
float y = (float)(orbitRadius * Math.sin(angle)); | |
stroke(255); | |
fill(255); | |
ellipse(x + ox, y + oy, radius, radius); | |
} | |
} | |
} | |
void keyPressed() | |
{ | |
if(key == 'h') | |
{ | |
g1.setVisible(!g1.isVisible()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment