xxxxxxxxxx
let radius = 25
let numSides = 5
let offsets = 6
let col = [255,0,0]
let messy = false
function setup() {
createCanvas(windowWidth, windowHeight);
noFill();
}
function draw(){
x = mouseX
y = mouseY
stroke(random(255),random(255),random(255))
if (messy){
randomPolygon(x,y,numSides,radius)
noFill()
} else{
polygon(x,y,numSides,radius)
strokeWeight(5)
fill(col)
}
}
function mousePressed(){
radius = random(25,50)
numSides = random(2,15)
offsets = random(2,5)
background(col)
col = [random(255),random(255),random(255)]
if (random()>0.7){
messy= true
} else {
messy = false
}
}
function polygon(x,y,sides,radius){
let angle = TWO_PI / sides;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius;
let sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}
function randomPolygon(x,y,sides,offsets){
push()
translate(x,y)
beginShape();
for (j = 0; j < sides; j++){
vertex(random(-100,100),random(-100,100))
}
endShape(CLOSE);
pop()
}