-
-
Save anonymous/abdf699224f13f867906 to your computer and use it in GitHub Desktop.
Rolling dragon curve
This file contains 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
// Source for 'rolling dragon curve', amiagoodperson.tumblr.com | |
import java.io.FilenameFilter; | |
int w, h; | |
int count = 0; | |
int fps = 15; | |
// Replace this directory with one containing the frames of 'dragon curve' as PNGs | |
// (gif at) http://amiagoodperson.tumblr.com/post/64585437717/such-fractal-many-unoriginal | |
String sourceDir = "C:/path/to/png/images"; | |
PImage[] images; | |
PImage current; | |
String filename = "dragoncurve_roll"; | |
int saveFreq = 1; | |
void setup() | |
{ | |
size(500, 500); | |
w = width; | |
h = height; | |
colorMode(HSB); | |
ellipseMode(RADIUS); | |
frameRate(fps); | |
loadImages(); | |
} | |
void loadImages() | |
{ | |
File dir = new File(sourceDir); | |
File[] pictures = dir.listFiles(new FilenameFilter() { | |
public boolean accept(File f, String s) | |
{ | |
//gen.png is used as 'source pattern' picture in linefractalgen | |
return s.contains(".png") && !s.equals("gen.png"); // too lazy to check if this .png is terminal | |
} | |
}); | |
if(pictures == null) | |
{ | |
println(sourceDir + " is not a directory!"); | |
return; | |
} | |
images = new PImage[pictures.length]; | |
try | |
{ | |
for(int i = 0; i < pictures.length; i++) | |
{ | |
images[i] = loadImage(pictures[i].getCanonicalPath()); | |
images[i].loadPixels(); | |
} | |
println("Found " + images.length + " png images."); | |
println("First image is " + images[0].width + "x" + images[0].height); | |
size(images[0].width, images[0].height); | |
} | |
catch (Exception e) | |
{ | |
println("Images didn't load!"); | |
e.printStackTrace(); | |
} | |
current = new PImage(width, height); | |
current.loadPixels(); | |
} | |
String mode = "select"; | |
void transform() | |
{ | |
if(mode.equals("select")) | |
selector(); | |
} | |
void selector() | |
{ | |
int mode = 1; | |
int multiplier = -3; | |
//todo: component offsets | |
int switchFreq = (int)Math.ceil(1.0 * w*h/images.length); | |
int whichImg = count; | |
int j; | |
for(int i = 0; i < width*height; i++) | |
{ | |
j = i; | |
if(multiplier < 0) | |
j = -(width*height - i); | |
switch(mode) | |
{ | |
case 1: //continguous block of pixels is selected from the same image | |
whichImg = (count + multiplier * j/switchFreq) % images.length; | |
break; | |
case 2: //changes every pixel | |
whichImg = (count + multiplier * j) % images.length; | |
break; | |
case 3: //radiates from centre | |
whichImg = (count + abs(multiplier) * distSq(i)) % images.length; | |
break; | |
default: | |
whichImg = count; | |
} | |
current.pixels[i] = images[whichImg].pixels[i]; | |
} | |
current.updatePixels(); | |
} | |
int distSq(int index) | |
{ | |
int x = index % width; | |
int y = index / width; | |
return (int)sq(x - width/2) + (int)sq(y - height/2); | |
} | |
//argb == 3210 | |
int component(color c, int which) | |
{ | |
return (c << (8*which)) & 0xFF; | |
} | |
void draw() | |
{ | |
background(0); | |
count++; | |
transform(); | |
image(current, 0, 0); | |
//image(images[count % images.length], 0, 0); | |
if(filename.length() > 0 && count % saveFreq == 0 && count <= images.length) | |
save(filename + filename(count/saveFreq) + ".png"); | |
} | |
String filename(int i) | |
{ | |
if(i > 26) | |
return 'z' + filename(i - 26); | |
return ""+(char)('a'+i-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment