Created
September 21, 2022 01:29
-
-
Save ledlogic/ee5258fe15d7b6fc387ac6461f72c10d to your computer and use it in GitHub Desktop.
An animation for use behind a circular stargate
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
double dim = 600; | |
double center = dim/2; | |
double offsetX = 0; | |
double offsetY = 0; | |
double range = 10; | |
double scale = dim / range; | |
double plotWidth = 0.05; | |
double plotIncrement = 0.1; | |
double sinhFactor = 1.25; // 1.25 | |
double maxColor = 255; | |
double maxStroke = 5; | |
double radians = 0; | |
double radiansVelocity = TWO_PI / 360 * 2; | |
double staticRadiansOffset = TWO_PI/360 * 45; | |
double pulse = 1; | |
double pulseVelocity = 0.01; | |
double pulseMax = 1; | |
double pulseMin = 0.2; | |
double secondaryFactor = 1.8; | |
double steps = 6; | |
double stepsVelocity = 0.01; | |
double stepsMin = 5; | |
double stepsMax = 15; | |
int fps = 60; | |
void black() { | |
stroke(0, 0, 0); | |
fill(0, 0, 0); | |
} | |
void gray() { | |
stroke(25, 25, 25); | |
fill(25, 25, 25); | |
} | |
void pulseColor(double step, double steps, double pulse) { | |
double primary = (step / steps * maxColor) * pulse; | |
stroke((float)(primary/secondaryFactor), (float)(primary/secondaryFactor), (float)primary); | |
} | |
void settings() { | |
//size((int)dim, (int)dim); | |
fullScreen(); | |
} | |
void setup() { | |
frameRate(fps); | |
dim = Math.min(width, height)*0.8; | |
center = dim / 2; | |
offsetX = (width - dim)/2; | |
offsetY = (height - dim)/2; | |
} | |
void draw() { | |
renderBackground(); | |
renderColors(); | |
radians += radiansVelocity; | |
if (steps >= stepsMax) { | |
stepsVelocity = -stepsVelocity; | |
} | |
if (steps <= stepsMin) { | |
stepsVelocity = -stepsVelocity; | |
} | |
steps += stepsVelocity; | |
if (pulse >= pulseMax) { | |
pulseVelocity = -pulseVelocity; | |
} | |
if (pulse <= pulseMin) { | |
pulseVelocity = -pulseVelocity; | |
} | |
pulse += pulseVelocity; | |
//println ("steps: " + steps + ", pulse: " + pulse); | |
} | |
void renderColors() { | |
for (int i = 0; i < steps; i++) { | |
pulseColor(i, 5, 1); | |
render(staticRadiansOffset + i * TWO_PI/steps, 1); | |
} | |
for (int i = 0; i < steps; i++) { | |
pulseColor(i, 5, pulse); | |
render(radians + i * TWO_PI/steps, -1); | |
//render(-radians + i * TWO_PI/(steps * 0.5), 1); | |
} | |
} | |
void renderBackground() { | |
gray(); | |
rect(0, 0, width, height); | |
black(); | |
ellipse((float)(center + offsetX), (float)(center + offsetY), (float)dim, (float)dim); | |
} | |
double theFunction(double input, double yfactor) { | |
return yfactor * Math.sinh(input / sinhFactor); | |
} | |
void render(double radians, double yfactor) { | |
if (yfactor == -1) { | |
for (double x1 = -range/2; x1 <= range/2; x1 += plotIncrement) { | |
renderInner(radians, yfactor, x1); | |
} | |
} else { | |
for (double x1 = -range/2; x1 <= range/2; x1 += plotIncrement) { | |
renderInner(radians, yfactor, x1); | |
} | |
} | |
} | |
void renderInner(double radians, double yfactor, double x1) { | |
double y1 = theFunction(x1, yfactor); | |
double radius1 = sqrt(pow((float)x1, 2) + pow((float)y1, 2)); | |
if (radius1 * scale > center) { | |
return; | |
} | |
strokeWeight((float)(maxStroke * radius1)); | |
double x0 = x1-plotWidth; | |
double y0 = theFunction(x0, yfactor); | |
double x2 = x1+plotWidth; | |
double y2 = theFunction(x2, yfactor); | |
renderLine(radians, x0, y0, x2, y2); | |
} | |
void renderLine(double radians, double x0, double y0, | |
double x1, double y1) { | |
double a0 = Math.atan2(y0, x0) + radians; | |
double r0 = sqrt(pow((float)x0, 2) + pow((float)y0, 2)); | |
double cx0 = Math.cos(a0) * r0; | |
double cy0 = Math.sin(a0) * r0; | |
double a1 = Math.atan2(y1, x1) + radians; | |
double r1 = sqrt(pow((float)x1, 2) + pow((float)y1, 2)); | |
double cx1 = Math.cos(a1) * r1; | |
double cy1 = Math.sin(a1) * r1; | |
float tx0 = (float)(offsetX + cx0*scale+center); | |
float ty0 = (float)(offsetY + cy0*scale+center); | |
float tx1 = (float)(offsetX + cx1*scale+center); | |
float ty1 = (float)(offsetY +cy1*scale+center); | |
line(tx0, ty0, tx1, ty1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment