Skip to content

Instantly share code, notes, and snippets.

@edmorais
Created January 10, 2023 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edmorais/c48a3927f3ea2f1a05a5db246ffe23a4 to your computer and use it in GitHub Desktop.
Save edmorais/c48a3927f3ea2f1a05a5db246ffe23a4 to your computer and use it in GitHub Desktop.
Genuary2023 10: Flowers wildly disorganized
/*
____ __ __ __ ___ _
/ __/__/ /_ _____ ________/ /__ / |/ /__ _______ _(_)__
/ _// _ / // / _ `/ __/ _ / _ \ / /|_/ / _ \/ __/ _ `/ (_-<
/___/\_,_/\_,_/\_,_/_/ \_,_/\___/ /_/ /_/\___/_/ \_,_/_/___/
Genuary 2023! 10
* by Eduardo Morais 2023 - www.eduardomorais.pt
*/
// libs
// import processing.javafx.*;
// config
int $appWinWidth = 1024;
int $appWinHeight = 1024;
color $appWinBG = #000000; // #110D92;
color $appDefStroke = #FFFFFF;
int $saveFrameNum = 0; // 0 to deactivate
int $saveFrameOffset = 600; // wait before start recording
// constants
int MAXRAD = 96;
int ROTATIONS = 4;
int MAXSTROKE = 8;
int MAXPETALS = 12;
int FLOWERS = 64;
// globals
Arc[] arcs;
int cellX, cellY, maxRad, minRad;
/*
SETTINGS & SETUP
*/
void settings() {
// brute MS Surface display density fix:
size($appWinWidth / displayDensity(), $appWinHeight / displayDensity());
MAXRAD/=displayDensity();
MAXSTROKE/=displayDensity();
}
color fgcolor() {
colorMode(HSB, 360, 100, 100);
return color(random(0, 120), random(50, 100), random(50, 100));
}
color bgcolor() {
colorMode(HSB, 360, 100, 100);
return color(random(150, 210), random(50, 100), random(10, 40));
}
void setup() {
background($appWinBG);
noFill();
noCursor();
frameRate(30);
minRad = MAXRAD / 8;
arcs = new Arc[FLOWERS];
colorMode(HSB, 360, 100, 100);
for (int i=0; i<FLOWERS; i++) {
color c = fgcolor();
arcs[i] = new Arc(
int(random(0,width)), int(random(0,height)), // pos
minRad, random(minRad,MAXRAD), // radius
int(random(2, MAXPETALS)), // petals
random(-PI, PI), random(0.05, 0.25), // st ang, ang vel
c, int(random(2, MAXSTROKE)) // color, stroke
);
}
}
/*
DRAW
*/
void draw() {
for (int i=0; i<arcs.length; i++) {
arcs[i].update();
arcs[i].display();
}
if ($saveFrameNum > 0 &&
frameCount > $saveFrameOffset && frameCount - $saveFrameOffset <= $saveFrameNum)
saveFrame("frames/#####.tga");
}
/* arcs */
class Arc {
PVector position;
float minrad, maxrad, rad, strot, rot, avel;
int strokew, petals;
color col, bgcol;
Arc(int x, int y, float mird, float mxrd, int p, float sr, float av, color c, int sw) {
position = new PVector(x, y);
minrad = mird;
maxrad = mxrd;
rad = random(minrad, maxrad);
rot = sr;
avel = sr >=0 ? av : 0-av;
petals = p;
col = c;
strokew = sw;
}
void update() {
rot+=avel;
if (rot > TAU*ROTATIONS || rot < -TAU*ROTATIONS) {
position = new PVector(int(random(0,width)), int(random(0,height)));
avel = 0 - avel;
col = fgcolor();
bgcol = bgcolor();
strokew = int(random(2, MAXSTROKE));
petals = int(random(2, MAXPETALS));
windowBlur(bgcolor(), 2);
}
rad = lerp(minrad, maxrad, abs(sin(rot*petals)));
}
void display() {
blendMode(SCREEN);
stroke(col, 64);
strokeWeight(strokew);
noFill();
PVector angvec = PVector.fromAngle(rot).setMag(rad);
PVector drawto = PVector.add(position, angvec);
line(position.x, position.y,
drawto.x, drawto.y);
}
}
/* Full window blur */
void windowBlur(color bg, int opacity) {
blendMode(BLEND);
noStroke();
fill(bg, opacity);
rectMode(CORNER);
rect(0,0, width, height);
noFill();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment