46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
//preload images
|
|
function preload() {
|
|
and = loadImage('assets/and.png');
|
|
not = loadImage('assets/not.png');
|
|
or = loadImage('assets/or.png');
|
|
xor = loadImage('assets/xor.png');
|
|
nand = loadImage('assets/nand.png');
|
|
nor = loadImage('assets/nor.png');
|
|
on = loadImage('assets/on.png');
|
|
off = loadImage('assets/off.png');
|
|
lon = loadImage('assets/lon.png');
|
|
loff = loadImage('assets/loff.png');
|
|
}
|
|
|
|
function setup() {
|
|
createCanvas(displayWidth, displayHeight);
|
|
gates = [];
|
|
gate1 = new Gate(150, 150, "not", not);
|
|
gate2 = new Gate(250, 250, "not", not);
|
|
gates.push(gate1);
|
|
gates.push(gate2);
|
|
}
|
|
|
|
function draw() {
|
|
background(255);
|
|
stroke(0);
|
|
gates.forEach(gate => {
|
|
gate.draw();
|
|
});
|
|
}
|
|
|
|
function mousePressed() {
|
|
gates.forEach(gate => {
|
|
if(gate.onGate(mouseX, mouseY)){
|
|
gate.selected = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
function mouseReleased() {
|
|
gates.forEach(gate => {
|
|
if(gate.onGate(mouseX, mouseY)){
|
|
gate.selected = false;
|
|
}
|
|
});
|
|
} |