Skip to content

Instantly share code, notes, and snippets.

@carlosefr
Created April 15, 2022 15:54
Show Gist options
  • Save carlosefr/98d78455299ee998cf6db64d9abe3071 to your computer and use it in GitHub Desktop.
Save carlosefr/98d78455299ee998cf6db64d9abe3071 to your computer and use it in GitHub Desktop.
Yet Another Plasma Effect v2.0 - 10 years later (2008)
/*
* Yet Another Plasma Effect v2.0 - 10 years later...
*
* Copyright (c) 2008 Carlos Rodrigues <cefrodrigues@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
color[] palette;
int[] pattern;
void setup()
{
size(320, 240, P3D);
frameRate(30);
// Calculate the wave function...
int[] fx = new int[max(width, height)];
float m1 = random(0.1, 0.2);
float m2 = random(0.01, 0.02);
for (int x = 0; x < fx.length; x++) {
fx[x] = round(100 * sin(x * m1) + 400 * cos(x * m2));
}
// Generate a symmetric color gradient...
palette = new color[256];
int r = 255, g = 0, b = 0;
for (int i = 0; i < palette.length / 2; i++) {
palette[i] = palette[palette.length - i - 1] = color(r, g, b);
r -= 2;
g += 2;
b += 2;
}
// Calculate the 2D function that indexes the color palette...
pattern = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
pattern[y * width + x] = abs(fx[x] + fx[y]) % (palette.length - 1);
}
}
}
void draw()
{
loadPixels();
// Rotate the color palette (animation)...
color c = palette[0];
for (int i = 0; i < palette.length - 1; i++) {
palette[i] = palette[i + 1];
}
palette[palette.length - 1] = c;
// Paint the frame based on the 2D function...
for (int i = 0; i < width * height; i++) {
pixels[i] = palette[pattern[i]];
}
updatePixels();
}
/* EOF - yape2.pde */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment