xxxxxxxxxx
71
const circleDatail=300;
class Drop{
constructor(x,y,r){
this.center=createVector(x,y);
this.r=r;
this.vertices=[];
for(let i=0;i<circleDatail;i++){
let angle=map(i,0,circleDatail,0,TWO_PI);
let v=createVector(cos(angle),sin(angle));
v.mult(this.r);
v.add(this.center);
this.vertices[i]=v;
// this.color=color(random(50,215),0,0);
this.color=random(50,215);
}
}
tineC(x,y,r, z, c) {
let u = 1 / pow(2, 1 / c);
let center=createVector(x,y)
for (let v of this.vertices) {
let pc = p5.Vector.sub(v, center);
let h = abs(pc.mag());
let l=z*pow(u,(h-r));
let a=l/h;
// P = C + (P - C) * (cos(a) sin(a), -sin(a) cos(a))
//const translatedPb = p5.Vector.sub(P, C);
const rotatedX = pc.x * cos(a) + pc.y * sin(a);
const rotatedY = -pc.x * sin(a) + pc.y * cos(a);
const rotatedTranslatedP = createVector(rotatedX, rotatedY);
let C=center.copy().add(rotatedTranslatedP);
v.set(C);
}
}
tine(x,z,c){
for (let v of this.vertices){
v.x=v.x;
let u=1/pow(2,1/c);
v.y=v.y+z*pow(u,abs(v.x-x));
}
}
marble(other){
for (let v of this.vertices){
let c=other.center;
let p=v.copy();
p.sub(c);
let r=other.r;
let m=p.mag();
let root=sqrt(1+r*r/(m*m));
p.mult(root);
p.add(c);
v.set(p);
}
}
show(){
fill(this.color);
noStroke();
beginShape();
for(let v of this.vertices){
vertex(v.x,v.y);
}
endShape(CLOSE);
}
}