xxxxxxxxxx
57
function setup() {
createCanvas(500, 500);
slider = createSlider(0, 10, 1);
textSize(12);
slider.position(10, 10);
slider.style('width', '100px');
frameRate(3);
}
function draw() {
background(0);
let unitWidth = 20;
let unitHeight = 20;
let strokeWidth = slider.value();
let rColor = 255-mouseX/2;
let gColor = 255-mouseY/2;
let bColor = 255-(mouseX+mouseY)/4;
let lightness = 30;
if (mouseIsPressed) {
background(random(lightness,rColor), random(lightness,gColor), random(lightness,bColor));
rColor = 0;
gColor = 0;
bColor = 0;
}
for (i=0; i<width; i=i+unitWidth) {
for (k=0; k<height; k=k+unitHeight) {
let x = round(random(3))
stroke(random(lightness,rColor), random(lightness,gColor), random(lightness,bColor));
strokeWeight(strokeWidth);
if (x==0){
line(i, k+unitHeight/2, i+unitWidth, k+unitHeight/2);
//ellipse(unitWidth/2+i, unitHeight/2+k, unitWidth, unitHeight);
} else if (x==1) {
line(i+unitWidth/2, k, i+unitWidth/2, k+unitHeight);
//rect(i, k, unitWidth, unitHeight);
} else if (x==2) {
line(i, k, i+unitWidth, k+unitHeight);
} else if (x==3) {
line(i+unitWidth, k, i, k+unitHeight);
}
}
}
fill(255);
noStroke();
text('stroke width', 125, 23);
}