parent
d658db34bd
commit
7459fe550a
@ -0,0 +1,15 @@
|
||||
const imageHeight = 50;
|
||||
const imageWidth = 100;
|
||||
const pathImg = "../img/";
|
||||
const imageLogiqueEt = "logiqueet.png";
|
||||
const imageLogiqueOu = "logiqueou.png";
|
||||
const imageEnd = "idea_white.png";
|
||||
|
||||
//line
|
||||
const colorLineInnactive = "black";
|
||||
const colorLineActive = "#f6cd61";
|
||||
|
||||
//switch
|
||||
const colorSwitchBorder = "black";
|
||||
const colorSwitchInnactiveBackground = "red";
|
||||
const colorSwitchActiveBackground = "green";
|
@ -0,0 +1,158 @@
|
||||
function createEnd(x, y) {
|
||||
var imageObj2 = new Image();
|
||||
imageObj2.onload = function () {
|
||||
var end = new Konva.Image({
|
||||
x: x,
|
||||
y: y,
|
||||
image: imageObj2,
|
||||
width: 50,
|
||||
height: 50,
|
||||
id: "end",
|
||||
});
|
||||
|
||||
|
||||
layer.add(end);
|
||||
layer.batchDraw();
|
||||
};
|
||||
imageObj2.src = pathImg + imageEnd;
|
||||
}
|
||||
|
||||
function createSwitch(id, x, y) {
|
||||
switchs.push(id);
|
||||
var num = lineCount.length;
|
||||
lineCount.push(1);
|
||||
var rect1 = new Konva.Rect({
|
||||
x: x,
|
||||
y: y,
|
||||
width: 100,
|
||||
height: 50,
|
||||
stroke: colorSwitchBorder,
|
||||
fill: colorSwitchInnactiveBackground,
|
||||
strokeWidth: 4,
|
||||
id: id,
|
||||
id3: null,
|
||||
});
|
||||
|
||||
|
||||
layer.add(rect1);
|
||||
|
||||
}
|
||||
|
||||
function createLine(points, id) {
|
||||
let line = new Konva.Line({
|
||||
points: points,
|
||||
stroke: colorLineInnactive,
|
||||
strokeWidth: 3,
|
||||
lineCap: 'round',
|
||||
lineJoin: 'round',
|
||||
id: id,
|
||||
});
|
||||
layer.add(line);
|
||||
}
|
||||
|
||||
|
||||
function createLink(entre, sortie, lineId) {
|
||||
//entre est une porte logique
|
||||
switch (whatIsElement(entre)) {
|
||||
case "switch":
|
||||
switch (whatIsElement(sortie)) {
|
||||
case "logique":
|
||||
switch (giveLineId(sortie.name)) {
|
||||
case "id1":
|
||||
let switchMidX = entre.getX() + entre.getWidth();
|
||||
let switchMidY = entre.getY() + entre.getHeight() / 2;
|
||||
|
||||
let logiqueMidX = sortie.x;
|
||||
let logiqueMidY = sortie.y + (imageHeight / 3);
|
||||
createLine([switchMidX, switchMidY, logiqueMidX, logiqueMidY], "line" + lineId);
|
||||
setLine(sortie, "id1", "line" + lineId);
|
||||
entre.id3 = "line" + lineId;
|
||||
break;
|
||||
case "id2":
|
||||
createLine([entre.getX() + entre.getWidth(), entre.getY() + entre.getHeight() / 2, sortie.x, sortie.y + (imageHeight / 3) * 2], "line" + lineId);
|
||||
setLine(sortie, "id2", "line" + lineId);
|
||||
entre.id3 = "line" + lineId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "logique":
|
||||
switch (whatIsElement(sortie)) {
|
||||
case "logique":
|
||||
switch (giveLineId(sortie.name)) {
|
||||
case "id1":
|
||||
let switchMidX = entre.x + imageWidth;
|
||||
let switchMidY = entre.y + imageHeight / 2;
|
||||
|
||||
let logiqueMidX = sortie.x;
|
||||
let logiqueMidY = sortie.y + (imageHeight / 3);
|
||||
createLine([switchMidX, switchMidY, logiqueMidX, logiqueMidY], "line" + lineId);
|
||||
setLine(sortie, "id1", "line" + lineId);
|
||||
setLine(entre, "id3", "line" + lineId);
|
||||
break;
|
||||
case "id2":
|
||||
createLine([entre.x + imageWidth, entre.y + imageHeight / 2, sortie.x, sortie.y + (imageHeight / 3) * 2], "line" + lineId);
|
||||
setLine(sortie, "id2", "line" + lineId);
|
||||
setLine(entre, "id3", "line" + lineId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
function createLogique(x, y, id, type) {
|
||||
|
||||
switch (type) {
|
||||
case "et":
|
||||
var imageObj = new Image();
|
||||
imageObj.onload = function () {
|
||||
var et = new Konva.Image({
|
||||
x: x,
|
||||
y: y,
|
||||
image: imageObj,
|
||||
width: imageWidth,
|
||||
height: imageHeight,
|
||||
id: id,
|
||||
});
|
||||
|
||||
|
||||
layer.add(et);
|
||||
layer.batchDraw();
|
||||
};
|
||||
imageObj.src = pathImg + imageLogiqueEt;
|
||||
imageObj.id = id;
|
||||
break;
|
||||
case "ou":
|
||||
var imageObj = new Image();
|
||||
imageObj.onload = function () {
|
||||
var et = new Konva.Image({
|
||||
x: x,
|
||||
y: y,
|
||||
image: imageObj,
|
||||
width: imageWidth,
|
||||
height: imageHeight,
|
||||
id: id,
|
||||
});
|
||||
|
||||
|
||||
layer.add(et);
|
||||
layer.batchDraw();
|
||||
};
|
||||
imageObj.src = pathImg + imageLogiqueOu;
|
||||
imageObj.id = id;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var logique = {
|
||||
name: id,
|
||||
x: x,
|
||||
y: y,
|
||||
type: type,
|
||||
id1: null,
|
||||
id2: null,
|
||||
id3: null,
|
||||
}
|
||||
logiques.push(logique);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
function initAllSwitch(){
|
||||
switchs.forEach(function(element){
|
||||
let switche = stage.findOne("#"+element);
|
||||
switche.on('click', function () {
|
||||
let colorrect = switche.fill() == colorSwitchInnactiveBackground ? colorSwitchActiveBackground : colorSwitchInnactiveBackground;
|
||||
switche.fill(colorrect);
|
||||
changeLineColor(switche.id3);
|
||||
checkAllSortieLogique();
|
||||
layer.draw();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function initLayer() {
|
||||
createEnd(500,50);
|
||||
}
|
Loading…
Reference in new issue