xxxxxxxxxx
89
let sliders = [];
let sliderParams = [
[10, 300, 100],
[4, 100, 17],
[0, 30, 10],
[0, 10, 2],
[0, 300, 30],
[0, 200, 0],
[1, 10, 3],
[10, 100, 20]
];
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
background(0);
frameRate(10);
for(let i = 0; i < sliderParams.length; i++) {
let minv = sliderParams[i][0];
let maxv = sliderParams[i][1];
let startv = sliderParams[i][2];
sliders[i] = createSlider(minv, maxv, startv);
sliders[i].position(10, height + 20 + 30*i);
sliders[i].style('width', width/2 + 'px');
}
}
function draw() {
background(0);
let circleSize = sliders[0].value();
let rayCount = sliders[1].value();
let tipSize = sliders[2].value();
let tipN = sliders[3].value();
let lineLength = sliders[4].value();
let lineBeginR = sliders[5].value();
let strokeW = sliders[6].value();
let starN = sliders[7].value();
/* Random is optional! */
circleSize = random(10, 200);
rayCount = int(random(5, 50));
tipSize = random(0, 20);
tipN = int(random(1, 3));
lineLength = random(0, 100);
lineBeginR = random(0, circleSize);
strokeW = random(1, 6);
starN = random(7, 50);
noFill();
stroke(255);
strokeWeight(strokeW);
circle(width/2, height/2, circleSize);
for(let i = 0; i < rayCount; i++) {
let r1 = lineBeginR;
let r2 = circleSize/2 + lineLength;
let alpha = i * (360 / rayCount);
let x1 = width/2 + r1 * cos(alpha);
let y1 = height/2 + r1 * sin(alpha);
let x2 = width/2 + r2 * cos(alpha);
let y2 = height/2 + r2 * sin(alpha);
line(x1, y1, x2, y2);
if (i % tipN === 0)
circle(x2, y2, tipSize);
}
star(width/2, height/2,
circleSize/2-40, circleSize/2-20, starN);
}
function star(x, y, radius1, radius2, npoints) {
let angle = 360 / npoints;
let halfAngle = angle / 2.0;
beginShape();
for (let a = 0; a < 360; a += angle) {
let sx = x + cos(a) * radius2;
let sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius1;
sy = y + sin(a + halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}