-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
689 lines (641 loc) · 27.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>creer votre photo</title>
</head>
<body>
<div class="bg-hero">
<section class="left">
<div class="shapeGen">
<select id="shape">
<h3>shape :</h3>
<option value="tri">triangle</option>
<option value="cer">cercle</option>
<option value="rect">rectangle</option>
<option value="line">ligne</option>
</select>
<select id="fill">
<h3>coleur du fill:</h3>
<option value="none">sans</option>
<option value="blue">blue</option>
<option value="yellow">jaune</option>
<option value="gr2een">vert</option>
</select>
<select id="stroke">
<h3>coleur du stroke:</h3>
<option value="none">sans</option>
<option value="blue">blue</option>
<option value="yellow">jaune</option>
<option value="green">vert</option>
</select>
<input type="button" value="Ajouter" id="add-button">
</div>
<div class="main">
<svg id="bgsvg" width="500" height="500">
<rect id="rect-bg" width="500" height="500" style="fill:#DAF7A6;" />
</svg>
</div>
<div class="shape-manup">
<div class="move-pl" style="display: none;">
<input type="button" value="up" id="up">
<input type="button" value="down" id="down">
<input type="button" value="left" id="left">
<input type="button" value="right" id=right></div>
<div class="mfy" id="mfy-tri" style="display: none;">
x1(min) <input type="text" id="x1">
y1(max) <input type="text" id="y1">
x2 <input type="text" id="x2">
y2(min) <input type="text" id="y2"><br>
x3(max) <input type="text" id="x3">
y3 <input type="text" id="y3">
</div>
<div class="mfy" id="mfy-rect" style="display: none;">
x: <input type="text" id="x">
y: <input type="text" id="y">
height: <input type="text" id="height">
width: <input type="text" id="width">
</div>
<div class="mfy" id="mfy-cer" style="display: none;">
cx <input type="text" id="cx">
cy <input type="text" id="cy">
r <input type="text" id="r">
</div>
<div class="mfy" id="mfy-line" style="display: none;">
x1(min) <input type="text" id="lx1">
y1(min) <input type="text" id="ly1">
x2 <input type="text" id="lx2">
y2 <input type="text" id="ly2">
</div>
</div>
</section>
<section class="right">
<div id="shape-gest" style="display: flex; flex-direction: column;">
<button id="gest-del">supprimer</button>
<button id="gest-next">suivant</button>
<button id="gest-prev">précedent</button>
</div>
</section>
</div>
<script>
const svgbg=document.getElementById("bgsvg");
var bgHeight = Number(svgbg.getAttribute("height"));
var bgWidth = Number(svgbg.getAttribute("width"));
var obj=null;
var objects=[];
var i=null;
//triangle
var x1 = 20;
var x2 = 75;
var x3 = 125;
var y1 = 100;
var y2 = 20;
var y3 = 100;
//cercle
var cx = 60;
var cy = 60;
var r = 40;
//rectangle
var x =20;
var y = 20;
var height = 100;
var width = 100;
//line
var lx1=20;
var ly1=20;
var lx2=100;
var ly2=100;
//deplacement value
var move = 40;
//add button
document.getElementById("add-button").onclick = function() {
var shape = document.getElementById("shape").value;
var fill = document.getElementById("fill").value;
var stroke = document.getElementById("stroke").value;
//check if both values are none
if(fill=="none" && stroke=="none"){
alert("Il est interdit de mettre le fill et le stroke nuls"); //alert
return;
}
if(shape == "tri"){//triangle
obj=document.createElementNS("http://www.w3.org/2000/svg","polygon")
obj.setAttribute("points",`${x1},${y1} ${x2},${y2} ${x3},${y3}`);
objects.push([obj,new TriInfo]);
} //end of triangle
if(shape == "cer"){
obj=document.createElementNS("http://www.w3.org/2000/svg","circle");
obj.setAttribute("cx",`${cx}`);
obj.setAttribute("cy",`${cy}`);
obj.setAttribute("r",`${r}`);
objects.push([obj,new CerInfo]);
}
if(shape == "line"){//line
obj=document.createElementNS("http://www.w3.org/2000/svg","line")
obj.setAttribute("x1",`${lx1}`);
obj.setAttribute("y1",`${ly1}`);
obj.setAttribute("x2",`${lx2}`);
obj.setAttribute("y2",`${ly2}`);
objects.push([obj,new LineInfo]);
}//end of line
if(shape == "rect"){
obj=document.createElementNS("http://www.w3.org/2000/svg","rect");
obj.setAttribute("width",`${height}`);
obj.setAttribute("height",`${width}`);
obj.setAttribute("x",`${x}`);
obj.setAttribute("y",`${y}`);
objects.push([obj,new RectInfo]);
}
//set the style
obj.setAttribute("fill",fill);
obj.setAttribute("stroke",stroke);
obj.setAttribute("stroke-width","3");
//add the object
i=objects.length-1;
svgbg.appendChild(obj);
setShapeEnv(obj);
}
//remove button
document.getElementById("gest-del").onclick=function(){
if(!objects.length){
alert("pas de figure!!!");
return;
}
objects.splice(i,1);
obj.remove();
i = (i-1)%objects.length;
if(objects.length){
obj=objects.at(i)[0];
setShapeEnv(obj);
}else{
document.getElementById("mfy-cer").style.display="none";
document.getElementById("mfy-tri").style.display="none";
document.getElementById("mfy-rect").style.display="none";
document.getElementById("mfy-line").style.display="none"
}
//copy changes in previous
}
document.getElementById("gest-next").onclick=function(){
if(!objects.length) alert("pas de figure!!!");
i= (i+1)%objects.length;
obj = objects.at(i)[0];
setShapeEnv(obj);
}
document.getElementById("gest-prev").onclick=function(){
if(!objects.length) alert("pas de figure!!!");
i = (i-1)%objects.length;
obj = objects.at(i)[0];
setShapeEnv(obj);
}
function setShapeEnv(obj){
shape = obj.nodeName;
//show control panel
document.getElementsByClassName("move-pl")[0].style="block";
if(shape == "circle"){
//show mfy-pnl
document.getElementById("mfy-cer").style.display="block";
document.getElementById("mfy-tri").style.display="none";
document.getElementById("mfy-rect").style.display="none";
document.getElementById("mfy-line").style.display="none";
//show cercle attributes
document.getElementById("cx").value=objects.at(i)[1].cx;
document.getElementById("cy").value=objects.at(i)[1].cy;
document.getElementById("r").value=objects.at(i)[1].r;
//set entered values on change
document.getElementById("cx").onchange = function(){
var Cx=Number(document.getElementById("cx").value);
if(Cx+objects.at(i)[1].r <= bgWidth && Cx-objects.at(i)[1].r>=0){
obj.setAttribute("cx",`${Cx}`);
objects.at(i)[1].cx=Cx;
}
else{
alert("valeur invalide")
}
}//end of cx
document.getElementById("cy").onchange = function(){
var Cy=Number(document.getElementById("cy").value);
if(Cy+objects.at(i)[1].r <= bgHeight && Cy-objects.at(i)[1].r>=0){//
obj.setAttribute("cy",`${Cy}`);
objects.at(i)[1].cy=Cy;
}
else{
alert("valeur invalide")
}
}//end of cy
document.getElementById("r").onchange = function(){
var R=Number(document.getElementById("r").value);
if(R+objects.at(i)[1].cx<= bgWidth && R+objects.at(i)[1].cy<=bgHeight && objects.at(i)[1].cx-R >= 0 && objects.at(i)[1].cy-R >= 0){//
obj.setAttribute("r",`${R}`);
objects.at(i)[1].r=R;
}
else{
alert("valeur invalide")
}
}//end of r
}
if(shape == "rect"){
//show rect-pnl
document.getElementById("mfy-rect").style.display="block";
document.getElementById("mfy-tri").style.display="none";
document.getElementById("mfy-cer").style.display="none";
document.getElementById("mfy-line").style.display="none";
//show attributes in input
document.getElementById("x").value=objects.at(i)[1].x;
document.getElementById("y").value=objects.at(i)[1].y;
document.getElementById("width").value=objects.at(i)[1].width;
document.getElementById("height").value=objects.at(i)[1].height;
//set entered values on change
document.getElementById("x").onchange = function(){
var X=Number(document.getElementById("x").value);
if(X+objects.at(i)[1].width <= bgWidth && X>=0){
obj.setAttribute("x",`${X}`);
objects.at(i)[1].x=X;
}
else{
alert("valeur invalide")
}
}//end of x
document.getElementById("y").onchange = function(){
var Y=Number(document.getElementById("y").value);
if(Y+height <= bgHeight && Y>=0){//
obj.setAttribute("y",`${Y}`);
objects.at(i)[1].y=Y;
}
else{
alert("valeur invalide");
}
}//end of y
document.getElementById("width").onchange = function(){
var Width=Number(document.getElementById("width").value);
if(Width+x<= bgWidth && Width>0){//
obj.setAttribute("width",`${Width}`);
objects.at(i)[1].width=Width;
}
else{
alert("valeur invalide")
}
}//end of width
document.getElementById("height").onchange = function(){
var Height=Number(document.getElementById("height").value);
if(Height+y<= bgHeight && Height>0){//
obj.setAttribute("height",`${Height}`);
objects.at(i)[1].height=Height;
}
else{
alert("valeur invalide")
}
}//end of height
}
if(shape == "polygon"){
//show tri-pnl
document.getElementById("mfy-tri").style.display="block";
document.getElementById("mfy-rect").style.display="none";
document.getElementById("mfy-cer").style.display="none";
document.getElementById("mfy-line").style.display="none"
//show attributes in input
document.getElementById("x1").value=objects.at(i)[1].x1;
document.getElementById("x2").value=objects.at(i)[1].x2;
document.getElementById("x3").value=objects.at(i)[1].x3;
document.getElementById("y1").value=objects.at(i)[1].y1;
document.getElementById("y2").value=objects.at(i)[1].y2;
document.getElementById("y3").value=objects.at(i)[1].y3;
//set entered values on change
document.getElementById("x1").onchange = function(){
var X1=Number(document.getElementById("x1").value);
if(X1>=0 && X1<=objects.at(i)[1].x2){
objects.at(i)[1].x1=X1;
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
else{
alert("valeur invalide");
}
}//end of x1
document.getElementById("x2").onchange = function(){
var X2=Number(document.getElementById("x2").value);
if(X2>=objects.at(i)[1].x1 && X2<=objects.at(i)[1].x3){
objects.at(i)[1].x2=X2;
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
else{
alert("valeur invalide");
}
}//end of x2
document.getElementById("x3").onchange = function(){
var X3=Number(document.getElementById("x3").value);
if(X3<=bgWidth && X3>=objects.at(i)[1].x2){
objects.at(i)[1].x3=X3;
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
else{
alert("valeur invalide");
}
}//end of x3
document.getElementById("y1").onchange = function(){
var Y1=Number(document.getElementById("y1").value);
if(Y1 <= bgHeight && Y1>=objects.at(i)[1].y3){//
objects.at(i)[1].y1=Y1;
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
else{
alert("valeur invalide");
}
}//end of y1
document.getElementById("y2").onchange = function(){
var Y2=Number(document.getElementById("y2").value);
if(Y2 <= objects.at(i)[1].y3 && Y2>=0){//
objects.at(i)[1].y2=Y2;
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
else{
alert("valeur invalide");
}
}//end of y2
document.getElementById("y3").onchange = function(){
var Y3=Number(document.getElementById("y3").value);
if(Y3 <= objects.at(i)[1].y1 && Y3>=objects.at(i)[1].y2){//
objects.at(i)[1].y3=Y3;
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
else{
alert("valeur invalide");
}
}//end of y3
}
if(shape == "line"){
//show mfy-line
document.getElementById("mfy-tri").style.display="none";
document.getElementById("mfy-rect").style.display="none";
document.getElementById("mfy-cer").style.display="none";
document.getElementById("mfy-line").style.display="block"
//show attributes in input
document.getElementById("lx1").value=objects.at(i)[1].lx1;
document.getElementById("lx2").value=objects.at(i)[1].lx2;
document.getElementById("ly1").value=objects.at(i)[1].ly1;
document.getElementById("ly2").value=objects.at(i)[1].ly2;
//set entered values on change
document.getElementById("lx1").onchange = function(){
var Lx1=Number(document.getElementById("lx1").value);
if(Lx1>=0 && Lx1<=objects.at(i)[1].lx2){
objects.at(i)[1].lx1=Lx1;
obj.setAttribute("x1",`${Lx1}`);
}
else{
alert("valeur invalide")
}
}//end of lx1
document.getElementById("lx2").onchange = function(){
var Lx2=Number(document.getElementById("lx2").value);
if(Lx2>=objects.at(i)[1].lx1 && Lx2<=bgWidth){
objects.at(i)[1].lx2=Lx2;
obj.setAttribute("x2",`${Lx2}`);
}
else{
alert("valeur invalide")
}
}//end of lx2
document.getElementById("ly1").onchange = function(){
var Ly1=Number(document.getElementById("ly1").value);
if(Ly1 >= 0 && Ly1 <= objects.at(i)[1].ly2){//
objects.at(i)[1].ly1=Ly1;
obj.setAttribute("y1",`${Ly1}`);
}
else{
alert("valeur invalide")
}
}//end of ly1
document.getElementById("ly2").onchange = function(){
var Ly2=Number(document.getElementById("ly2").value);
if(Ly2 <=bgHeight && Ly2 >= objects.at(i)[1].ly1){//
objects.at(i)[1].ly2=Ly2;
obj.setAttribute("y2",`${Ly2}`);
}
else{
alert("valeur invalide");
}
}//end of ly2
}
document.getElementById("up").onclick = function(){
if(shape == "rect"){
if(objects.at(i)[1].y-move>0){
objects.at(i)[1].y=objects.at(i)[1].y-move;
}
else{
objects.at(i)[1].y=0;
}
obj.setAttribute("y",`${objects.at(i)[1].y}`);
}
else if(shape == "circle"){
if((objects.at(i)[1].cy-objects.at(i)[1].r)-move>0){
objects.at(i)[1].cy=objects.at(i)[1].cy-move;
}
else{
objects.at(i)[1].cy=objects.at(i)[1].r;
}
obj.setAttribute("cy",`${objects.at(i)[1].cy}`);
}
else if(shape == "polygon"){
//suppose y2 is the heigher
if(objects.at(i)[1].y2-move>0){
objects.at(i)[1].y1=objects.at(i)[1].y1-move;
objects.at(i)[1].y2=objects.at(i)[1].y2-move;
objects.at(i)[1].y3=objects.at(i)[1].y3-move;
}
else{
objects.at(i)[1].y3=objects.at(i)[1].y3-objects.at(i)[1].y2;
objects.at(i)[1].y1=objects.at(i)[1].y1-objects.at(i)[1].y2;
objects.at(i)[1].y2=0;
}
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
else if(shape == "line"){
//suppose y2 is the heigher
if(objects.at(i)[1].ly1-move>0){
objects.at(i)[1].ly1=objects.at(i)[1].ly1-move;
objects.at(i)[1].ly2=objects.at(i)[1].ly2-move;
}
else{
objects.at(i)[1].ly2=objects.at(i)[1].ly2-objects.at(i)[1].ly1;
objects.at(i)[1].ly1=0;
}
obj.setAttribute("x1",`${objects.at(i)[1].lx1}`);
obj.setAttribute("x2",`${objects.at(i)[1].lx2}`);
obj.setAttribute("y1",`${objects.at(i)[1].ly1}`);
obj.setAttribute("y2",`${objects.at(i)[1].ly2}`);
}
}//end of up
document.getElementById("down").onclick = function(){
if(shape == "rect"){
if(objects.at(i)[1].y+objects.at(i)[1].height+move<500){
objects.at(i)[1].y=objects.at(i)[1].y+move;
}
else{
objects.at(i)[1].y=500-objects.at(i)[1].height;
}
obj.setAttribute("y",`${objects.at(i)[1].y}`);
}
else if(shape == "circle"){
if((objects.at(i)[1].cy+objects.at(i)[1].r)+move<500){
objects.at(i)[1].cy=objects.at(i)[1].cy+move;
}
else{
objects.at(i)[1].cy=500-objects.at(i)[1].r;
}
obj.setAttribute("cy",`${objects.at(i)[1].cy}`);
}
else if(shape == "polygon"){
//suppose y1 is the lowest
if(objects.at(i)[1].y1+move<bgHeight){
objects.at(i)[1].y1=objects.at(i)[1].y1+move;
objects.at(i)[1].y2=objects.at(i)[1].y2+move;
objects.at(i)[1].y3=objects.at(i)[1].y3+move;
}
else{
objects.at(i)[1].y2=objects.at(i)[1].y2+bgHeight-objects.at(i)[1].y1;
objects.at(i)[1].y3=objects.at(i)[1].y3+bgHeight-objects.at(i)[1].y1;
objects.at(i)[1].y1=bgHeight;
}
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
else if(shape == "line"){
//suppose y1 is the lowest
if(objects.at(i)[1].ly2+move<=bgHeight){
objects.at(i)[1].ly1=objects.at(i)[1].ly1+move;
objects.at(i)[1].ly2=objects.at(i)[1].ly2+move;
}
else{
objects.at(i)[1].ly1=objects.at(i)[1].ly1+bgHeight-objects.at(i)[1].ly2;
objects.at(i)[1].ly2=bgHeight;
}
obj.setAttribute("x1",`${objects.at(i)[1].lx1}`);
obj.setAttribute("x2",`${objects.at(i)[1].lx2}`);
obj.setAttribute("y1",`${objects.at(i)[1].ly1}`);
obj.setAttribute("y2",`${objects.at(i)[1].ly2}`);
}
}//end of down
document.getElementById("right").onclick = function(){
if(shape == "rect"){
if(objects.at(i)[1].x+objects.at(i)[1].width+move<500){
objects.at(i)[1].x=objects.at(i)[1].x+move;
}
else{
objects.at(i)[1].x=500-objects.at(i)[1].width;
}
obj.setAttribute("x",`${objects.at(i)[1].x}`);
}
else if(shape == "circle"){
if((objects.at(i)[1].cx+objects.at(i)[1].r)+move<500){
objects.at(i)[1].cx=objects.at(i)[1].cx+move;
}
else{
objects.at(i)[1].cx=500-objects.at(i)[1].r;
}
obj.setAttribute("cx",`${objects.at(i)[1].cx}`);
}
else if(shape == "polygon"){
//suppose x3 is on right
if(objects.at(i)[1].x3+move<500){
objects.at(i)[1].x1=objects.at(i)[1].x1+move;
objects.at(i)[1].x2=objects.at(i)[1].x2+move;
objects.at(i)[1].x3=objects.at(i)[1].x3+move;
}
else{
objects.at(i)[1].x1=objects.at(i)[1].x1+500-objects.at(i)[1].x3;
objects.at(i)[1].x2=objects.at(i)[1].x2+500-objects.at(i)[1].x3;
objects.at(i)[1].x3=500;
}
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
else if(shape == "line"){
if(objects.at(i)[1].lx2+move <= 500){
objects.at(i)[1].lx1=objects.at(i)[1].lx1+move;
objects.at(i)[1].lx2=objects.at(i)[1].lx2+move;
}
else{
objects.at(i)[1].lx1=objects.at(i)[1].lx1+500-objects.at(i)[1].lx2;
objects.at(i)[1].lx2=500;
}
obj.setAttribute("x1",`${objects.at(i)[1].lx1}`);
obj.setAttribute("x2",`${objects.at(i)[1].lx2}`);
obj.setAttribute("y1",`${objects.at(i)[1].ly1}`);
obj.setAttribute("y2",`${objects.at(i)[1].ly2}`);
}
}//end of right
document.getElementById("left").onclick = function(){
if(shape == "rect"){
if(objects.at(i)[1].x-move>0){
objects.at(i)[1].x=objects.at(i)[1].x-move;
}
else{
objects.at(i)[1].x=0;
}
obj.setAttribute("x",`${objects.at(i)[1].x}`);
}
else if(shape == "circle"){
if((objects.at(i)[1].cx-objects.at(i)[1].r)-move>0){
objects.at(i)[1].cx=objects.at(i)[1].cx-move;
}
else{
objects.at(i)[1].cx=objects.at(i)[1].r;
}
obj.setAttribute("cx",`${objects.at(i)[1].cx}`);
}
if(shape == "polygon"){
//suppose x1 is on the left
if(objects.at(i)[1].x1-move>0){
objects.at(i)[1].x1=objects.at(i)[1].x1-move;
objects.at(i)[1].x2=objects.at(i)[1].x2-move;
objects.at(i)[1].x3=objects.at(i)[1].x3-move;
}
else{
objects.at(i)[1].x3=objects.at(i)[1].x3-objects.at(i)[1].x1;
objects.at(i)[1].x2=objects.at(i)[1].x2-objects.at(i)[1].x1;
objects.at(i)[1].x1=0;
}
obj.setAttribute("points",`${objects.at(i)[1].x1},${objects.at(i)[1].y1} ${objects.at(i)[1].x2},${objects.at(i)[1].y2} ${objects.at(i)[1].x3},${objects.at(i)[1].y3}`);
}
if(shape == "line"){
if(objects.at(i)[1].lx1-move>0){
objects.at(i)[1].lx1=objects.at(i)[1].lx1-move;
objects.at(i)[1].lx2=objects.at(i)[1].lx2-move;
}
else{
objects.at(i)[1].lx2=objects.at(i)[1].lx2-objects.at(i)[1].lx1;
objects.at(i)[1].lx1=0;
}
obj.setAttribute("x1",`${objects.at(i)[1].lx1}`);
obj.setAttribute("x2",`${objects.at(i)[1].lx2}`);
obj.setAttribute("y1",`${objects.at(i)[1].ly1}`);
obj.setAttribute("y2",`${objects.at(i)[1].ly2}`);
}
}//end of left
}//end of shapeEnv
class RectInfo {
x =20;
y = 20;
height = 100;
width = 100;
}
class CerInfo {
cx = 60;
cy = 60;
r = 40;
}
class LineInfo {
lx1=20;
ly1=20;
lx2=100;
ly2=100;
}
class TriInfo {
x1 = 20;
x2 = 75;
x3 = 125;
y1 = 100;
y2 = 20;
y3 = 100;
}
</script>
</body>
</html>