Last active
May 21, 2020 23:35
-
-
Save georgesb/16f7194da67c2df28d3921ff86bf7f13 to your computer and use it in GitHub Desktop.
Generative Art 2
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
<script src="https://cdn.jsdelivr.net/npm/p5@0.10.2/lib/p5.js"></script> | |
<script src="script.js"></script> |
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
let side; | |
let mid; | |
let v1, v2, v3, v4; | |
let f = []; | |
let x = []; | |
let y = []; | |
function setup() { | |
createCanvas(600, 400); | |
rectMode(CENTER); | |
noStroke(); | |
side = 200; | |
mid = side / 2; | |
v1 = createVector(mid, 0); | |
v2 = createVector(-mid, 0); | |
v3 = createVector(0, mid); | |
v4 = createVector(0, -mid); | |
f.push(v1, radians(90), radians(270), v2, radians(270), | |
radians(90), v3, radians(180), radians(0), | |
v4, radians(0), radians(180)); | |
x.push(100, 300, 500, 100, 300, 500); | |
y.push(100, 300, 100, 300, 100, 300); | |
for (let j = 0; j <= 5; j++) { | |
push(); | |
translate(x[j], y[j]); | |
fill(random(0, 255), random(0, 255), random(0, 255)); | |
rect(0, 0, side, side); | |
fill(random(0, 255), random(0, 255), random(0, 255)); | |
drawArc(); | |
pop(); | |
} | |
} | |
function drawArc() { | |
let index = round(random(0, 3)); | |
let values = [0, 3, 6, 9]; | |
let i = values[index]; | |
arc(f[i].x, f[i].y, side, side, f[i + 1], f[i + 2], PIE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment