Plasma effect: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Sidef}}: Fix link: Perl 6 --> Raku) |
|||
Line 1,225: | Line 1,225: | ||
end for |
end for |
||
{} = wait_key()</lang> |
{} = wait_key()</lang> |
||
=={{header|Processing}}== |
|||
<lang java>/** |
|||
Plasmas with Palette Looping |
|||
https://lodev.org/cgtutor/plasma.html#Plasmas_with_Palette_Looping_ |
|||
*/ |
|||
int pal[] = new int[128]; |
|||
int[] buffer; |
|||
float r = 42, g = 84, b = 126; |
|||
boolean rd, gd, bd; |
|||
void setup() { |
|||
size(600, 600); |
|||
frameRate(25); |
|||
buffer = new int[width*height]; |
|||
for (int x = 0; x < width; x++) { |
|||
for (int y = 0; y < height; y++) { |
|||
buffer[x+y*width] = int(((128+(128*sin(x/32.0))) |
|||
+(128+(128*cos(y/32.0))) |
|||
+(128+(128*sin(sqrt((x*x+y*y))/32.0))))/4); |
|||
} |
|||
} |
|||
} |
|||
void draw() { |
|||
if (r > 128) rd = true; |
|||
if (!rd) r++; |
|||
else r--; |
|||
if (r < 0) rd = false; |
|||
if (g > 128) gd = true; |
|||
if (!gd) g++; |
|||
else g--; |
|||
if (r < 0) gd = false; |
|||
if (b > 128) bd = true; |
|||
if (!bd) b++; |
|||
else b--; |
|||
if (b < 0){ bd = false;} |
|||
float s_1, s_2; |
|||
for (int i = 0; i < 128; i++) { |
|||
s_1 = sin(i*PI/25); |
|||
s_2 = sin(i*PI/50+PI/4); |
|||
pal[i] = color(r+s_1*128, g+s_2*128, b+s_1*128); |
|||
} |
|||
loadPixels(); |
|||
for (int i = 0; i < buffer.length; i++) { |
|||
pixels[i] = pal[(buffer[i]+frameCount)&127]; |
|||
} |
|||
updatePixels(); |
|||
}</lang> |
|||
'''It can be played on line''' :<BR> [https://www.openprocessing.org/sketch/873932/ here.] |
|||
=={{header|Python}}== |
=={{header|Python}}== |