Daily Coding(p5.js) No.21
Code
l
et st;
function setup() {
createCanvas(500, 500);
noLoop();
}
function draw() {
background(0);
stroke(254,204,204,100);
//stroke(204,255,255,100);
strokeWeight(3);
line(width/2, 0, width/2, height);
//stroke(204,255,255,40);
stroke(254,204,204,40);
line(width/2, 60, width, 60);
line(width/2, height/2, width, height/2);
line(width/2, 410, width, 410);
strokeWeight(2);
st = height/3;
for(let i = 0; i < int(random(6,9)); i++){
//stroke(204,255,255,25);
stroke(254,204,204,25);
ell(width/2, random(st, st + 20), random(30,60), 15);
st += 20;
}
st = height/10;
for(let i = 0; i < int(random(3,6)); i++){
//stroke(204,255,255,10);
stroke(254,204,204,10);
ell(width/2, random(st, st + 10), 30 ,15);
st += 10;
}
st = height-50;
for(let i = 0; i < int(random(3,6)); i++){
//stroke(204,255,255,10);
stroke(254,204,204,10);
ell(width/2, random(st, st - 10), 25 ,15);
st -= 10;
}
//stroke(204,255,255,50);
stroke(254,204,204,50);
randomline(100, width/2, 50, 350, 70, 1);
randomline(100, width/2, 50, 350, 70, 2);
randomline(200, width/2, height/2-20, 450, 150, 1);
randomline(200, width/2, height/2-20, 450, 150, 2);
randomline(100, width/2, height-100, 300, 20, 1);
randomline(100, width/2, height-100, 300, 20, 2);
}
function ell(x, y, a, b) {
let start = random(0, PI);
let goal = random(PI, PI*2);
for(let theta = start; theta < goal; theta+=0.01) {
//rad = radians(theta);
point(x + a * cos(theta), y + b * sin(theta));
}
}
function randomline(count,a, b, w, h, mode) {
if(mode == 1) {
for(let i = 0; i < count; i++) {
let x = random(a-w/2, a+w/2);
let y = random(b-h/2, b+h/2);
line(x, y, x, y + int(random(50)));
}
} else if(mode == 2) {
for(let i = 0; i < count*2; i++) {
let x1 = random(a-w/2, a+w/2);
let y1 = random(b-h/2, b+h/2);
let r = int(random(20,30));
let the = random(0,PI*2);
let x2 = x1 + r * cos(the);
let y2 = y1 + r * sin(the);
line(x1, y1, x2, y2);
}
}
}
function keyPressed() {
if(key == 'r') redraw();
}
ではでは
この記事が気に入ったらサポートをしてみませんか?