]> git.cworth.org Git - zombocom-ai/blob - bus.html
Add initial structure of a Magic School Bus puzzle
[zombocom-ai] / bus.html
1 <!DOCTYPE html>
2 <html>
3
4 <head>
5   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6   <title>ZOMBO</title>
7   <link href="/zombo.css" rel="stylesheet" type="text/css">
8   <meta name="viewport" content="width=device-width,initial-scale=1">
9   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
10   <meta name="HandheldFriendly" content="true">
11
12   <style>
13     @keyframes zoom {
14         from {
15             opacity: 100%;
16             transform: scale(1);
17         }
18         to {
19             opacity: 0%;
20             transform: scale(30);
21         }
22     }
23     .zoom-into {
24         animation-name: zoom;
25         animation-duration: 2s;
26         animation-timing-function: ease-in;
27         animation-fill-mode: forwards;
28     }
29     @keyframes fade {
30         from {
31             opacity: 100%;
32         }
33         to {
34             opacity: 0%;
35         }
36     }
37     .fade-out {
38         animation-name: fade;
39         animation-duration: 0.8s;
40         animation-timing-function: ease-in;
41         animation-fill-mode: forwards;
42     }
43     #welcome {
44         position: fixed;
45         width: 100%;
46         top: 50%;
47         left: 50%;
48         transform: translate(-50%, -50%);
49     }
50     #game {
51         position: relative;
52     }
53     #word {
54         text-align: center;
55         font-size: 400%;
56         font-weight: bold;
57     }
58     #interface {
59         width: 100%;
60     }
61     #input {
62         display: block;
63         margin-left: auto;
64         margin-right: auto;
65         width: 60%;
66         font-size: 200%;
67         border-width: 5px;
68     }
69     #jumpstart {
70         position: fixed;
71         right: 5px;
72         bottom: 5px;
73     }
74     #welcome-message {
75         font-size: 120%;
76         font-weight: bold;
77         text-align: center;
78     }
79     #result {
80         position: fixed;
81         width: 100%;
82         top: 50%;
83         left: 50%;
84         transform: translate(-50%, -50%);
85         font-size: 500%;
86         text-align: center;
87     }
88     #form {
89         width: 100%;
90     }
91     #code {
92         width: 95%;
93     }
94     #output {
95         width: 100%;
96     }
97   </style>
98 </head>
99
100 <body>
101   <div id="content">
102
103     <div id="welcome" style="visibility: hidden">
104       <div id="header" align="center">
105         <p>
106           <img src="images/1403010940_The_Magic_School_Bus_in_the_apocalypse.png">
107         </p>
108       </div>
109
110       <div id="welcome-message">
111         <div id="timer_div" style="visibility: hidden">
112           Entering Magic School Bus in <span id="timer"></span> seconds.
113         </div>
114         <br>
115         Students present: <span id="students">1</span>/4
116       </div>
117     </div>
118
119     <div id="program" style="visibility: hidden">
120       <h1>
121         Magic School Bus Central Processor
122       </h1>
123       <form id="form">
124         <textarea id="code" rows="10" width="100%">t.forward(100);
125 t.right(90);
126 t.forward(100);
127         </textarea>
128         <button type="submit">Run code</button>
129       </form>
130       <img id="output"></img>
131     </div>
132
133     <button id="jumpstart">
134       Jumpstart Magic School Bus
135     </button>
136
137   </div>
138
139   <script src="/socket.io/socket.io.js"></script>
140   <script>
141     const socket = io("/bus");
142
143     const welcome = document.getElementById("welcome");
144     const program = document.getElementById("program");
145     const header = document.getElementById("header");
146     const companions = document.getElementById("students");
147     const timer_div = document.getElementById("timer_div");
148     const timer = document.getElementById("timer");
149     const form = document.getElementById("form");
150     const code = document.getElementById("code");
151     const welcome_message = document.getElementById("welcome-message");
152     const jumpstart = document.getElementById("jumpstart");
153     const output = document.getElementById("output");
154
155     function fade_element(elt) {
156         elt.style.opacity = "100%";
157         elt.className = "fade-out";
158         // Arrange to clear the class name when the animation is over
159         // This will allow for it to be restarted on the next word.
160         setTimeout(() => {
161             elt.style.opacity = "0%";
162             elt.className = "";
163         }, 900);
164     }
165
166     jumpstart.addEventListener('click', event => {
167         socket.emit('jumpstart');
168     });
169
170     form.addEventListener('submit', event => {
171         event.preventDefault();
172         console.log("Submitted form with code: " + code.value);
173         socket.emit('run', code.value);
174     });
175
176     socket.on('students', (count) => {
177         students.textContent = count.toString();
178     });
179
180     socket.on('timer', (value) => {
181         timer_div.style.visibility = "visible";
182         timer.textContent = value.toString();
183
184         if (value === 0) {
185             welcome_message.style.visibility = "hidden";
186             timer_div.style.visibility = "hidden";
187             header.className = "zoom-into";
188             // Clear that className after the animation is complete
189             setTimeout(() => {
190                 header.style.visibility = "hidden"
191                 header.className = "";
192             }, 2200);
193         }
194     });
195
196     socket.on('state', (state) => {
197         if (state === "program") {
198             welcome.style.visibility = "hidden";
199             program.style.visibility = "visible";
200         } else if (state === "welcome") {
201             welcome.style.visibility = "visible";
202             welcome_message.style.visibility = "visible";
203             header.style.opacity = "100%";
204             header.style.transform = "scale(1)";
205             header.style.visibility = "visible";
206             program.style.visibility = "hidden";
207             output.src = "";
208         }
209     });
210
211     socket.on('output', (filename) => {
212         output.src = filename;
213     });
214
215   </script>
216 </body>
217 </html>