-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapes.js
71 lines (66 loc) · 1.48 KB
/
Shapes.js
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
const shapeData = {
"shape1": {
type: "rect",
colour: 'red',
centre: {
x: 100,
y: 100
},
size: {
width: 200,
height: 100
}
},
"shape2": {
type: "circle",
colour: "blue",
centre: {
x: 200,
y: 200
},
size: {
radius: 200,
}
},
"shape3": {
type: "rect",
colour: 'yellow',
centre: {
x: 500,
y: 400
},
size: {
width: 400,
height: 200
}
},
"shape4": {
type: "circle",
colour: 'green',
centre: {
x: 350,
y: 300
},
size: {
radius: 400,
}
}
};
const draw = SVG('drawing').size(700, 700);
for (const shapeName in shapeData) {
const shapeDef = shapeData[shapeName];
console.log(shapeDef);
let shape;
switch (shapeDef.type) {
case 'rect':
shape = draw.rect(shapeDef.size.width, shapeDef.size.height);
break;
case 'circle':
shape = draw.circle(shapeDef.size.radius);
break;
}
draw.circle();
shape.center(shapeDef.centre.x, shapeDef.centre.y).attr({fill: shapeDef.colour});
}
const ring = draw.circle(180).attr({fill: 'yellow', 'fill-opacity': '0.5', stroke: 'purple', 'stroke-width': 10});
ring.animate().move(500, 500).loop(true, true);