Pure math
Generative art in a tweet’s worth of code.
Each sketch below is a self-contained p5.js snippet, most small enough to fit in a single tweet. No assets and no libraries beyond p5 itself — just trigonometry, a loop, and a canvas. The code is shown exactly as it runs, live, beside it. Click any sketch to open it full screen.
Flower field
#つぶやきProcessing
A tweet-sized sketch: one chained arrow function turns a loop counter into 10,000 points, warped by nested sine and cosine terms into a slowly rotating flower.
a=(y,d=mag(k=(4+cos(i/9-t*2))*cos(i/35),e=y/7-13)+sin(e/9+t/2)-4)=>point((q=2*sin(k*3)-y/35*k*(9+k*sin(cos(e)*9-d*2+t)))+40*cos(c=d-t)+200,q*sin(c)+d*35)
t=0,draw=$=>{t||createCanvas(w=400,w);background(9).stroke(w,96);for(t+=PI/80,i=1e4;i--;)a(i/235)}Rotating rose
Dwayne Helena
A four-petal polar rose, r = 160·cos(4θ + 2t), traced out as a fading point cloud rather than a solid line.
t=0,draw=$=>{t||createCanvas(400,400);background(8,30);stroke(255,120);t+=0.015;for(i=2200;i--;){a=i*0.01;r=160*cos(4*a+t*2);point(200+r*cos(a),200+r*sin(a))}}Lissajous cloud
Dwayne Helena
A 3:5 Lissajous figure resampled every frame as a scatter of points instead of a traced curve.
t=0,draw=$=>{t||createCanvas(400,400);background(8,25);stroke(0,200,255,140);t+=0.01;for(i=3000;i--;){a=i*0.01;point(200+160*sin(3*a+t),200+160*sin(5*a))}}Spiral field
Dwayne Helena
An Archimedean spiral perturbed by a slow sine wobble and flattened on one axis.
t=0,draw=$=>{t||createCanvas(400,400);background(8,20);stroke(255,180,60,150);t+=0.02;for(i=4000;i--;){a=i*0.03;r=a*1.4+40*sin(a*0.2+t);point(200+r*cos(a+t),200+r*sin(a+t)*0.6)}}Superformula star
Dwayne Helena
Johan Gielis's superformula, r(θ) built from |cos| and |sin| raised to fractional powers, tracing a seven-pointed starfish.
t=0,draw=$=>{t||createCanvas(400,400);background(8,20);stroke(255,160,220,150);t+=0.01;m=7,n1=0.3,n2=1.7,n3=1.7;for(i=2000;i--;){a=i*0.01;r=pow(pow(abs(cos(m*a/4)),n2)+pow(abs(sin(m*a/4)),n3),-1/n1)*40;point(200+r*cos(a+t),200+r*sin(a+t))}}Wave interference
Dwayne Helena
Two point sources emit sine waves across a sampled grid; each cell’s brightness is the sum of both waves at that point.
t=0,draw=$=>{t||createCanvas(400,400);background(8);noStroke();t+=0.15;for(x=0;x<400;x+=4)for(y=0;y<400;y+=4){d1=dist(x,y,150,200);d2=dist(x,y,250,200);v=sin(d1*0.2-t)+sin(d2*0.2-t);fill(255,(v+2)*60);rect(x,y,3,3)}}Epicycloid
Dwayne Helena
A small circle of radius 23 rolling around the outside of a radius-60 circle traces this looping curve.
t=0,draw=$=>{t||createCanvas(400,400);background(8,15);stroke(120,255,180,150);t+=0.02;R=60,rr=23;for(i=2500;i--;){a=i*0.02+t;x=(R+rr)*cos(a)-rr*cos((R+rr)/rr*a);y=(R+rr)*sin(a)-rr*sin((R+rr)/rr*a);point(200+x,200+y)}}Hypotrochoid
Dwayne Helena
The classic Spirograph curve: a point offset from a small circle rolling inside a larger ring.
t=0,draw=$=>{t||createCanvas(400,400);background(8,15);stroke(255,140);t+=0.02;R=120,rr=37,d=80;for(i=3000;i--;){a=i*0.03+t;x=(R-rr)*cos(a)+d*cos((R-rr)/rr*a);y=(R-rr)*sin(a)-d*sin((R-rr)/rr*a);point(200+x*0.8,200+y*0.8)}}Moiré rings
Dwayne Helena
Two sets of concentric rings, one drifting slowly off-centre, interfere to produce a moiré pattern.
t=0,draw=$=>{t||createCanvas(400,400);background(8);stroke(255,50);noFill();t+=0.01;for(i=40;i--;)ellipse(200+30*cos(t),200+30*sin(t),i*18,i*18);for(i=40;i--;)ellipse(200,200,i*18,i*18)}Phyllotaxis
Dwayne Helena
Points placed at the golden angle, 137.5° apart, reproduce the sunflower-seed packing pattern found across nature.
t=0,draw=$=>{t||createCanvas(400,400);background(8,18);noStroke();fill(255,150);t+=0.01;for(i=600;i--;){a=i*2.399963+t;r=9*sqrt(i);ellipse(200+r*cos(a),200+r*sin(a),3,3)}}Kaleidoscope mandala
Dwayne Helena
An eight-fold mirror applied to a single wavy radial curve turns it into a mandala.
t=0,draw=$=>{t||createCanvas(400,400);background(8,25);stroke(255,210,90,160);t+=0.02;n=8;for(i=800;i--;){a=i*0.05;r=100+60*sin(a*3+t*2);for(k=0;k<n;k++){ang=a+k*TWO_PI/n;point(200+r*cos(ang),200+r*sin(ang))}}}Concentric polygons
Dwayne Helena
Regular polygons from a triangle to a nonagon, alternating rotation direction, nested by radius.
t=0,draw=$=>{t||createCanvas(400,400);background(8,25);stroke(255,150);noFill();t+=0.01;for(s=3;s<10;s++){beginShape();for(i=0;i<=s;i++){a=i/s*TWO_PI+t*(s%2?1:-1);r=20+s*16;vertex(200+r*cos(a),200+r*sin(a))}endShape(CLOSE)}}Ulam prime spiral
Dwayne Helena
Walk outward in a square spiral, marking every prime number up to 6,000. Structure isn’t supposed to appear — yet diagonal lines do.
t=0,draw=$=>{if(t)return;t=1;createCanvas(400,400);background(8);noStroke();fill(255);isP=v=>{if(v<2)return false;for(d=2;d*d<=v;d++)if(v%d===0)return false;return true};x=200,y=200,dx=1,dy=0,n=0,steps=1,turns=0;for(v=1;v<6000;v++){if(isP(v))rect(x,y,2,2);x+=dx*3;y+=dy*3;n++;if(n===steps){n=0;[dx,dy]=[-dy,dx];turns++;if(turns%2===0)steps++}}}Noise flow field
Dwayne Helena
500 particles drift along a Perlin-noise vector field, each trail fading into the next frame.
ps=[],t=0,draw=$=>{if(!t){createCanvas(400,400);background(8);for(i=500;i--;)ps.push({x:random(400),y:random(400)})}t+=0.008;background(8,10);stroke(140,200,255,150);for(p of ps){a=(noise(p.x*0.008,p.y*0.008,t)-0.5)*TWO_PI*3;p.x+=cos(a)*1.5;p.y+=sin(a)*1.5;point(p.x,p.y);if(p.x<0||p.x>400||p.y<0||p.y>400){p.x=random(400);p.y=random(400)}}}