int bandValue=0;//defines bandvalue
int countClicks=0;//defines countclicks
int firstBand=0;//defines firstband
int secondBand=0;//defines secondband
int thirdBand=0;//defines thirdband
int resistor_value=0;//defines resistor value)
void setup() {
size(500, 500);//sets screen size
}
void draw() {
background(275);//sets background colour to grey
for (int i=0; i<=450; i+=50) {//draws the 10 boxes to the left hand side
switch(i)
{
case 0:
fill(0);//makes 1st box black
break;
case 50:
fill(#7E4417);//makes 2nd box brown
break;
case 100:
fill(#B40923);//makes 3rd box red
break;
case 150:
fill(#F25B02);//makes 4th box orange
break;
case 200:
fill(#FFEB03);//makes 5th box yellow
break;
case 250:
fill(#A1CE0F);//makes 6th box green
break;
case 300:
fill(#0F9CCE);//makes 7th box blue
break;
case 350:
fill(#6111A7);//makes 8th box purple
break;
case 400:
fill(#938F8B);//makes 9th box silver
break;
case 450:
fill(#FFFEFA);//makes 10th box white
break;
}
rect(0, i, 50, 50);//draws a rectangle
}
textSize(50);//sets text size
text(resistor_value+“Ω”, width/2, height/2);//displays text
}
void mousePressed() {
countClicks++;//counts number of clicks
println(“Mouse clicks=”, countClicks);//displays mouse Click
println(mouseX, mouseY);
if ((mouseX>0&&mouseX<50)&&(mouseY>0&&mouseY<50)) {//sets the condition
bandValue=0;//sets bandvalue to 0
println(“BLACK”, bandValue);//displays bandvalue and black
}
if ((mouseX>0&&mouseX<50)&&(mouseY>50&&mouseY<100)) {//sets the condition
bandValue=1;//sets bandvalue to 1
println(“BROWN”, bandValue);//displays bandvalue and brown
}
if ((mouseX>0&&mouseX<50)&&(mouseY>100&&mouseY<150)) {//sets the condition
bandValue=2;//sets bandvalue to 2
println(“RED”, bandValue);//displays bandvalue and red
}
if ((mouseX>0&&mouseX<50)&&(mouseY>150&&mouseY<200)) {//sets the condition
bandValue=3;//sets bandvalue to 3
println(“ORANGE”, bandValue);//displays bandvalue and orange
}
if ((mouseX>0&&mouseX<50)&&(mouseY>200&&mouseY<250)) {//sets the condition
bandValue=4;//sets bandvalue to 4
println(“YELLOW”, bandValue);//displays bandvalue and yellow
}
if ((mouseX>0&&mouseX<50)&&(mouseY>250&&mouseY<300)) {//sets the condition
bandValue=5;//sets bandvalue to 5
println(“GREEN”, bandValue);//displays bandvalue and black
}
if ((mouseX>0&&mouseX<50)&&(mouseY>300&&mouseY<350)) {//sets the condition
bandValue=6;//sets bandvalue to 6
println(“BLUE”, bandValue);//displays bandvalue and blue
}
if ((mouseX>0&&mouseX<50)&&(mouseY>350&&mouseY<400)) {//sets the condition
bandValue=7;//sets bandvalue to 7
println(“VIOLET”, bandValue);//displays bandvalue and violet
}
if ((mouseX>0&&mouseX<50)&&(mouseY>400&&mouseY<450)) {//sets the condition
bandValue=8;//sets bandvalue to 8
println(“SILVER”, bandValue);//displays bandvalue and silver
}
if ((mouseX>0&&mouseX<50)&&(mouseY>450&&mouseY<500)) {//sets the condition
bandValue=9;//sets bandvalue to 9
println(“WHITE”, bandValue);//displays bandvalue and white
}
//if(countClicks==3){//resets number of clicks
// countClicks=0;
//}
switch(countClicks) {
case 1:
firstBand=bandValue;
println(“First band value is=”, firstBand);//displays first bandvalue
break;
case 2:
secondBand=bandValue;
println(“Second band value is=”, secondBand);//displays second bandvalue
break;
case 3:
thirdBand=bandValue;
println(“Third band value is=”, thirdBand);//displays third bandvalue
countClicks=0;
println("Calculate Resistor Value");//displays calculate resistor value
resistor_value=((firstBand*10)+secondBand)*int(pow(10, thirdBand));//calculates resistor value
println("Resistor Value is", resistor_value);//displays resistor value
}
}