Created
March 12, 2020 18:26
-
-
Save shimpe/5a0750d95a4477cd071c68f9b8218577 to your computer and use it in GitHub Desktop.
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
( | |
// By James McCartney | |
var w, h = 1080, v = 720, seed, run = true, phase = 0; | |
var text_radius = 300; // pixels | |
var text_angle_increment = 7.degrad; // 7 degrees converted to radians | |
var text_start_angle = 0; | |
var text_center_x = 0; | |
var text_center_y = 0; | |
var text_font = Font("Helvetica", 48); | |
a = rrand(60,300); | |
~history = (lines: ["this is a test string for swirling"]); | |
w = Window("wedge", Rect(40, 40, h, v), false); | |
w.view.background = Color.rand(0,0.3); | |
w.onClose = { run = false }; // stop the thread on close | |
w.front; | |
// store an initial seed value for the random generator | |
seed = Date.seed; | |
w.drawFunc = { | |
Pen.width = 2; | |
Pen.use { | |
// reset this thread's seed for a moment | |
thisThread.randSeed = Date.seed; | |
// now a slight chance of a new seed or background color | |
if (0.006.coin) { seed = Date.seed; }; | |
if (0.02.coin) { w.view.background = Color.rand(0,0.3); }; | |
// either revert to the stored seed or set the new one | |
thisThread.randSeed = seed; | |
// the random values below will be the same each time if the seed has not changed | |
// only the phase value has advanced | |
Pen.translate(h/2, v/2); | |
// rotate the whole image | |
// negative random values rotate one direction, positive the other | |
Pen.rotate(phase * 1.0.rand2); | |
// scale the rotated y axis in a sine pattern | |
Pen.scale(1, 0.3 * sin(phase * 1.0.rand2 + 2pi.rand) + 0.5 ); | |
// create a random number of annular wedges | |
rrand(6,24).do { | |
Pen.color = Color.rand(0.0,1.0).alpha_(rrand(0.1,0.7)); | |
Pen.beginPath; | |
~history.lines[0].asString.do({ |chr, idx | | |
// iterate over all letters and draw them on the calculated position | |
var sx = text_center_x + (text_radius * sin(text_start_angle + (idx * text_angle_increment))); | |
var sy = text_center_y + (text_radius * cos(text_start_angle + (idx * text_angle_increment))); | |
Pen.stringAtPoint(chr.asString, sx@sy, text_font); | |
}); | |
Pen.addAnnularWedge(Point(0,0), a = rrand(60,300), a + 50.rand2, 2pi.rand | |
+ (phase * 2.0.rand2), 2pi.rand); | |
if (0.5.coin) {Pen.stroke}{Pen.fill}; | |
}; | |
}; | |
}; | |
// fork a thread to update 20 times a second, and advance the phase each time | |
{ while { run } { w.refresh; 0.05.wait; phase = phase + 0.01pi;} }.fork(AppClock) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment