Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fadecandy "rings" Example modified for export to 32x32 GIF
/*
* Fadecandy
*
* Copyright (c) 2013 Micah Elizabeth Scott
*
* 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.
*/
// Fadecandy "rings" Example modified for export to 32x32 GIF by Louis Beaudoin
/*****************************************************************
Add this to your code to export GIFs:
First, Import the GifAnimation Library
(Sketch->Import Library->Add Library, search for "GifAnimation"
Add a call to setupGIF() from setup()
Add a call to exportGIF() right after updatePixels()
Set the size of the window to the size of your GIF: size(32, 32)
*****************************************************************/
import gifAnimation.*;
GifMaker gifExport;
int frames = 0;
int totalFrames = 500;
void setupGIF()
{
gifExport = new GifMaker(this, "export.gif", 1);
gifExport.setRepeat(0); // make it an "endless" animation
}
void exportGIF() {
if(frames < totalFrames) {
gifExport.setDelay((int)(1000/frameRate));
gifExport.addFrame();
frames++;
} else {
gifExport.finish();
frames++;
println("gif saved");
exit();
}
}
/*****************************************************************/
void setup()
{
size(32, 32);
setupGIF();
colorMode(HSB, 100);
}
float noiseScale=0.02;
float fractalNoise(float x, float y, float z) {
float r = 0;
float amp = 1.0;
for (int octave = 0; octave < 4; octave++) {
r += noise(x, y, z) * amp;
amp /= 2;
x *= 2;
y *= 2;
z *= 2;
}
return r;
}
float dx, dy, dz;
void draw() {
long now = millis();
float speed = 0.002;
float zspeed = 0.1;
float angle = sin(now * 0.001);
float z = now * 0.00008;
float hue = now * 0.01;
float scale = 0.005;
float saturation = 100 * constrain(pow(1.15 * noise(now * 0.000122), 2.5), 0, 1);
float spacing = noise(now * 0.000124) * 0.1;
dx += cos(angle) * speed;
dy += sin(angle) * speed;
dz += (noise(now * 0.000014) - 0.5) * zspeed;
float centerx = noise(now * 0.000125) * 1.25 * width;
float centery = noise(now * -0.000125) * 1.25 * height;
loadPixels();
for (int x=0; x < width; x++) {
for (int y=0; y < height; y++) {
float dist = sqrt(pow(x - centerx, 2) + pow(y - centery, 2));
float pulse = (sin(dz + dist * spacing) - 0.3) * 0.3;
float n = fractalNoise(dx + x*scale + pulse, dy + y*scale, z) - 0.75;
float m = fractalNoise(dx + x*scale, dy + y*scale, z + 10.0) - 0.75;
color c = color(
(hue + 40.0 * m) % 100.0,
saturation,
100 * constrain(pow(3.0 * n, 1.5), 0, 0.9)
);
pixels[x + width*y] = c;
}
}
updatePixels();
exportGIF();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.