Created
September 29, 2019 17:03
-
-
Save ericterpstra/743c4eb708678b61e0548c8572037e9c to your computer and use it in GitHub Desktop.
2D Plasma Effect in Processing 3
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
// Derived from https://www.bidouille.org/prog/plasma | |
int WIDTH = 400; | |
int HEIGHT = 400; | |
float kx = WIDTH/HEIGHT; | |
int strokeColor = 255; | |
float time = second(); | |
float timeScalar = .004; | |
float yy; | |
float xx; | |
float v; | |
float r; | |
float g; | |
float b; | |
void setup() { | |
size(400, 400); | |
background(0); | |
//noLoop(); | |
} | |
void draw() { | |
time = millis() * timeScalar; | |
drawFrame(); | |
} | |
void drawFrame() { | |
loadPixels(); | |
for ( int y = 0; y < HEIGHT; y++ ) { | |
yy = float(y)/HEIGHT - kx/2; | |
for ( int x = 0; x < WIDTH; x++ ) { | |
xx = kx*x/WIDTH - kx/2; | |
v = plasmaMap(xx, yy, time); | |
r = 255*(sin(PI*v)); | |
g = 255*(cos(PI*v)); | |
b = 255*(cos(PI*v*v)); | |
pixels[(x+y*WIDTH)] = color(r,g,b); | |
} | |
} | |
updatePixels(); | |
} | |
float plasmaMap( float x, float y, float time) { | |
float v = 0; | |
v += sin(x*10+time); | |
v += sin((y*10+time)/2); | |
v += sin((x*10+y*10+time)/2); | |
float cx = x + .5 * sin(time/5); | |
float cy = y + .5 * cos(time/3); | |
v += sin(sqrt(100*(cx*cx+cy*cy)+1)+time); | |
v = v/2; | |
return v; | |
} | |
float convertGray(float val) { | |
return map(val, -1, 1, 0, 255); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment