.
[hacks/simpleWebSlides.git] / fds / anim / dessin.js
1 var content = document.getElementById("content");
2
3 function del_all () {
4    while (content.hasChildNodes()) {
5         content.removeChild(content.lastChild);
6     };
7
8 }
9 function del_line ()
10 {
11
12     if (content.hasChildNodes()) {
13         content.removeChild(content.lastChild);
14     };
15
16 }
17
18 function add_line()
19 {
20     var children = content.childNodes;
21     var id = children.length;
22     var div = document.createElement("div");
23     div.setAttribute("id", "div" + id);
24     div.setAttribute("class", "horizontal");
25     var table = document.createElement("table");
26     table.setAttribute("id", "table" + id);
27     var row = document.createElement("tr");
28     row.setAttribute("id", "row" + id);
29     row.setAttribute("class", "row");
30     var text = document.createElement("input");
31     text.setAttribute("id", "textfield" + id);
32     text.setAttribute("class", "textfield");
33     text.setAttribute("type", "text");
34     text.size=10;
35     text.setAttribute("onkeypress", "do_keypress(" + id + ")");
36     table.appendChild(row);
37     div.appendChild(text);
38     div.appendChild(table);
39     content.appendChild(div);
40
41 }
42
43 var wait = false;
44 function reset_wait(id) { wait = false; draw_line(id);}
45 function do_keypress(id)
46 {
47     if (!wait) {
48         wait = true;
49         setTimeout("reset_wait(" + id + ")", 1000);
50     };
51 }
52
53 function draw_line(id)
54 {
55     var row  = document.getElementById("row" + id);
56     var text = document.getElementById("textfield" + id);
57     var next = row.firstChild;
58     var tmp = null;
59     while(next) {
60         tmp = next.nextSibling;
61         row.removeChild(next);
62         next = tmp;
63     };
64     pixels = text.value.split(",");
65     var colors = new Array();
66     colors[0] = "black";
67     colors[1] = "white";
68     var c = 0;
69     for (s in pixels)
70     {
71         if (pixels[s] >= 0 && pixels[s] <= 15) {
72             for(i = 0; i < pixels[s]; i++)
73             {
74                 var td = document.createElement("td");
75                 td.setAttribute("id", "cell" + id + "_" + i);
76                 var span = document.createElement("span");
77                 span.setAttribute("class", colors[c]);
78                 td.appendChild(span);
79                 row.appendChild(td);
80             };
81         } else {
82             continue;
83         };
84         c = (c + 1) % 2;
85     };
86 }
87
88 var dessins = [];
89 dessins[0] = [
90     "0, 7, 2, 7",
91     "0, 6, 1, 2, 1, 6",
92     "0, 6, 1, 2, 1, 6",
93     "0, 5, 1, 4, 1, 5",
94     "6, 4, 6",
95     "1, 14, 1",
96     "0, 1, 1, 4, 1, 2, 1, 4, 1, 1",
97     "0, 2, 1, 3, 1, 2, 1, 3, 1, 2",
98     "0, 3, 1, 2, 1, 2, 1, 2, 1, 3",
99     "0, 3, 1, 8, 1, 3",
100     "0, 2, 1, 10, 1, 2",
101     "0, 2, 1, 10, 1, 2",
102     "0, 1, 1, 5, 2, 5, 1, 1",
103     "0, 1, 1, 3, 2, 2, 2, 3, 1, 1",
104     "1, 2, 2, 6, 2, 2, 1",
105     "3, 10, 3"
106 ];
107
108 dessins[1] = [
109     " 0, 5, 5, 6 ",
110     " 0, 3, 2, 5, 2, 4 ",
111     " 0, 2, 1, 9, 1, 3 ",
112     " 0, 1, 1, 11, 1, 2 ",
113     " 0, 1, 1, 1, 1, 1, 1, 8, 1, 1 ",
114     " 1, 2, 1, 1, 1, 4, 3, 2, 1 ",
115     " 1, 2, 1, 1, 1, 3, 1, 2, 1, 2, 1 ",
116     " 1, 11, 1, 1, 1, 1 ",
117     " 1, 1, 1, 1, 1, 1, 1, 4, 1, 3, 1 ",
118     " 1, 1, 5, 8, 1 ",
119     " 1, 1, 5, 8, 1 ",
120     " 0, 1, 1, 1, 5, 7, 1 ",
121     " 0, 1, 1, 2, 1, 1, 1, 1, 1, 5, 1, 1 ",
122     " 0, 2, 1, 10, 1, 2 ",
123     " 0, 3, 2, 6, 2, 3 ",
124     " 0, 5, 6, 5 "
125 ];
126
127 dessins[2] = [
128     "0, 5, 6, 5",
129     "0, 3, 4, 2, 4, 3",
130     "0, 1, 6, 2, 6, 1",
131     "1, 2, 4, 2, 4, 2, 1",
132     "1, 3, 2, 4, 2, 3, 1",
133     "1, 14, 1",
134     "2, 4, 4, 4, 2",
135     "2, 3, 6, 3, 2",
136     "1, 4, 6, 4, 1",
137     "1, 1, 12, 1, 1",
138     "1, 1, 1, 3, 1, 2, 1, 3, 1, 1, 1",
139     "3, 3, 1, 2, 1, 3, 3",
140     "1, 5, 1, 2, 1, 5, 1",
141     "0, 1, 1, 12, 1, 1",
142     "0, 1, 2, 10, 2, 1",
143     "0, 2, 12, 2"
144 ];
145 dessins[3] = [
146     "0, 7, 2, 7",
147     "0, 2, 1, 3, 1, 2, 1, 3, 1, 2",
148     "0, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1",
149     "0, 1, 1, 2, 1, 6, 1, 2, 1, 1",
150     "1, 14, 1",
151     "1, 4, 2, 3, 2, 3, 1",
152     "1, 3, 1, 2, 1, 1, 1, 2, 1, 2, 1",
153     "1, 14, 1",
154     "0, 1, 1, 12, 1, 1",
155     "0, 2, 1, 10, 1, 2",
156     "0, 3, 1, 7, 2, 3",
157     "0, 4, 7, 5",
158     "0, 3, 4, 2, 1, 1, 3, 2",
159     "0, 2, 1, 3, 1, 2, 2, 3, 1, 1",
160     "0, 1, 1, 5, 1, 1, 1, 5, 1",
161     "0, 1, 1, 5, 3, 5, 1"
162 ];
163
164 dessins[4] = [
165     "0, 2, 12, 2",
166     "0, 1, 1, 12, 1, 1",
167     "1, 3, 7, 2, 1, 1, 1",
168     "1, 2, 1, 7, 1, 3, 1",
169     "1, 1, 1, 9, 1, 2, 1",
170     "1, 1, 1, 2, 4, 3, 1, 2, 1",
171     "1, 2, 6, 3, 1, 2, 1",
172     "1, 4, 1, 5, 1, 3, 1",
173     "1, 4, 1, 3, 2, 4, 1",
174     "1, 5, 3, 6, 1",
175     "1, 4, 1, 3, 1, 5, 1",
176     "1, 4, 1, 3, 1, 5, 1",
177     "1, 5, 3, 4, 1, 1, 1",
178     "1, 10, 2, 2, 1",
179     "0, 1, 1, 12, 1, 1",
180     "0, 2, 12, 2"
181 ];
182
183 function fill_and_draw(sel) {
184     var value = sel.options[sel.selectedIndex].value;
185     del_all();
186     var tab = dessins[Math.min(parseInt(value + ""),dessins.length) - 1];
187     for (var i = 0 ; i < tab.length; i++){
188         add_line ();
189         var t = document.getElementById("textfield" + i);
190         t.value = tab[i];
191         draw_line(i);
192     };
193 }