xxxxxxxxxx
113
remaining=[];
step=[];
balls=[];
chosen=[];
r=150;
sr=20;
a=365;
speed =2;
testing=false;
function setup() {
createCanvas(400, 400);
for(var i=0; i<180;i+=10)
{
step[i]=i;
}
for (var i=0; i<75; i++)
{
randr=floor(random(0,(r/2)-10)); // Rand dist from hopper center
randa=floor(random(0,361)); // Rand angle from hopper center
x=randr* cos(radians(randa)); // X of small ball
y=randr* sin(radians(randa)); // Y of small ball
balls[i]=createVector(x,y); // Add ball to hopper
remaining[i]=i+1;
chosen[i]=0;
}
}
function draw() {
background(220);
animate();
}
function mousePressed()
{
if(!animation)
{
animation=true;
}
}
animation=false;
//This function shows the rotation of the ball hopper.
function animate(){
fill(255)
noStroke();
rect(0,0, width/4-5, height/2-5)
stroke(0);
background(255);
noFill();
push()
translate(width/2, height/2);
if(animation)
{
// gravity();
a-=speed;
rotate(radians(a));
if(a==180)
{
balls.pop();
lastpull=remaining.pop();
if(!testing)
{
shuffle(remaining,1);
}
chosen[lastpull-1]=1;
fill(0);
}
}
rlength=remaining.length
for(var i=0; i<rlength; i++)
{
// bx=balls[i].x;
//by=balls[i].y;
//txt=remaining[i];
bx=by=0;
txt="0";
point(bx,by);
point(bx,by);
//text("TEST", bx,by);
textSize(20);
//textAlign(CENTER, CENTER);
//text(frameRate(), width / 4, height / 4);
//arc(bx,by, sr,sr, 0, TWO_PI);
// fill(255);
circle(bx,by, sr);
//rect(bx,by,sr,sr);
//fill(0);
textSize(10);
text(txt, bx-5, by+5);
}
noFill()
for(var i=0; i<step.length; i++)
{
ellipse(0, 0, r, r-step[i]);
}
circle(0,0, r)
circle(r/2*(cos(radians(0))), r/2*(sin(radians(0))), 5);
pop();
textAlign(CENTER, CENTER);
text(floor(frameRate()), width / 4, height / 4);
if(a<=0)
{
// animation=false;
a=360;
}
}