xxxxxxxxxx
function setup() {
createCanvas(w=720, w);
background(255);
fill(0);
strokeWeight(0);
let num = 1500;
for(let i=0;i<num;i++){
push();
translate(w*0.025+w*0.95*random(), w*0.025+w*0.4625*random())
dango(15, "#ff8888");
pop();
}
for(let i=0;i<num;i++){
push();
translate(w*0.025+w*0.95*myRand(), w-w*0.025-w*0.4625*myRand())
dango(15, "#8888ff");
pop();
}
fill(255);
strokeWeight(10);
stroke(0);
textSize(w*0.075);
textAlign(CENTER, CENTER);
text("p5.js random()", w/2, w*0.25);
text("myRand()", w/2, w-w*0.25);
}
prand = undefined
function myRnadSeed(seed){
prand = seed
}
function myRand(){
if(prand == undefined){
prand = 1234567890 + second()
}
let N = Number.MAX_SAFE_INTEGER + 10
for(let i=0;i<5;i++){
prand += 1/N
prand *= 123456789
prand += 987654321
prand += 0.1*N*prand*(sin(prand * 0.123456789) + cos(prand * 0.987654321))
prand = prand % N
prand /= N
}
prand = abs(prand)
return prand
}
function dango(size, fcolor){
push();
strokeWeight(size/18);
translate(0, 0)
fill(fcolor);
ellipse(0, 0, size);
face(size);
pop();
}
function face(size){
push();
fill("#000000");
strokeWeight(size/18);
ellipse(size/8*2, -size/10, size/14);
ellipse(-size/8, -size/10, size/14);
fill(0,0);
arc(size/8, size/20, size/10*1.25, size/10, -PI/2*1.25, PI/2*1.25);
arc(size/8*0.6, size/16*3.5, size/4, size/10, 0, PI);
pop();
}