Skip to content

Instantly share code, notes, and snippets.

@ericterpstra
Created September 29, 2019 17:03
Show Gist options
  • Save ericterpstra/743c4eb708678b61e0548c8572037e9c to your computer and use it in GitHub Desktop.
Save ericterpstra/743c4eb708678b61e0548c8572037e9c to your computer and use it in GitHub Desktop.
2D Plasma Effect in Processing 3
// 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