-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
189 lines (160 loc) · 4.99 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
<html>
<head>
<link rel="stylesheet" type="text/css" href="node_modules/@construit/highlighter/css/construit-highlighter.css">
<link rel="stylesheet" type="text/css" href="node_modules/@construit/scriptbox/css/interpreter.css">
<link rel="stylesheet" type="text/css" href="node_modules/@construit/scriptbox/css/gutter.css">
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono:400" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet">
<script src="compare-js-em.js"></script>
<script src="https://use.fontawesome.com/f172de12fc.js"></script>
<style>
body {
display: flex;
font-size: 20px;
font-family: "Roboto", Helvetica, arial;
flex-direction: column;
margin: 0;
}
#menu {
background: #eee;
padding: 15px;
display: flex;
color: #666;
}
#emmenu {
width: 50%;
text-align: center;
}
#emmenu > select {
margin-top: 5px;
}
#jsmenu {
width: 50%;
text-align: center;
}
#jsmenu > select {
margin-top: 5px;
}
#inputs {
display: flex;
background: #777;
overflow: hidden;
}
#emtextin {
width: 50%;
margin: 20px;
font-size: 20px;
box-sizing: border-box;
overflow: auto;
box-shadow: 0 0 10px black;
background: #f3f0da;
}
#jstextin {
width: 50%;
margin: 20px;
font-size: 20px;
box-sizing: border-box;
overflow: auto;
box-shadow: 0 0 10px black;
background: #f3f0da;
}
#image1 {
position: absolute;
left: calc(50% - 300px);
top: 100px;
}
#image2 {
position: absolute;
right: 10px;
top: 100px;
}
</style>
</head>
<body>
<!--script>
myhouse = [];
function Triangle(x,y,width,height,colour) {
var ele = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
var points = "" + x + " " + (y+height) + ", " + (x+width/2) + " " + y + ", " + (x+width) + " " + (y+height);
ele.setAttribute("points", points);
ele.setAttribute("style", "fill: "+((colour) ? colour : "black")+";");
return ele;
}
function Rectangle(x,y,width,height,colour) {
var ele = document.createElementNS("http://www.w3.org/2000/svg", "rect");
ele.setAttribute("x", x);
ele.setAttribute("y", y);
ele.setAttribute("width", width);
ele.setAttribute("height", height);
ele.setAttribute("style", "fill: "+((colour) ? colour : "black")+";");
return ele;
}
house = function (houseX, houseY, options) {
if (!options) options={};
let floorHeight = options.floorHeight||40;
let floors = options.floors||2;
let houseWidth = options.houseWidth||200;
let roofHeight = options.roofHeight||houseWidth * 0.5;
let roofY = houseY + roofHeight;
let roof = Triangle(houseX,houseY,houseWidth,roofHeight);
let blockHeight = floorHeight * floors;
let houseBlock = Rectangle(houseX,roofY,houseWidth,blockHeight);
return [houseBlock, roof];
}
myhouse = house(0,0);
setInterval(function() {
var svg1 = document.getElementById("image2");
if (!svg1 || !myhouse) return;
while (svg1.lastChild) svg1.removeChild(svg1.lastChild);
for (var i=0; i<myhouse.length; i++) {
svg1.appendChild(myhouse[i]);
}
}, 400);
</script>
<script type="text/construit" data-mount="image1">
use lib > svg > :(Rectangle);
image1 is <svg width="300" height="300">{myhouse}</svg>;
triangle_points is "" // $1 // " " // ($2+$4) // ", " // ($1+$3/2) // " " // $2 // ", " // ($1+$3) // " " // ($2+$4);
Triangle is <polygon xmlns="http://www.w3.org/2000/svg" points={triangle_points} style={"fill: "//($5 if $5 else "black")//";"} />;
houseX is $1;
houseY is $2;
floorHeight = 40;
floors = 2;
houseWidth = 200;
roofHeight is houseWidth * 0.5;
roofX is houseX;
roofY is houseY + roofHeight;
roof is Triangle(roofX, houseY, houseWidth, roofHeight);
blockHeight is floorHeight * floors;
houseBlock is Rectangle(houseX, roofY, houseWidth, blockHeight);
house is [houseBlock, roof];
myhouse is house(0,0);
</script-->
<div id="menu">
<div id="emmenu"><b>ConstruitScript</b><br>
<select id="emoptions">
<option value="scripts/house/step1.js-e">House - Initial Script</option>
<option value="scripts/house/step1a.js-e">House - Monolithic Definition</option>
</select>
</div>
<div id="jsmenu"><b>JavaScript</b><br>
<select id="jsoptions">
<option value="scripts/house/step1.js">House - Single Function</option>
<option value="scripts/house/step1b.js">House - Naive OO</option>
<option value="scripts/house/step1c.js">House - OO Refactor Roof</option>
<option value="scripts/house/step1d.js">House - OO Refactor All Locals</option>
<option value="scripts/house/step1e.js">House - OO Refactor Floors</option>
<option value="scripts/house/step1f.js">House - OO Refactor Computed Members</option>
<option value="scripts/house/step1g.js">House - OO Inject Triangle</option>
<option value="scripts/house/step1h.js">House - OO Dependency Injection</option>
</select>
</div>
</div>
<div id="inputs">
<div id="emtextin"></div>
<div id="jstextin"></div>
</div>
<div id="image1"></div>
<svg xmlns="http://www.w3.org/2000/svg" width=300 height=300 id="image2"></svg>
</body>
</html>