Created
May 2, 2020 11:39
-
-
Save tamamu/5b20c39bbe2af927b0129169a81f7236 to your computer and use it in GitHub Desktop.
Draw 団子es with p5.js
This file contains hidden or 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 dangoes = []; | |
class Dango { | |
constructor(x, y, num) { | |
this.x = x; | |
this.y = y; | |
this.num = num; | |
this.rad = 0; | |
this.colors = | |
new Array(num) | |
.fill() | |
.map(() => Math.floor(Math.random() * 2)) | |
.map(v => v === 0 ? "white" : "pink"); | |
} | |
draw() { | |
const {x, y, num, colors, rad} = this; | |
stroke("black"); | |
strokeWeight(2); | |
line( | |
x-50*cos(rad), | |
y-50*sin(rad), | |
x+(30*num)*cos(rad), | |
y+(30*num)*sin(rad) | |
); | |
for (let i=0; i < num; ++i) { | |
const p = Math.random() <= 0.1; | |
fill(colors[i]); | |
ellipse( | |
x + (i * 30)*cos(rad), | |
y + (i * 30)*sin(rad), | |
30 | |
); | |
} | |
} | |
} | |
function setup() { | |
createCanvas(640, 480); | |
} | |
function pushDango(x, y, num = 3) { | |
dangoes.push(new Dango(x, y, num)); | |
} | |
function draw() { | |
background("white"); | |
for (let dango of dangoes) { | |
dango.draw(); | |
dango.rad += deltaTime * PI * 0.001; | |
} | |
} | |
function mouseClicked() { | |
pushDango(mouseX, mouseY, 3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment