Created
August 22, 2023 17:00
-
-
Save tchnmncr/37d7fff4a05a235fe9d75e83c80fc101 to your computer and use it in GitHub Desktop.
Latööcarfian Dream Generator v2.0
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
/** Latööcarfian Dream Generator v2.0 | |
* by tchnmncr @ eldri.tech | |
* | |
* Based on code on pg. 26 of _Chaos in Wonderland_ | |
* by Clifford A. Pickover | |
* Good ranges for a, b, c, and d: | |
* (-3 < a, b < 3) | |
* (0.5 < c, d < 1.5) | |
*/ | |
PGraphics dream; | |
double a = 1.5641136; // Values for generating "Serpent Horizon" | |
double b = 2.7102947; | |
double c = 0.9680385; | |
double d = 0.995141; | |
double x, y = 0.1; | |
int alpha = 10; | |
int xOff = 0; // Horizontal offset | |
int yOff = 0; // Vertical offset | |
int zoom = 200; // Magnification | |
int iterations = 10000000; | |
int saveInterval = 1000000; | |
boolean saveFrames = false; | |
void setup() { | |
size(1080, 1080); | |
dream = createGraphics(1080, 1080); // Create buffer to draw into | |
} | |
// Do the heavy lifting outside of draw(); much faster | |
void updateFrame() { | |
for (int i = 0; i < iterations; i = i+1) { | |
double xNew = Math.sin(y*b) + c * Math.sin(x*b); | |
double yNew = Math.sin(x*a) + d * Math.sin(y*a); | |
x = xNew; y = yNew; | |
dream.point((float)x * zoom, (float)y * zoom); | |
// Save some frames while updating | |
if (saveFrames) { | |
if (i % saveInterval == 0) { | |
String dateString = String.format("%d_%02d_%02d_%02d_%02d_%02d", | |
year(), month(), day(), hour(), minute(), second()); | |
dream.save("/data/" + dateString + ".png"); | |
} | |
} | |
} | |
} | |
void draw() { | |
println("Dreaming..."); | |
dream.beginDraw(); | |
dream.background(0); | |
dream.stroke(255,255,255,alpha); | |
dream.translate(width/2 + xOff, height/2 + yOff); // Draw from center of window w/ offsets | |
updateFrame(); | |
println("The dream is done!"); | |
dream.beginDraw(); | |
dream.endDraw(); | |
image(dream, 0, 0, 1080, 1080); | |
noLoop(); | |
} | |
// Press 's' key to save the drawing output | |
void keyPressed() { | |
switch (key) { | |
case 's': | |
String dateString = String.format("%d_%02d_%02d_%02d_%02d_%02d", | |
year(), month(), day(), hour(), minute(), second()); | |
dream.save("/data/" + dateString + ".png"); | |
println("Image saved."); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment