Last active
August 29, 2015 14:20
-
-
Save anilsemizoglu/1ba39ea4ddcd77b8f7a3 to your computer and use it in GitHub Desktop.
A Processing Sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gifAnimation.*; | |
GifMaker gifExport; | |
// total_frames determine how many frames will be in the gif | |
int frames = 0, total_frames = 10, | |
randx, randy, radius; | |
public void setup(){ | |
size(1200,900); | |
background(255); | |
//outputting the gif | |
smooth(); | |
frameRate(12); | |
// 5 is the quality factor, | |
gifExport = new GifMaker(this, "circles.gif",5); | |
gifExport.setRepeat(0); // make it an "endless" animation | |
} | |
// function to vary the color with coordinates | |
color var_color(int x, int y,float alp){ | |
// find the center of the image | |
int center_x = int(width/2); | |
int center_y = int(height/2); | |
// find the distance from the origin | |
int dis_y = abs(y - center_y); | |
int dis_x = abs(x - center_x); | |
// determine the red and blue color depending | |
// on the coordinates | |
int red_value = int(255 * dis_y / height); | |
int blue_value = int(255 * dis_x / width); | |
return color(red_value,0,blue_value,alp); | |
} | |
// function that draws a set of circles with | |
// exponential growth and a changing | |
// alpha value in the color | |
void circles(){ | |
float alpha = 100; | |
randx = int(random(width)); | |
randy = int(random(height)); | |
for(int k = 0; k<12;k++){ | |
radius *=3; | |
alpha *=0.8; | |
color color_use = var_color(randx,randy,alpha); | |
stroke(color_use); | |
noFill(); | |
ellipse(randx,randy,radius,radius); | |
} | |
} | |
// function to export the gif, called | |
// every 20 times circles() is called | |
// each frame of gif has 20 set of circles | |
void export(){ | |
if(frames < total_frames) { | |
gifExport.setDelay(20); | |
gifExport.addFrame(); | |
frames++; | |
} else { | |
gifExport.finish(); | |
frames++; | |
println("gif saved"); | |
exit(); | |
} | |
} | |
void draw(){ | |
int j = 0; | |
while (j<20){ | |
radius=1; | |
circles(); | |
j++; | |
} | |
export(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment