let ph1;
//variables
var fillbox;
var fillphoton;
function setup()
{
createCanvas(400, 400);
ph1=new photon();
}
function draw()
{
background(220);
//ellipse
fill("white")
ellipse(200,150,50,100)
//photon
ph1.show()
ph1.move()
//functions
boxes();
choice();
//function for boxes
function boxes()
{
fill("white")
rect(20,250,20,20);
fill("red")
rect(45,250,20,20);
fill("blue")
rect(70,250,20,20);
fill("green")
rect(95,250,20,20);
fill("white")
rect(200,250,20,20);
fill("red")
rect(225,250,20,20);
fill("blue")
rect(250,250,20,20);
fill("green")
rect(275,250,20,20);
}
//function for filling circle
function mousePressed()
{
//box1
if(mouseX>20 && mouseX<40 && mouseY>250 && mouseY<270)
{
fillbox=1;
}
//box2
if(mouseX>45 && mouseX<65 && mouseY>250 && mouseY<270)
{
fillbox=2;
}
//box3
if(mouseX>70 && mouseX<90 && mouseY>250 && mouseY<270)
{
fillbox=3;
}
//box3
if(mouseX>95 && mouseX<115 && mouseY>250 && mouseY<270)
{
fillbox=4;
}
if(mouseX>200&&mouseX<220&&mouseY<270&&mouseY>250)
{
fillphoton=1;
}
//box2
if(mouseX>225&&mouseX<245&&mouseY<270&&mouseY>250)
{
fillphoton=2;
}
//box3
if(mouseX>250&&mouseX<270&&mouseY<270&&mouseY>250)
{
fillphoton=3;
}
//box3
if(mouseX>275&&mouseX<295&&mouseY<270&&mouseY>250)
{
fillphoton=4;
}
}
function choice()
{
if(fillbox==1)
{
fill("white")
ellipse(200,150,50,100)
if(fillbox==2)
{
fill("red")
ellipse(200,150,50,100)
}
if(fillbox==3)
{
fill("blue")
ellipse(200,150,50,100)
}
if(fillbox==4)
{
fill("green")
ellipse(200,150,50,100)
}
}
//class for photon to move and show
class photon
{
constructor()
{
this.x=0
}
show()
{
if(fillphoton==1)
{
fill("white")
ellipse(this.x,200,15)
if(fillphoton==2)
{
fill("red")
ellipse(this.x,200,15)
}
if(fillphoton==3)
{
fill("blue")
ellipse(this.x,200,15)
}
if(fillphoton==4)
{
fill("green")
ellipse(this.x,200,15)
}
}
move()
{
this.x=this.x+10
if(this.x>400)
{
this.x=0
}
}
}
function()
{
if
}