//declare the variables
var secureStorageComb_0;
var secureStorageComb_1;
function preload()
{
//IMAGES WILL BE LOADED HERE
}
function setup()
{
createCanvas(512,512);
//initialise the variables
secureStorageComb_0 = 0;
secureStorageComb_1 = 0;
}
///////////////////EVENT HANDLERS///////////////////
//Add your code to these events to open the safe ...
function mouseMoved()
{
secureStorageComb_0 = 0;
secureStorageComb_1 = 0;
console.log("mouseMoved", mouseX, mouseY);
}
function mouseDragged()
{
secureStorageComb_1 = (secureStorageComb_1 + 54);
console.log("mouseDragged", mouseX, mouseY);
}
function mousePressed()
{
secureStorageComb_0 =(secureStorageComb_0 + 14);
secureStorageComb_1 =(secureStorageComb_1 + 34);
console.log("mousePressed");
}
function mouseReleased()
{
secureStorageComb_0 = (secureStorageComb_0 + 6);
secureStorageComb_1 = (secureStorageComb_1 + 77);
console.log("mouseReleased");
}
function keyPressed()
{
secureStorageComb_0 = (secureStorageComb_0 + 15);
console.log("keyPressed", key);
}
function keyReleased()
{
secureStorageComb_0 = (secureStorageComb_0 + 41);
secureStorageComb_1 = (secureStorageComb_1 + 86);
console.log("keyReleased", key);
}
///////////////DO NOT CHANGE CODE BELOW THIS POINT///////////////////
function draw()
{
//Draw the safe door
background(70);
noStroke();
fill(29,110,6);
rect(26,26,width-52,width-52);
//Draw the combination dial
push();
translate(200,height/2);
drawDial(200, secureStorageComb_0, 43);
pop();
//Draw the lever
push();
translate(width - 125,256);
drawLever(secureStorageComb_1);
pop();
}
function drawDial(diameter,num,maxNum)
{
//the combination lock
var r = diameter * 0.5;
var p = r * 0.6;
stroke(0);
fill(255,255,200);
ellipse(0,0,diameter,diameter);
fill(100);
noStroke();
ellipse(0,0,diameter*0.66,diameter*0.66);
fill(150,0,0);
triangle(
-p * 0.4,-r-p,
p * 0.4,-r-p,
0,-r-p/5
);
noStroke();
push();
var inc = 360/maxNum;
rotate(radians(-num * inc));
for(var i = 0; i < maxNum; i++)
{
push();
rotate(radians(i * inc));
stroke(0);
line(0,-r*0.66,0,-(r-10));
noStroke();
fill(0);
text(i,0,-(r-10));
pop();
}
pop();
}
function drawLever(rot)
{
push();
rotate(radians(-rot))
stroke(0);
fill(100);
rect(-10,0,20,100);
ellipse(0,0,50,50);
ellipse(0,100,35,35);
pop();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>