mirror of
https://github.com/processing/processing4.git
synced 2026-02-02 21:29:17 +01:00
81 lines
1.9 KiB
Java
81 lines
1.9 KiB
Java
import processing.core.*;
|
|
|
|
import java.applet.*;
|
|
import java.awt.*;
|
|
import java.awt.image.*;
|
|
import java.awt.event.*;
|
|
import java.io.*;
|
|
import java.net.*;
|
|
import java.text.*;
|
|
import java.util.*;
|
|
import java.util.zip.*;
|
|
import java.util.regex.*;
|
|
|
|
public class Plasma extends PApplet {
|
|
|
|
/**
|
|
* Plasma Demo Effect
|
|
* by luis2048.
|
|
*
|
|
* Cycles of changing colours warped to give an illusion
|
|
* of liquid, organic movement.Colors are the sum of sine
|
|
* functions and various formulas. Based on formula by Robert Klep.
|
|
*/
|
|
|
|
int pixelSize=2;
|
|
PGraphics pg;
|
|
|
|
public void setup(){
|
|
size(640, 360);
|
|
// Create buffered image for plasma effect
|
|
pg = createGraphics(160, 90, P2D);
|
|
colorMode(HSB);
|
|
noSmooth();
|
|
}
|
|
|
|
public void draw()
|
|
{
|
|
float xc = 25;
|
|
|
|
// Enable this to control the speed of animation regardless of CPU power
|
|
// int timeDisplacement = millis()/30;
|
|
|
|
// This runs plasma as fast as your computer can handle
|
|
int timeDisplacement = frameCount;
|
|
|
|
// No need to do this math for every pixel
|
|
float calculation1 = sin( radians(timeDisplacement * 0.61655617f));
|
|
float calculation2 = sin( radians(timeDisplacement * -3.6352262f));
|
|
|
|
// Output into a buffered image for reuse
|
|
pg.beginDraw();
|
|
pg.loadPixels();
|
|
|
|
// Plasma algorithm
|
|
for (int x = 0; x < pg.width; x++, xc += pixelSize)
|
|
{
|
|
float yc = 25;
|
|
float s1 = 128 + 128 * sin(radians(xc) * calculation1 );
|
|
|
|
for (int y = 0; y < pg.height; y++, yc += pixelSize)
|
|
{
|
|
float s2 = 128 + 128 * sin(radians(yc) * calculation2 );
|
|
float s3 = 128 + 128 * sin(radians((xc + yc + timeDisplacement * 5) / 2));
|
|
float s = (s1+ s2 + s3) / 3;
|
|
pg.pixels[x+y*pg.width] = color(s, 255 - s / 2.0f, 255);
|
|
}
|
|
}
|
|
pg.updatePixels();
|
|
pg.endDraw();
|
|
|
|
// display the results
|
|
image(pg,0,0,width,height);
|
|
|
|
}
|
|
|
|
|
|
static public void main(String args[]) {
|
|
PApplet.main(new String[] { "Plasma" });
|
|
}
|
|
}
|