continuation du commit precedent

master
pisouvigne 5 years ago
parent 8384278e4c
commit f4c3ce4fc7

@ -1,12 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head>
<head>
<link rel="stylesheet" type="text/css" href="semantic/semantic.min.css"> <link rel="stylesheet" type="text/css" href="semantic/semantic.min.css">
<script <script src="https://code.jquery.com/jquery-3.1.1.min.js"
src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script src="semantic/semantic.min.js"></script> <script src="semantic/semantic.min.js"></script>
<script src="https://unpkg.com/konva@6.0.0/konva.min.js"></script> <script src="https://unpkg.com/konva@6.0.0/konva.min.js"></script>
<script src="js/func.js"></script> <script src="js/func.js"></script>
@ -17,12 +15,11 @@
margin: 0; margin: 0;
padding: 0; padding: 0;
overflow: hidden; overflow: hidden;
background-color: #f0f0f0;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="ui menu"> <div class="ui menu">
<div class="item"> <div class="item">
<div class="ui primary button">Jouer</div> <div class="ui primary button">Jouer</div>
@ -40,106 +37,41 @@
<div id="container" style="border:1px solid red;"></div> <div id="container" style="border:1px solid red;"></div>
<script> <script>
var switchs = [], lines = [], logiques = [];
var logique = {
var stage = new Konva.Stage({ idown : "logique1",
container: 'container', id1 : "line1",
width: window.innerWidth/2, id2 : "line2",
height: window.innerHeight/2, id3 : "line3",
});
var etlogique = {
entre1 : createEtLogique(300,50, "pd"),
entre2 : "200",
sortie : "500",
} }
logiques.push(logique);
console.log(logiques);
var layer = new Konva.Layer(); var layer = new Konva.Layer();
/* var stage = new Konva.Stage({
* create a triangle shape by defining a container: 'container',
* drawing function which draws a triangle width: window.innerWidth / 2,
*/ height: window.innerHeight / 2,
// add the triangle shape to the layer
var imageObj2 = new Image();
imageObj2.onload = function () {
var yoda = new Konva.Image({
x: 500,
y: 50,
image: imageObj2,
width: 50,
height: 50,
id : "et",
});
// add the shape to the layer
layer.add(yoda);
layer.batchDraw();
};
imageObj2.src = 'img/idea_white.png';
var rect1 = new Konva.Rect({
x: 20,
y: 20,
width: 100,
height: 50,
stroke: 'black',
strokeWidth: 4,
id : "rect",
});
// add the shape to the layer
layer.add(rect1);
console.log(rect1);
var simpleText = new Konva.Text({
x: 20,
y: 20,
text: '0',
fontSize: 30,
fontFamily: 'Calibri',
fill: 'black',
id : "text",
}); });
layer.add(simpleText);
rect1.on('click', function () { initLayer();
var et = stage.findOne("#text");
var line = stage.findOne("#line");
var text = et.text() == '1' ? '0' : '1';
var colorline = et.text() == '1' ? 'black' : 'blue';
line.stroke(colorline);
et.text(text);
layer.draw();
});
var redLine = new Konva.Line({
points: [120, 45, 300, 66],
stroke: 'black',
strokeWidth: 3,
lineCap: 'round',
lineJoin: 'round',
id : "line",
});
layer.add(redLine);
var lineFinal = new Konva.Line({ var etlogique = {
points: [400, 75, 500, 75], entre1: createEtLogique(300, 50, "logique1"),
stroke: 'black', entre2: "200",
strokeWidth: 3, sortie: "500",
lineCap: 'round', }
lineJoin: 'round',
id : "lineFinal",
});
layer.add(lineFinal);
let line = createLine([120, 45, 300, 66], "line");
layer.add(line);
line = createLine([400, 75, 500, 75], "line");
layer.add(line);
// add the layer to the stage
stage.add(layer); stage.add(layer);
console.log(layer);
</script> </script>
</body> </body>
</html> </html>

@ -1,4 +1,4 @@
function createEtLogique(x, y, id){ function createEtLogique(x, y, id) {
var imageObj = new Image(); var imageObj = new Image();
imageObj.onload = function () { imageObj.onload = function () {
var yoda = new Konva.Image({ var yoda = new Konva.Image({
@ -7,10 +7,10 @@ function createEtLogique(x, y, id){
image: imageObj, image: imageObj,
width: 100, width: 100,
height: 50, height: 50,
id : "pd", id: "pd",
}); });
// add the shape to the layer
layer.add(yoda); layer.add(yoda);
layer.batchDraw(); layer.batchDraw();
}; };
@ -18,3 +18,67 @@ function createEtLogique(x, y, id){
return imageObj; return imageObj;
} }
function createLine(points, id) {
let line = new Konva.Line({
points: points,
stroke: 'black',
strokeWidth: 3,
lineCap: 'round',
lineJoin: 'round',
id: id,
});
return line
}
function initLayer() {
var imageObj2 = new Image();
imageObj2.onload = function () {
var yoda = new Konva.Image({
x: 500,
y: 50,
image: imageObj2,
width: 50,
height: 50,
id: "et",
});
layer.add(yoda);
layer.batchDraw();
};
imageObj2.src = 'img/idea_white.png';
var rect1 = new Konva.Rect({
x: 20,
y: 20,
width: 100,
height: 50,
stroke: 'black',
strokeWidth: 4,
id: "rect",
});
layer.add(rect1);
var simpleText = new Konva.Text({
x: 20,
y: 20,
text: '0',
fontSize: 30,
fontFamily: 'Calibri',
fill: 'black',
id: "text",
});
layer.add(simpleText);
rect1.on('click', function () {
var et = stage.findOne("#text");
var line = stage.findOne("#line");
var text = et.text() == '1' ? '0' : '1';
var colorline = et.text() == '1' ? 'black' : 'blue';
line.stroke(colorline);
et.text(text);
layer.draw();
});
}
Loading…
Cancel
Save