xxxxxxxxxx
// ----------------------------------------
// Easy to read code :-)
// ----------------------------------------
let f=0; // Used for animation
function setup() {
createCanvas(400,400);
stroke(255);
}
function draw() {
background(0);
for(i=0;i<TAU;i+=PI/16){
// Calculate movement for the inner circle points
let r=85;
let x=sin(f+i)*r+200;
let y=cos(f+i)*r+200;
circle(x,y,6);
// Calculate movement for points on the square
r=170;
let X=sin(f+i)*r+200;
let Y=cos(f+i)*r+200;
if(X>320) X=320;
if(X<80) X=80;
if(Y>320) Y=320;
if(Y<80) Y=80;
line(x,y,X,Y);
circle(X,Y,6);
// Calculate movement for the outer circle points
x=sin(f+i)*r+200;
y=cos(f+i)*r+200;
line(x,y,X,Y);
circle(x,y,6);
}
f+=0.01; // Animate by increasing the value
}
// ----------------------------------------
// !!! Warning!!!
// Nerdy stuff bellow
// ----------------------------------------
// ----------------------------------------
// Pre-compressed code
// ----------------------------------------
// f=0
// draw=_=> {
// f||createCanvas(W=400,W)
// background(f+=.01)
// C=circle
// for(i=0;i<TAU;i+=.19){
// C(X=S(r=170),Y=O(stroke(g=320)),6)
// X=X>g?g:X
// Y=Y>g?g:Y
// C(X=X<80?80:X,Y=Y<80?80:Y,6)
// line(x,y,X,Y)
// line(S(r=85),O(),X,Y)
// C(x,y,6)
// }
// }
// S=_=>x=sin(f+i)*r+200
// O=_=>y=cos(f+i)*r+200
// ----------------------------------------
// Compressed code
// ----------------------------------------
// f=0,draw=e=>{for(f||createCanvas(W=400,W),background(f+=.01),C=circle,i=0;i<TAU;i+=.19)C(X=S(r=170),Y=O(stroke(g=320)),6),X=X>g?g:X,Y=Y>g?g:Y,C(X=X<80?80:X,Y=Y<80?80:Y,6),line(x,y,X,Y),line(S(r=85),O(),X,Y),C(x,y,6)},S=X=>x=sin(f+i)*r+200,O=X=>y=cos(f+i)*r+200