Created
January 14, 2023 15:38
-
-
Save edmorais/e4d05e4c36535eb42936a6c9efd2c195 to your computer and use it in GitHub Desktop.
Genuary2023 14: Random flowers & arcs, movement with parallax effect
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
/* | |
____ __ __ __ ___ _ | |
/ __/__/ /_ _____ ________/ /__ / |/ /__ _______ _(_)__ | |
/ _// _ / // / _ `/ __/ _ / _ \ / /|_/ / _ \/ __/ _ `/ (_-< | |
/___/\_,_/\_,_/\_,_/_/ \_,_/\___/ /_/ /_/\___/_/ \_,_/_/___/ | |
Genuary 2023! 14 | |
* 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; | |
float MAXSPD = 4; | |
int FLOWER_NUM = 64; | |
int CURVE_NUM = 128; | |
// globals | |
Flower[] flowers; | |
Curve[] curves; | |
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), 16); | |
} | |
void setup() { | |
$appWinBG = bgcolor(); | |
background($appWinBG); | |
noFill(); | |
noCursor(); | |
frameRate(30); | |
minRad = MAXRAD / 8; | |
flowers = new Flower[FLOWER_NUM]; | |
curves = new Curve[CURVE_NUM]; | |
colorMode(HSB, 360, 100, 100); | |
for (int i=0; i<FLOWER_NUM; i++) { | |
flowers[i] = new Flower( | |
int(random(width,width*2)), int(random(0,height)), // pos | |
minRad, random(minRad,MAXRAD), // radius | |
int(random(2, random(MAXPETALS/2, MAXPETALS))), // petals | |
random(-PI, PI), // st ang | |
random(1, MAXSPD), // linear vel | |
fgcolor(), int(random(2, MAXSTROKE)) // color, stroke | |
); | |
} | |
for (int i=0; i<CURVE_NUM; i++) { | |
curves[i] = new Curve( | |
int(random(width,width*2)), int(random(0,height)), // pos | |
random(minRad, MAXRAD*4), // radius | |
random(-PI, PI), random(-0.01,0.01), // st ang, ang vel | |
random(1, MAXSPD), // linear vel | |
fgcolor(), int(random(2, MAXSTROKE/4)) // color, stroke | |
); | |
} | |
} | |
/* | |
DRAW | |
*/ | |
void draw() { | |
for (int i=0; i<flowers.length; i++) { | |
flowers[i].update(); | |
flowers[i].display(); | |
} | |
for (int i=0; i<curves.length; i++) { | |
curves[i].update(); | |
curves[i].display(); | |
} | |
windowBlur($appWinBG, 96); | |
if ($saveFrameNum > 0 && | |
frameCount > $saveFrameOffset && frameCount - $saveFrameOffset <= $saveFrameNum) | |
saveFrame("frames/#####.tga"); | |
} | |
/* curves */ | |
class Curve { | |
PVector position, cen; | |
float dia, strot, rot, avel, xvel; | |
int strokew; | |
color col; | |
PGraphics gfx; | |
Curve(int x, int y, float r, float sr, float av, float xv, color c, int sw) { | |
position = new PVector(x,y); | |
dia = r*2; | |
strot = sr; | |
rot = 0; | |
avel = av; | |
xvel = xv; | |
col = c; | |
strokew = sw; | |
gfx = createGraphics(int(dia+16), int(dia+16)); | |
cen = new PVector(gfx.width/2, gfx.height/2); | |
} | |
void update() { | |
rot+=avel; | |
position.x-=xvel; | |
if (position.x < 0-dia) { | |
position = new PVector(int(random(width,width*2)), int(random(0,height))); | |
avel = 0 - avel; | |
col = fgcolor(); | |
strokew = int(random(2, MAXSTROKE)); | |
gfx.clear(); | |
} | |
} | |
void display() { | |
gfx.beginDraw(); | |
gfx.blendMode(BLEND); | |
gfx.stroke(col, 24); | |
gfx.strokeWeight(strokew); | |
gfx.noFill(); | |
gfx.arc(cen.x, cen.y, | |
dia,dia, | |
strot+rot, strot+rot*2); | |
gfx.endDraw(); | |
blendMode(SCREEN); | |
image(gfx, position.x, position.y); | |
} | |
} | |
/* our flower figure */ | |
class Flower { | |
PVector position, cen; | |
float minrad, maxrad, rad, strot, rot, avel, xvel; | |
int strokew, petals; | |
color col; | |
PGraphics gfx; | |
Flower(int x, int y, float mird, float mxrd, int p, float sr, float xv, color c, int sw) { | |
position = new PVector(x, y); | |
minrad = mird; | |
maxrad = mxrd; | |
rad = random(minrad, maxrad); | |
rot = sr; | |
xvel = xv; | |
avel = xv/30; | |
avel = sr >=0 ? avel : 0-avel; | |
petals = p; | |
col = c; | |
strokew = sw; | |
gfx = createGraphics(int(maxrad*2+16), int(maxrad*2+16)); | |
cen = new PVector(gfx.width/2, gfx.height/2); | |
} | |
void update() { | |
rot+=avel; | |
position.x-=xvel; | |
if (position.x < 0-maxrad*2) { | |
position = new PVector(int(random(width,width*2)), int(random(0,height))); | |
avel = 0 - avel; | |
col = fgcolor(); | |
strokew = int(random(2, MAXSTROKE)); | |
petals = int(random(2, MAXPETALS)); | |
gfx.clear(); | |
} | |
rad = lerp(minrad, maxrad, abs(sin(rot*petals))); | |
} | |
void display() { | |
gfx.beginDraw(); | |
gfx.blendMode(SCREEN); | |
gfx.stroke(col, 64); | |
gfx.strokeWeight(strokew); | |
gfx.noFill(); | |
PVector angvec = PVector.fromAngle(rot).setMag(rad); | |
PVector drawto = PVector.add(cen, angvec); | |
gfx.line(cen.x, cen.y, | |
drawto.x, drawto.y); | |
gfx.endDraw(); | |
blendMode(SCREEN); | |
image(gfx, position.x, position.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