update
parent
964555a374
commit
b67aafbe18
|
@ -1,25 +1,36 @@
|
||||||
class Gate {
|
class Gate {
|
||||||
constructor(x, y, type) {
|
constructor(x, y, type, image) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
this.image = image;
|
||||||
this.types = new Types(type);
|
this.types = new Types(type);
|
||||||
this.selected = false;
|
this.selected = false;
|
||||||
|
|
||||||
|
this.width = 50;
|
||||||
|
this.height = 50;
|
||||||
|
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
this.outputs = [];
|
this.outputs = [];
|
||||||
for(var i = 0; i < this.types.type.inputs; i++){
|
for (var i = 0; i < this.types.type.inputs; i++) {
|
||||||
//TODO calculate postions for ankors based on this.x and this.y
|
//TODO calculate postions for ankors based on this.x and this.y
|
||||||
this.inputs.push(new Ankor(this.x - 10, this.y));
|
this.inputs.push(new Ankor(this.x - 10, this.y));
|
||||||
}
|
}
|
||||||
for(var i = 0; i < this.types.type.outputs; i++){
|
for (var i = 0; i < this.types.type.outputs; i++) {
|
||||||
//TODO calculate postions for ankors based on this.x and this.y
|
//TODO calculate postions for ankors based on this.x and this.y
|
||||||
this.outputs.push(new Ankor(this.x + 10, this.y));
|
this.outputs.push(new Ankor(this.x + 10, this.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
//todo draw gate and ankors and use type to resolve image
|
//TODO draw ankors add exception for light and switch
|
||||||
|
//draw gate and load image
|
||||||
|
fill(255);
|
||||||
|
image(this.image, this.x, this.y);
|
||||||
|
noFill();
|
||||||
|
noStroke();
|
||||||
|
rect(this.x, this.y, this.width, this.height);
|
||||||
|
|
||||||
|
//draw ankors
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate() {
|
calculate() {
|
||||||
|
@ -27,17 +38,31 @@ class Gate {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onGate(x, y) {
|
||||||
|
if (
|
||||||
|
x > this.x &&
|
||||||
|
x < this.x + this.width &&
|
||||||
|
y > this.y &&
|
||||||
|
y < this.y + this.height
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
returnOnAnkor(x, y) {
|
returnOnAnkor(x, y) {
|
||||||
|
//todo add actual onankor that works with renderd circles
|
||||||
this.inputs.forEach(ankor => {
|
this.inputs.forEach(ankor => {
|
||||||
if(x == ankor.x && y == ankor.y){
|
if (x == ankor.x && y == ankor.y) {
|
||||||
return ankor;
|
return ankor;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.outputs.forEach(ankor => {
|
this.outputs.forEach(ankor => {
|
||||||
if(x == ankor.x && y == ankor.y){
|
if (x == ankor.x && y == ankor.y) {
|
||||||
return ankor;
|
return ankor;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
26
sketch.js
26
sketch.js
|
@ -14,15 +14,33 @@ function preload() {
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
createCanvas(displayWidth, displayHeight);
|
createCanvas(displayWidth, displayHeight);
|
||||||
var gate = new Gate(1, 2, "light");
|
gates = [];
|
||||||
console.log(gate)
|
gate1 = new Gate(150, 150, "not", not);
|
||||||
|
gate2 = new Gate(250, 250, "not", not);
|
||||||
|
gates.push(gate1);
|
||||||
|
gates.push(gate2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
background(0);
|
background(255);
|
||||||
stroke(255);
|
stroke(0);
|
||||||
|
gates.forEach(gate => {
|
||||||
|
gate.draw();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mousePressed() {
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue