erratic-gate/scripts/not.js
Mateiadrielrafael fe18c7cf5c
Add files via upload
Signed-off-by: prescientmoon <git@moonythm.dev>
2018-06-22 17:09:43 +03:00

94 lines
2.1 KiB
JavaScript

function not(id){
this.id = id;
this.name = "#" + this.id;
this.rep = add(80,80,"green","black",this.id,true);
this.pin1 = new pin(0);
this.o = new pin(1);
this.o.nei = this;
//this.text = new text(this,"Or-gate");
this.activation = function(){
if (!this.pin1.val){
return true;
}
return false;
}
this.x = function(){
let name = "#" + this.id;
return parseFloat($(name).attr("x"));
}
this.y = function(){
let name = "#" + this.id;
//console.log("y"+parseFloat($(name).attr("y")));
return parseFloat($(name).attr("y"));
}
//design
var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
$(g).attr({
width: "100%",
height: "100%"
});
var skin = $(document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject')).attr({
x: "50",
y: "50",
id: (id+"-skin"),
width:"80",
height:"80"
});
var img = $(document.createElement('img')).attr({
height:"80",
width:"80",
src:"textures/gates/not_gate.jpg"
});
var iDiv = document.createElement("div");
$(iDiv).append(img);
this.skin = skin;
this.img = img;
$(skin).append(iDiv);
//noname(this);
$(g).append(skin);
var elem = document.getElementById("svg1");
elem.appendChild(g);
//updating
this.update = function(){
//the main object and his pins
let x = this.x();
let y = this.y();
this.pin1.set(x-20,y+30);
this.o.set(x+80,y+30);
//and the skin
var name = "#"+this.id+"-skin";
var skin = $(name);
skin.attr("x",(parseFloat($((this.rep)).attr("x"))+4).toString());
skin.attr("y",(parseFloat($((this.rep)).attr("y"))+4).toString());
}
pieces[pieces.length] = this;
addclk11(this);
}
function addclk11(ob){
var rep = ob.rep;
$((ob.img)).mousedown(function(e){
var svg = document.getElementById("svg1");
$(svg).append(ob.rep);
$(svg).append($(ob.pin1.rep));
$(svg).append($(ob.o.rep));
$(svg).append($(ob.skin));
selected = ob.id;
});
$((ob.img)).mouseup(function(e){
selected = "yay";
});
}