git @ Cat's Eye Technologies The-Dipple / a46b25e
Add Concrete Mixer. Chris Pressey 10 years ago
1 changed file(s) with 78 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 <!DOCTYPE html>
1 <head>
2 <meta charset="utf-8">
3 <title>Concrete Mixer</title>
4 <style>
5 body { text-align: center }
6 </style>
7 </head>
8 <body>
9
10 <h1>Concrete Mixer</h1>
11
12 <div id="container">
13 </div>
14
15 </body>
16 <script>
17 if (window.yoob === undefined) yoob = {};
18
19 yoob.makeTextInput = function(container, size, value) {
20 var input = document.createElement('input');
21 input.size = "" + (size || 12);
22 input.value = value || "";
23 container.appendChild(input);
24 return input;
25 };
26
27 yoob.makeLineBreak = function(container) {
28 var br = document.createElement('br');
29 container.appendChild(br);
30 return br;
31 };
32
33 yoob.makeSVG = function(container) {
34 var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
35 container.appendChild(svg);
36 return svg;
37 };
38
39 yoob.makeSVGElem = function(svg, tag, cfg) {
40 var elem = document.createElementNS(svg.namespaceURI, tag);
41 for (var key in cfg) {
42 if (cfg.hasOwnProperty(key)) {
43 elem.setAttribute(key, cfg[key]);
44 }
45 }
46 svg.appendChild(elem);
47 return elem;
48 };
49
50 /** MAIN **/
51
52 var container = document.getElementById("container");
53
54 var input = yoob.makeTextInput(container, 72, "");
55 yoob.makeLineBreak(container);
56
57 var width = 500;
58 var height = 300;
59
60 var svg = yoob.makeSVG(container);
61 svg.style.width = "" + width + "px";
62 svg.style.height = "" + height + "px";
63 svg.style.border = "1px solid blue";
64
65 input.onchange = function() {
66 var e = yoob.makeSVGElem(svg, "text", {
67 x: Math.floor(Math.random() * ((width / 2) - 20)) + 10,
68 y: Math.floor(Math.random() * (height - 20)) + 10,
69 fill: "black",
70 "font-size": 10 + Math.floor(Math.random() * 10)
71 });
72 e.innerHTML = input.value;
73 input.value = "";
74 };
75
76 input.focus();
77 </script>