-
Notifications
You must be signed in to change notification settings - Fork 0
/
plasma.pde
95 lines (66 loc) · 1.71 KB
/
plasma.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Plasma 1.0 by André Abt (2010)
// www.andre-abt.com
color palette [] = new color [256];
void setup() {
size(255, 255, P2D);
background(51);
noStroke();
//smooth();
// create color palette
int i, r, g, b;
// between 0..100 fade black to red
for (i = 0; i < 100; i++)
{
r = i * 255 / 100;
g = 0;
b = 0;
palette[i] = color (r, g, b);
}
// between 100..150 fade red to yellow
for ( ; i < 150; i++)
{
r = 255;
g = (i-100) * 255 / 50;
b = 0;
palette[i] = color (r, g, b);
}
// between 150..255 fade yellow to blue
for ( ; i <= 255; i++)
{
r = 255 - ((i - 150) * 255 / 106);
g = 255 - ((i - 150) * 255 / 106);
b = (i - 150) * 255 / 106;
palette[i] = color (r, g, b);
}
}
float deg;
float rad;
color currentColor;
int currentPixel;
float fColor;
float value;
void draw() {
loadPixels();
for(int y=0;y<height;y++) {
//draw line
for(int x=0;x<width;x++) {
// 4 different sinus functions modulating, frameCount is the "time"
fColor = ((sin (x/18.0 + frameCount/99.0) + cos (y/39.0 + frameCount/30.0))
+ sin (x/39.0 - frameCount/40.0) + cos (y/15.0 - frameCount/40.0))
/ 4;
/* variante
fColor = ((sin (x/15.0 + time/99.0) * cos (y/39.0 + time/30.0))
+ sin (x/39.0 - time/40.0) * cos (y/15.0 - time/40.0)) / 4;
*/
// normalize to 0..255.
fColor = ((fColor + 1) / 2) * 255;
// get color from palette
currentColor = palette[int (fColor)];
// colorize current pixel
currentPixel = (y * width) + x;
pixels[currentPixel] = currentColor;
}
}
updatePixels();
//println(frameCount);
}