amélioration des lignes, pour éviter les lignes continue, ajout d'une arrivé de niveau pouvant acceuillir un nombre infini de lignes

master
pisouvigne 5 years ago
parent 988a6e835d
commit 7887900dda

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

@ -1,17 +1,19 @@
//Portes Logiques //Portes Logiques
const imageHeight = 25; const imageHeight = 45;
const imageWidth = 50; const imageWidth = 50;
const imageRotation = 0;
//Image //Image
const pathImg = "../img/"; const pathImg = "../img/";
const imageLogiqueEt = "logiqueet.png"; const imageLogiqueEt = "eee.png";
const imageLogiqueOu = "logiqueou.png"; const imageLogiqueOu = "logiqueou.png";
const imageEnd = "idea_white.png"; const imageEnd = "idea_white.png";
//line //line
const colorLineInnactive = "black"; const colorLineInnactive = "black";
const colorLineActive = "#f6cd61"; const colorLineActive = "#46FEFE";
const lineStroke = 1; const lineStroke = 3;
const pourcentageBreak = 15;
//switch //switch
const SwitchHeight = 25; const SwitchHeight = 25;

@ -9,11 +9,17 @@ function createEnd(x, y) {
height: 50, height: 50,
id: "end", id: "end",
}); });
layer.add(end); layer.add(end);
layer.batchDraw(); layer.batchDraw();
}; };
end = {
name: "end",
x: x,
y: y,
type: "end",
position: 1,
let:1,
}
imageObj2.src = pathImg + imageEnd; imageObj2.src = pathImg + imageEnd;
} }
@ -36,8 +42,11 @@ function createSwitch(id, x, y) {
} }
function createLine(points, id) { function createLine(points, id) {
let startX = points[0], startY = points[1], endX = points[2], endY = points[3];
let distance20 = (endX - startX)/100*pourcentageBreak;
let newPoints = [startX, startY,startX + distance20, startY,endX - distance20,endY,endX,endY];
let line = new Konva.Line({ let line = new Konva.Line({
points: points, points: newPoints,
stroke: colorLineInnactive, stroke: colorLineInnactive,
strokeWidth: lineStroke, strokeWidth: lineStroke,
id: id, id: id,
@ -46,8 +55,10 @@ function createLine(points, id) {
} }
function createLink(entre, sortie, lineId) { function createLink(entre, sortie) {
//entre est une porte logique //entre est une porte logique
lineId = lineCount.length;
lineCount.push(1);
switch (whatIsElement(entre)) { switch (whatIsElement(entre)) {
case "switch": case "switch":
switch (whatIsElement(sortie)) { switch (whatIsElement(sortie)) {
@ -91,53 +102,47 @@ function createLink(entre, sortie, lineId) {
setLine(entre, "id3", "line" + lineId); setLine(entre, "id3", "line" + lineId);
break; break;
} }
break;
default:
endLines.push(lineId);
createLine([entre.x + imageWidth, entre.y + imageHeight / 2, sortie.x, sortie.y + (imageHeight / end.position+1)*end.let], "line" + lineId);
setLine(entre, "id3", "line" + lineId);
end.let--;
break;
} }
break; break;
} }
} }
function createLogique(x, y, id, type) { function createLogique(x, y, id, type) {
var imageObj = new Image();
switch (type) { imageObj.onload = function () {
case "et": var et = new Konva.Image({
var imageObj = new Image(); x: x,
imageObj.onload = function () { y: y,
var et = new Konva.Image({ image: imageObj,
x: x, width: imageWidth,
y: y, height: imageHeight,
image: imageObj, id: id,
width: imageWidth, });
height: imageHeight, if (imageRotation != 0) {
id: id, et.rotation(imageRotation);
}); et.x(et.getX() + imageHeight);
}
layer.add(et);
layer.add(et); layer.batchDraw();
layer.batchDraw(); };
}; switch(type){
case "et" :
imageObj.src = pathImg + imageLogiqueEt; imageObj.src = pathImg + imageLogiqueEt;
imageObj.id = id;
break; break;
case "ou": 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.src = pathImg + imageLogiqueOu;
imageObj.id = id;
break; break;
} }
imageObj.id = id;
var logique = { var logique = {

@ -1,5 +1,5 @@
function whatIsElement(element) { function whatIsElement(element) {
if (findLogique(element.name) == null) { if (findLogique(element.name) == null || findLogique(element.name) == undefined) {
return "switch"; return "switch";
} else { } else {
return "logique"; return "logique";

@ -1,22 +1,38 @@
function initAllSwitch(){ function initAllSwitch() {
switchs.forEach(function(element){ switchs.forEach(function (element) {
let switche = stage.findOne("#"+element); let switche = stage.findOne("#" + element);
switche.on('click', function () { switche.on('click', function () {
let colorrect = switche.fill() == colorSwitchInnactiveBackground ? colorSwitchActiveBackground : colorSwitchInnactiveBackground; let colorrect = switche.fill() == colorSwitchInnactiveBackground ? colorSwitchActiveBackground : colorSwitchInnactiveBackground;
switche.fill(colorrect); switche.fill(colorrect);
changeLineColor(switche.id3); changeLineColor(switche.id3);
checkAllSortieLogique(); checkAllSortieLogique();
layer.draw(); layer.draw();
}); });
switche.on('mouseover', function () { switche.on('mouseover', function () {
document.body.style.cursor = "pointer"; document.body.style.cursor = "pointer";
}); });
switche.on('mouseout', function () { switche.on('mouseout', function () {
document.body.style.cursor = "default"; document.body.style.cursor = "default";
});
}); });
}
function initLayer() { });
createEnd(500,50); }
} function initLayer() {
}
function initEnd() {
let countLogique = 0;
logiques.forEach(function (element) {
if(element.id3 == null){
countLogique++;
}
});
end.position = countLogique;
end.let = countLogique;
logiques.forEach(function (element) {
if(element.id3 == null){
createLink(element,end);
}
});
}

@ -28,7 +28,7 @@
</header> </header>
<div id="container"></div> <div id="container"></div>
<script> <script>
var switchs = [], lineCount = [], logiques = [],lines = []; var switchs = [], lineCount = [], logiques = [],lines = [], endLines = [],end;
var layer = new Konva.Layer(); var layer = new Konva.Layer();
@ -47,18 +47,27 @@
createLogique(200, 100, "logique1","et"); createLogique(200, 100, "logique1","et");
createLogique(300,200,"logique2","ou"); createLogique(300,200,"logique2","ou");
createLogique(500,300,"logique3","et"); createLogique(500,300,"logique3","et");
createSwitch("s1", 20, 20,2,2); createLogique(500,400,"logique4","et");
createSwitch("s1", 20, 20);
createSwitch("s2", 20, 90); createSwitch("s2", 20, 90);
createSwitch("s3", 20, 300); createSwitch("s3", 20, 300);
createSwitch("s4", 20, 500); createSwitch("s4", 20, 500);
createSwitch("s5", 20, 700);
createLink(stage.findOne("#s3"), findLogique("logique2"),3); createSwitch("s6", 20, 600);
createLink(stage.findOne("#s2"), findLogique("logique1"),1); createLink(stage.findOne("#s5"), findLogique("logique4"));
createLink(stage.findOne("#s1"), findLogique("logique1"),0); createLink(stage.findOne("#s6"), findLogique("logique4"));
createLink(findLogique("logique1"),findLogique("logique2"),2); createLink(stage.findOne("#s3"), findLogique("logique2"));
createLink(stage.findOne("#s4"), findLogique("logique3"),4); createLink(stage.findOne("#s2"), findLogique("logique1"));
createLink(findLogique("logique2"),findLogique("logique3"),5); createLink(stage.findOne("#s1"), findLogique("logique1"));
createLink(findLogique("logique1"),findLogique("logique2"));
createLink(stage.findOne("#s4"), findLogique("logique3"));
createLink(findLogique("logique2"),findLogique("logique3"));
initAllSwitch(); initAllSwitch();
createEnd(800, 320);
initEnd();
</script> </script>
</body> </body>

Loading…
Cancel
Save