xxxxxxxxxx
224
pullx=-10;
pully=-10;
speed=2;
chosen = [];
remaining=[];
balls=[];
step=[];
lastpull=0;
sr=20;
complete=true; // Flag used for animation completion
auto=false; // flag used for auto drawing
//step=0;
a=q=0;
r=150;
stepvel=-1;
var animation=false;
function setup() {
createCanvas(800, 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));
randa=floor(random(0,361));
x=randr* cos(radians(randa));
y=randr* sin(radians(randa));
balls[i]=createVector(x,y);
remaining[i]=i+1;
chosen[i]=0;
}
shuffle(remaining,1);
}
BINGO = "BINGO "; //["B", "I", "N", "G", "O"];
function draw() {
//background(255);
animate();
complete=!animation;
if(complete)
{
q=0;
show();
complete=false;
if(auto)
{
animation=true;
}
}
}
function show() {
line(0, height / 2, width, height / 2);
line(30, height / 2, 30, height);
fill(0);
for (var i = 0; i < 6; i++) {
textSize(20);
var nextletter = BINGO[i];
text(nextletter, 5, (height / 2 + 25) + 40 * i);
var y = (height / 2) + 40 * i + 1;
line(0, y, width, y);
//line(0, height/2+25, width, height/2+25);
}
line(0, height - 1, width, height - 1);
line(width-1, height/2, width, height-1);
line(1, height/2, 1, height);
// Show all numbers in their rows
var row = 0;
var w = (width - 30) / 15;
var c = 1;
fill(255);
noStroke();
rect(width/2-5,0, width/2, height/2);
stroke(0);
fill(0);
textSize(100);
if(lastpull)
{
if(lastpull<75)
{
text(BINGO[floor(lastpull/15)]+"" +lastpull, (width/4)*3, height/4);
}
else
{
text("I" +lastpull, (width/4)*3, height/4);
}
}
for (var i = 0; i < 5; i++) {
for(j=0; j<15; j++){
fill('white');
if(chosen[c-1])
{
fill(0,0,255,150);
}
if(c==lastpull)
{
fill(255,0,0,150);
}
circle(31+(w/2)+(j*w), (height/2+40*i+1)+20,w);
fill('black');
textSize(15);
text(c, 30+(w/4)+(j*w), (height/2+40*i+1)+25)
c++;
}
}
}
function keyPressed()
{
if(keyCode==32)
{
if(!animation)
animation=true;
}
if(keyCode==65)
{
auto=!auto;
if(auto)
{
speed=1.5;
}
else
{
speed=2;
}
}
}
function touchStarted()
{
if(!animation)
animation=true;
}
function animate(){
fill(255)
noStroke();
rect(0,0, width/2-5, height/2-5)
stroke(0);
//background(255);
noFill();
push()
translate(width/8, height/4);
if(animation)
{
q+=0.5;
gravity();
a-=speed;
rotate(radians(a));
if(a==180)
{
balls.pop();
lastpull=remaining.pop();
chosen[lastpull-1]=1;
fill(0);
}
}
for(var i=0; i<remaining.length; i++)
{
fill(255);
circle(balls[i].x,balls[i].y, sr);
fill(0);
textSize(10);
text(remaining[i], balls[i].x-5, balls[i].y+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();
//b+=1;
if(a<=0)
{
animation=false;
a=360;
}
}
function gravity(){
bspeed=0.95;
{
targeta=a;
}
for(b of balls)
{
x=(r/4)*cos(radians(targeta));
y=(r/4)*sin(radians(targeta));
if(b.x<x)
b.x+=bspeed;
else if(b.x>x)
b.x-=bspeed;
if(b.y<y)
b.y+=bspeed;
else if(b.y>y)
b.y-=bspeed;
d=dist(b.x, b.y, x,y)
//line(b.x,b.y, x,y)
if(d<sr/2)
{
arand=floor(random(0,a+90)); // angle off of center
drand=floor(random(sr,(r/2)-sr/2));// distance off center
b.x=drand*cos(radians(arand));
b.y=drand*sin(radians(arand));
}
}
}