Created
September 2, 2020 02:21
-
-
Save volfegan/a386f9aed66359b56c1493d4eac6234d to your computer and use it in GitHub Desktop.
ASCII art Animation for a night bicycle race, birds, moon, stars
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
//common variables | |
float i, t=0, w=1280, h=720; | |
//stars | |
float[] x = new float[(int)h/2]; | |
float[] y = new float[(int)h/2]; | |
//moon | |
float g=sqrt(5)/2+.5, a, r; | |
char[]c={'⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷'}; | |
//birds & bikes | |
float k=0, m, n; | |
String[] ascii = {"└◡v◡┘", "◞◠v◠◟", "◐", "◰", "◓", "◳", "◑", "◲", "◒", "◱"}; | |
void setup() { | |
size(1280, 720); | |
//init stars | |
for (int i=0; i<(int)h/2; i++) { | |
//avoid moon centre | |
float x0 = random(w); | |
float y0 = random(h*.85); | |
while (dist(w*.75, h*.2, x0, y0)<h*.18) { | |
x0 = random(w); | |
y0 = random(h*.85); | |
} | |
x[i] = x0; | |
y[i] = y0; | |
} | |
} | |
void draw() { | |
clear(); | |
//stars | |
fill(-1); | |
for (int i=0; i<(int)h/2; i++) { | |
text('*', x[i], y[i]); | |
} | |
//the shining Moon | |
r=1; | |
for (i=2e3; i>0; i--) { | |
fill(int(i*.1+t*9)%(i%7==0?h:h*atan(t*r/i)), 5*i%(i%7==0?h:h*atan(t*r/i))+16, 7*i%(i%7==0?h:h*atan(t*r/i))+64, 16); | |
a=i*g; | |
text(c[int(t%c.length)], w*.75+r*cos(a), h*.2+r*sin(a)); | |
r+=.05; | |
} | |
String bird = ascii[int(t*10%2)]; | |
String wheel = ascii[int(2+t*20%8)]; | |
String bike = " ---------- __o\n -------- _ \\<,_\n------- ("+wheel+")/ ("+wheel+")"; | |
for (i=0; i<32; i++) { | |
n=noise(i); | |
m=6*sin(n*2+(3*k*(1+n))/64); | |
//flock of birds | |
fill(7*i+(32*m), 9*i+16*m+32, 4*i+64*n); | |
text(bird, (n*240+k*(3+5*n))%w, 120+10*i+(3+2*n)*m); | |
//bike race | |
fill(5*i+16, 7*i+64, 9*i+32*n+16); | |
if (i%3==0) text(bike, i*(w/32)*n+h/2*tan(-t*n), 640+64*n+128*m/500); | |
} | |
//our speed bike guy | |
text(bike, 360+h/2*sin(t)+3*m, 640+128*m/500); | |
k++; | |
t+=.01; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment