ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-4.22.tar.gz
[xscreensaver] / hacks / glx / tangram.c
1 /* tangram, Copyright (c) 2005 Jeremy English <jhe@jeremyenglish.org>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or
9  * implied warranty.
10  */
11
12
13 #include <X11/Intrinsic.h>
14
15 extern XtAppContext app;
16
17 #define PROGCLASS         "TANGRAM"
18 #define HACK_INIT         init_tangram
19 #define HACK_DRAW         draw_tangram
20 #define HACK_RESHAPE  reshape_tangram
21 #define sws_opts          xlockmore_opts
22
23
24 #define DEFAULTS        "*delay:        30000            \n" \
25                         "*wireframe:    False            \n" \
26
27 #undef countof
28 #define countof(x) (sizeof((x))/sizeof((*x)))
29
30 #include "xlockmore.h"
31
32 #include <ctype.h>
33
34
35 #ifdef USE_GL                   /* whole file */
36
37
38 #include <GL/glu.h>
39 #include <time.h>
40 #include <math.h>
41 #include "tangram_shapes.h"
42
43 typedef enum {
44     true = 1,
45     false = 0
46 } bool;
47
48 typedef struct {
49     GLubyte r;
50     GLubyte g;
51     GLubyte b;
52 } color;
53
54 typedef struct {
55     GLfloat x;
56     GLfloat y;
57     GLfloat z;
58 } coord;
59
60 typedef struct {
61     coord crd;                  /* coordinates */
62     GLint r;                    /* rotation */
63     GLint fr;                   /* flip Rotate. Used to keep track during animation */
64     GLint dl;                   /* display List */
65
66 } tangram_shape;
67
68 typedef enum {
69     no_shape = -1,
70     small_triangle1 = 0,
71     small_triangle2 = 1,
72     medium_triangle = 2,
73     large_triangle1 = 3,
74     large_triangle2 = 4,
75     square = 5,
76     rhomboid = 6
77 } shape_type;
78
79 typedef enum {
80     state_exploding,
81     state_solving,
82     state_solved
83 } tangram_state;
84
85 tangram_shape solved[][7] = {
86     {
87      {{-1.664000, -1.552000, 0}, 135, 0, 0},
88      {{-1.696000, 0.944000, 0}, 315, 0, 0},
89      {{0.064000, -2.128000, 0}, 135, 0, 0},
90      {{-0.960000, -1.056000, 0}, 90, 0, 0},
91      {{1.104000, 0.960000, 0}, 270, 0, 0},
92      {{-1.376000, -0.800000, 0}, 180, 0, 0},
93      {{1.152000, 0.736000, 0}, 360, 0, 0},
94      },
95     {
96      {{-0.096000, 1.552000, 0}, 135, 180, 0},
97      {{-0.064000, 2.336000, 0}, 315, 0, 0},
98      {{-0.080000, -0.224000, 0}, 135, 180, 0},
99      {{-2.096000, 1.584000, 0}, 90, 180, 0},
100      {{1.920000, 1.584000, 0}, 270, 0, 0},
101      {{0.416000, -0.192000, 0}, 180, 0, 0},
102      {{-0.096000, -1.296000, 0}, 335, 0, 0},
103      },
104     {
105      {{-0.144000, -0.720000, 0}, 225, 0, 0},
106      {{0.608000, 0.032000, 0}, 135, 0, 0},
107      {{-1.584000, 0.720000, 0}, 0, 0, 0},
108      {{-0.112000, -0.720000, 0}, 315, 0, 0},
109      {{-0.096000, -0.704000, 0}, 45, 0, 0},
110      {{0.592000, 0.016000, 0}, 225, 0, 0},
111      {{-0.880000, -0.032000, 0}, 315, 0, 0},
112      },
113     {
114      {{1.472000, 2.176000, 0}, 225, 0, 0},
115      {{1.248000, 3.488000, 0}, 270, 0, 0},
116      {{-0.752000, -1.680000, 0}, 270, 0, 0},
117      {{0.704000, -1.552000, 0}, 135, 0, 0},
118      {{1.280000, -0.080000, 0}, 180, 0, 0},
119      {{-0.016000, -0.896000, 0}, 225, 0, 0},
120      {{-0.000000, -0.944000, 0}, 315, 0, 0},
121      },
122     {
123      {{0.320000, 1.360000, 0}, 90, 0, 0},
124      {{0.704000, 3.072000, 0}, 270, 0, 0},
125      {{-1.200000, -3.392000, 0}, 135, 0, 0},
126      {{0.688000, -1.184000, 0}, 135, 0, 0},
127      {{-0.768000, 0.192000, 0}, 315, 0, 0},
128      {{-1.168000, -2.304000, 0}, 180, 0, 0},
129      {{1.312000, 1.296000, 0}, 270, 0, 0},
130      },
131     {
132      {{-2.064000, 0.848000, 0}, 65, 0, 0},
133      {{0.096000, 1.424000, 0}, 99, 180, 0},
134      {{2.016000, -2.448000, 0}, 270, 180, 0},
135      {{-2.016000, 0.368000, 0}, 315, 0, 0},
136      {{-0.560000, -1.040000, 0}, 135, 0, 0},
137      {{1.312000, -1.696000, 0}, 225, 0, 0},
138      {{0.864000, 0.336000, 0}, 180, 180, 0},
139      },
140     {
141      {{0.560000, -0.208000, 0}, 135, 0, 0},
142      {{0.336000, -1.552000, 0}, 90, 180, 0},
143      {{-2.336000, 1.248000, 0}, 90, 180, 0},
144      {{1.296000, -1.504000, 0}, 180, 0, 0},
145      {{-0.896000, 1.200000, 0}, 135, 180, 0},
146      {{0.304000, -2.544000, 0}, 180, 0, 0},
147      {{1.248000, 0.544000, 0}, 225, 0, 0},
148      },
149     {
150      {{-0.480000, -2.832000, 0}, 45, 0, 0},
151      {{-0.544000, -2.832000, 0}, 225, 180, 0},
152      {{-0.064000, -0.880000, 0}, 225, 180, 0},
153      {{-2.528000, 2.656000, 0}, 0, 0, 0},
154      {{-2.512000, 0.640000, 0}, 45, 180, 0},
155      {{0.192000, -2.096000, 0}, 225, 0, 0},
156      {{-0.064000, -0.832000, 0}, 180, 0, 0},
157      },
158     {
159      {{0.880000, -1.456000, 0}, 45, 0, 0},
160      {{0.832000, 0.592000, 0}, 180, 180, 0},
161      {{-2.016000, 1.648000, 0}, 135, 180, 0},
162      {{0.448000, 2.064000, 0}, 315, 0, 0},
163      {{-0.992000, 0.688000, 0}, 315, 180, 0},
164      {{1.856000, -0.400000, 0}, 180, 0, 0},
165      {{-0.128000, -1.424000, 0}, 90, 0, 0},
166      },
167     {
168      {{2.208000, 2.000000, 0}, 180, 0, 0},
169      {{-0.640000, 3.072000, 0}, 180, 180, 0},
170      {{1.360000, -3.312000, 0}, 180, 0, 0},
171      {{-0.592000, 2.256000, 0}, 360, 0, 0},
172      {{-0.960000, -0.160000, 0}, 45, 180, 0},
173      {{0.288000, -2.896000, 0}, 135, 0, 0},
174      {{0.496000, -0.128000, 0}, 135, 0, 0},
175      },
176     {
177      {{-0.480000, 0.864000, 0}, 58, 180, 0},
178      {{0.624000, -0.752000, 0}, 90, 180, 0},
179      {{0.576000, -0.560000, 0}, 180, 180, 0},
180      {{-0.192000, -1.264000, 0}, 225, 0, 0},
181      {{-0.176000, -1.280000, 0}, 135, 180, 0},
182      {{-0.816000, -0.528000, 0}, 123, 0, 0},
183      {{-0.416000, -0.528000, 0}, 90, 0, 0},
184      },
185     {
186      {{0.688000, -0.144000, 0}, 45, 180, 0},
187      {{-0.080000, 0.592000, 0}, 225, 0, 0},
188      {{-0.048000, 0.592000, 0}, 315, 180, 0},
189      {{-1.488000, -0.848000, 0}, 45, 0, 0},
190      {{1.376000, -0.864000, 0}, 225, 180, 0},
191      {{0.688000, -0.128000, 0}, 135, 0, 0},
192      {{-1.504000, -0.832000, 0}, 135, 0, 0},
193      },
194     {
195      {{0.624000, -1.776000, 0}, 225, 180, 0},
196      {{-0.144000, 0.432000, 0}, 225, 0, 0},
197      {{-0.800000, -0.272000, 0}, 45, 180, 0},
198      {{-2.320000, -0.304000, 0}, 45, 0, 0},
199      {{2.048000, -0.320000, 0}, 225, 180, 0},
200      {{-0.112000, 0.480000, 0}, 135, 0, 0},
201      {{-0.832000, -0.320000, 0}, 135, 180, 0},
202      },
203     {
204      {{-1.744000, -0.400000, 0}, 45, 180, 0},
205      {{0.416000, 1.776000, 0}, 315, 0, 0},
206      {{-1.008000, 0.272000, 0}, 90, 180, 0},
207      {{0.800000, 1.488000, 0}, 135, 0, 0},
208      {{0.832000, 1.440000, 0}, 45, 180, 0},
209      {{-1.744000, -1.872000, 0}, 135, 0, 0},
210      {{-1.008000, 0.320000, 0}, 45, 180, 0},
211      },
212     {
213      {{-0.720000, 3.440000, 0}, 180, 180, 0},
214      {{0.912000, -1.072000, 0}, 225, 0, 0},
215      {{0.736000, 3.440000, 0}, 180, 180, 0},
216      {{0.720000, 1.984000, 0}, 225, 0, 0},
217      {{-0.672000, 0.544000, 0}, 45, 180, 0},
218      {{-0.192000, -3.840000, 0}, 135, 0, 0},
219      {{-0.528000, -2.480000, 0}, 135, 0, 0},
220      },
221     {
222      {{1.184000, 1.904000, 0}, 90, 180, 0},
223      {{-2.256000, 0.960000, 0}, 90, 0, 0},
224      {{-0.208000, -0.528000, 0}, 45, 180, 0},
225      {{-0.256000, -0.512000, 0}, 135, 0, 0},
226      {{0.144000, -0.944000, 0}, 135, 180, 0},
227      {{-0.608000, -3.648000, 0}, 105, 0, 0},
228      {{0.832000, -0.912000, 0}, 135, 0, 0},
229      },
230     {
231      {{-1.056000, -2.272000, 0}, 90, 0, 0},
232      {{0.960000, -1.264000, 0}, 180, 0, 0},
233      {{-0.000000, -2.288000, 0}, 135, 0, 0},
234      {{-1.088000, -2.256000, 0}, 180, 0, 0},
235      {{0.992000, 0.736000, 0}, 0, 0, 0},
236      {{0.960000, -0.256000, 0}, 180, 0, 0},
237      {{-0.064000, 0.752000, 0}, 180, 180, 0},
238      },
239     {
240      {{-1.360000, -0.224000, 0}, 0, 0, 0},
241      {{-0.336000, -0.176000, 0}, 90, 0, 0},
242      {{0.688000, -0.192000, 0}, 45, 0, 0},
243      {{-1.424000, -1.168000, 0}, 180, 0, 0},
244      {{1.744000, 0.816000, 0}, 0, 0, 0},
245      {{-0.384000, -0.176000, 0}, 180, 0, 0},
246      {{1.648000, -1.216000, 0}, 270, 180, 0},
247      },
248     {
249      {{2.112000, 1.504000, 0}, 0, 0, 0},
250      {{-1.040000, 1.472000, 0}, 180, 180, 0},
251      {{0.032000, -1.600000, 0}, 135, 0, 0},
252      {{1.056000, 1.504000, 0}, 270, 0, 0},
253      {{-0.992000, -0.528000, 0}, 0, 180, 0},
254      {{2.080000, 0.512000, 0}, 180, 0, 0},
255      {{-1.104000, 0.480000, 0}, 270, 180, 0},
256      },
257     {
258      {{0.608000, 1.184000, 0}, 135, 0, 0},
259      {{-2.928000, -1.584000, 0}, 135, 0, 0},
260      {{0.688000, 0.560000, 0}, 90, 180, 0},
261      {{0.640000, -0.832000, 0}, 180, 0, 0},
262      {{-0.752000, -2.304000, 0}, 315, 180, 0},
263      {{-2.192000, -0.912000, 0}, 315, 0, 0},
264      {{2.704000, 1.616000, 0}, 270, 0, 0},
265      },
266     {
267      {{0.880000, 0.960000, 0}, 45, 0, 0},
268      {{0.832000, -0.960000, 0}, 0, 0, 0},
269      {{1.536000, 1.712000, 0}, 225, 180, 0},
270      {{-0.992000, 2.096000, 0}, 315, 0, 0},
271      {{0.480000, 2.704000, 0}, 180, 180, 0},
272      {{0.816000, 0.912000, 0}, 315, 0, 0},
273      {{0.784000, -1.952000, 0}, 315, 180, 0},
274      },
275     {
276      {{0.176000, 3.584000, 0}, 270, 0, 0},
277      {{2.016000, -1.424000, 0}, 90, 0, 0},
278      {{2.496000, 0.608000, 0}, 180, 180, 0},
279      {{-0.304000, 0.496000, 0}, 270, 0, 0},
280      {{-0.256000, -0.144000, 0}, 0, 180, 0},
281      {{-1.600000, -0.368000, 0}, 303, 0, 0},
282      {{0.768000, 0.912000, 0}, 180, 0, 0},
283      },
284     {
285      {{-2.096000, 1.696000, 0}, 315, 0, 0},
286      {{-1.632000, -1.440000, 0}, 45, 0, 0},
287      {{-1.232000, -0.064000, 0}, 315, 180, 0},
288      {{0.304000, 2.416000, 0}, 315, 0, 0},
289      {{1.776000, -0.496000, 0}, 315, 180, 0},
290      {{1.168000, -0.240000, 0}, 332, 0, 0},
291      {{-0.880000, -1.216000, 0}, 135, 0, 0},
292      },
293     {
294      {{-0.432000, -0.496000, 0}, 259, 0, 0},
295      {{0.176000, -1.488000, 0}, 105, 0, 0},
296      {{1.184000, -1.168000, 0}, 300, 180, 0},
297      {{1.824000, 0.096000, 0}, 195, 0, 0},
298      {{-2.400000, -0.048000, 0}, 11, 180, 0},
299      {{-0.240000, -1.200000, 0}, 315, 0, 0},
300      {{-0.688000, -1.488000, 0}, 281, 180, 0},
301      },
302     {
303      {{0.096000, 2.000000, 0}, 315, 0, 0},
304      {{0.432000, 0.160000, 0}, 360, 0, 0},
305      {{0.208000, -1.504000, 0}, 220, 180, 0},
306      {{-1.104000, -0.336000, 0}, 50, 0, 0},
307      {{-1.136000, -0.288000, 0}, 310, 180, 0},
308      {{0.416000, 1.232000, 0}, 360, 0, 0},
309      {{0.048000, 2.016000, 0}, 225, 180, 0},
310      },
311     {
312      {{-2.128000, 2.112000, 0}, 45, 0, 0},
313      {{0.128000, 1.856000, 0}, 360, 0, 0},
314      {{2.128000, -0.720000, 0}, 180, 180, 0},
315      {{-1.376000, 2.816000, 0}, 360, 0, 0},
316      {{-1.360000, 0.768000, 0}, 45, 180, 0},
317      {{0.128000, 0.336000, 0}, 360, 0, 0},
318      {{0.432000, -2.944000, 0}, 149, 0, 0},
319      },
320     {
321      {{1.952000, -0.800000, 0}, 225, 0, 0},
322      {{2.064000, -0.816000, 0}, 45, 0, 0},
323      {{0.928000, 0.688000, 0}, 225, 0, 0},
324      {{-1.568000, 3.152000, 0}, 0, 0, 0},
325      {{-1.520000, 1.104000, 0}, 45, 0, 0},
326      {{2.720000, -0.064000, 0}, 225, 0, 0},
327      {{1.968000, 0.672000, 0}, 270, 0, 0},
328      },
329     {
330      {{2.480000, -0.912000, 0}, 225, 0, 0},
331      {{2.592000, -0.928000, 0}, 45, 0, 0},
332      {{0.352000, 1.280000, 0}, 315, 0, 0},
333      {{-0.688000, 0.336000, 0}, 135, 0, 0},
334      {{1.808000, -0.112000, 0}, 135, 0, 0},
335      {{3.248000, -0.176000, 0}, 225, 0, 0},
336      {{-1.472000, 1.024000, 0}, 225, 0, 0},
337      },
338     {
339      {{-0.400000, -1.232000, 0}, 270, 0, 0},
340      {{0.400000, -0.640000, 0}, 270, 0, 0},
341      {{1.904000, -3.232000, 0}, 180, 0, 0},
342      {{1.872000, -1.776000, 0}, 225, 0, 0},
343      {{1.552000, 0.656000, 0}, 270, 0, 0},
344      {{1.056000, 1.760000, 0}, 270, 0, 0},
345      {{-0.320000, -1.024000, 0}, 135, 180, 0},
346      },
347     {
348      {{0.896000, -0.480000, 0}, 0, 0, 0},
349      {{0.128000, -0.720000, 0}, 45, 0, 0},
350      {{0.960000, -1.728000, 0}, 270, 0, 0},
351      {{-1.040000, -1.648000, 0}, 90, 0, 0},
352      {{-0.848000, 2.304000, 0}, 0, 0, 0},
353      {{-0.096000, 0.944000, 0}, 315, 0, 0},
354      {{-1.568000, -1.728000, 0}, 90, 180, 0},
355      },
356     {
357      {{0.416000, 3.648000, 0}, 270, 0, 0},
358      {{-0.000000, -1.072000, 0}, 331, 0, 0},
359      {{1.360000, 0.528000, 0}, 180, 0, 0},
360      {{0.880000, 0.464000, 0}, 270, 0, 0},
361      {{0.576000, -3.184000, 0}, 151, 0, 0},
362      {{0.864000, 2.576000, 0}, 270, 0, 0},
363      {{-1.120000, 0.528000, 0}, 90, 0, 0},
364      },
365     {
366      {{-1.056000, -3.456000, 0}, 90, 0, 0},
367      {{0.736000, 2.000000, 0}, 135, 0, 0},
368      {{-1.488000, 1.760000, 0}, 45, 0, 0},
369      {{-0.432000, 0.016000, 0}, 0, 180, 0},
370      {{-0.432000, -0.064000, 0}, 0, 0, 0},
371      {{0.560000, -2.576000, 0}, 225, 0, 0},
372      {{0.032000, 2.656000, 0}, 0, 0, 0},
373      },
374     {
375      {{-2.800000, -2.304000, 0}, 101, 0, 0},
376      {{1.888000, 2.032000, 0}, 135, 180, 0},
377      {{-1.856000, 2.016000, 0}, 315, 0, 0},
378      {{0.352000, -0.144000, 0}, 315, 180, 0},
379      {{-2.848000, 0.976000, 0}, 0, 0, 0},
380      {{-1.424000, -1.104000, 0}, 236, 0, 0},
381      {{-1.792000, 2.016000, 0}, 45, 0, 0},
382      },
383     {
384      {{0.864000, 0.880000, 0}, 180, 0, 0},
385      {{0.912000, -2.288000, 0}, 180, 180, 0},
386      {{-1.136000, -0.144000, 0}, 45, 0, 0},
387      {{-1.136000, -3.312000, 0}, 360, 180, 0},
388      {{-1.168000, 1.920000, 0}, 0, 0, 0},
389      {{-1.184000, -1.248000, 0}, 180, 0, 0},
390      {{-1.136000, -0.224000, 0}, 0, 0, 0},
391      },
392     {
393      {{0.592000, 0.704000, 0}, 90, 0, 0},
394      {{0.576000, -2.496000, 0}, 90, 180, 0},
395      {{2.624000, -1.440000, 0}, 225, 0, 0},
396      {{2.640000, -3.504000, 0}, 270, 180, 0},
397      {{2.656000, 1.712000, 0}, 270, 0, 0},
398      {{0.544000, 0.704000, 0}, 180, 0, 0},
399      {{1.648000, 0.640000, 0}, 0, 0, 0},
400      },
401     {
402      {{0.448000, -3.344000, 0}, 90, 0, 0},
403      {{-1.616000, 1.984000, 0}, 90, 180, 0},
404      {{-1.584000, 0.928000, 0}, 45, 0, 0},
405      {{-1.600000, -2.288000, 0}, 0, 180, 0},
406      {{1.536000, -1.328000, 0}, 270, 0, 0},
407      {{2.592000, -3.328000, 0}, 180, 0, 0},
408      {{-1.600000, 0.832000, 0}, 0, 0, 0},
409      },
410     {
411      {{0.608000, 0.880000, 0}, 180, 0, 0},
412      {{0.576000, -2.304000, 0}, 180, 180, 0},
413      {{-1.456000, -0.176000, 0}, 45, 0, 0},
414      {{-1.472000, -3.344000, 0}, 0, 180, 0},
415      {{-1.472000, 1.888000, 0}, 0, 0, 0},
416      {{0.640000, -1.168000, 0}, 180, 0, 0},
417      {{-1.456000, -0.256000, 0}, 0, 0, 0},
418      },
419     {
420      {{-0.208000, -0.352000, 0}, 225, 0, 0},
421      {{0.528000, 1.856000, 0}, 225, 180, 0},
422      {{-0.176000, -3.904000, 0}, 135, 0, 0},
423      {{-0.880000, 0.384000, 0}, 45, 180, 0},
424      {{-0.192000, -0.384000, 0}, 315, 0, 0},
425      {{0.304000, -2.864000, 0}, 180, 0, 0},
426      {{-0.224000, 2.528000, 0}, 315, 0, 0},
427      },
428     {
429      {{-0.032000, 0.704000, 0}, 315, 0, 0},
430      {{2.208000, -1.504000, 0}, 225, 180, 0},
431      {{-0.720000, -0.064000, 0}, 0, 0, 0},
432      {{-0.720000, -1.536000, 0}, 45, 180, 0},
433      {{-0.016000, 1.744000, 0}, 315, 180, 0},
434      {{0.464000, 0.736000, 0}, 180, 0, 0},
435      {{1.456000, -0.816000, 0}, 315, 0, 0},
436      },
437     {
438      {{-0.944000, 1.040000, 0}, 360, 0, 0},
439      {{1.120000, 0.000000, 0}, 180, 180, 0},
440      {{0.080000, -0.048000, 0}, 315, 0, 0},
441      {{0.080000, -1.104000, 0}, 135, 180, 0},
442      {{0.080000, 1.120000, 0}, 315, 180, 0},
443      {{1.120000, 0.048000, 0}, 180, 0, 0},
444      {{0.064000, 0.992000, 0}, 180, 180, 0},
445      },
446     {
447      {{-0.688000, 0.784000, 0}, 135, 0, 0},
448      {{0.800000, 0.784000, 0}, 135, 0, 0},
449      {{0.512000, -2.512000, 0}, 315, 0, 0},
450      {{1.488000, 0.000000, 0}, 225, 0, 0},
451      {{-1.392000, 0.000000, 0}, 45, 0, 0},
452      {{0.496000, -2.432000, 0}, 180, 0, 0},
453      {{0.480000, -2.496000, 0}, 270, 0, 0},
454      },
455     {
456      {{-0.992000, -2.160000, 0}, 90, 0, 0},
457      {{-1.040000, -1.152000, 0}, 270, 0, 0},
458      {{0.064000, -2.144000, 0}, 135, 0, 0},
459      {{0.080000, -1.088000, 0}, 90, 0, 0},
460      {{0.032000, -1.072000, 0}, 180, 0, 0},
461      {{0.544000, -3.216000, 0}, 180, 0, 0},
462      {{2.160000, -1.136000, 0}, 270, 0, 0},
463      },
464     {
465      {{-2.896000, -0.128000, 0}, 45, 0, 0},
466      {{-0.800000, 0.992000, 0}, 135, 0, 0},
467      {{-1.152000, -0.416000, 0}, 225, 0, 0},
468      {{-0.016000, 0.656000, 0}, 315, 0, 0},
469      {{1.456000, -0.736000, 0}, 135, 0, 0},
470      {{2.864000, 0.736000, 0}, 180, 0, 0},
471      {{-0.048000, 1.664000, 0}, 180, 180, 0},
472      },
473     {
474      {{2.960000, -1.376000, 0}, 270, 0, 0},
475      {{1.952000, -1.312000, 0}, 90, 0, 0},
476      {{-0.096000, 0.720000, 0}, 315, 0, 0},
477      {{-2.112000, -0.320000, 0}, 90, 180, 0},
478      {{1.904000, -0.320000, 0}, 180, 180, 0},
479      {{-0.096000, -1.776000, 0}, 135, 0, 0},
480      {{-3.168000, -2.304000, 0}, 360, 180, 0},
481      },
482     {
483      {{-1.600000, -1.232000, 0}, 270, 0, 0},
484      {{-1.600000, -0.128000, 0}, 180, 0, 0},
485      {{2.272000, -0.128000, 0}, 225, 0, 0},
486      {{-0.160000, -3.648000, 0}, 315, 180, 0},
487      {{-0.176000, 2.336000, 0}, 135, 180, 0},
488      {{-2.608000, -1.184000, 0}, 90, 0, 0},
489      {{1.280000, -2.208000, 0}, 360, 180, 0}
490      }
491 };
492
493
494 /* Dream */
495 color palette[] = {
496     {22, 26, 28},
497     {122, 142, 139},
498     {72, 82, 76},
499     {94, 115, 108},
500     {194, 202, 195},
501     {165, 175, 171},
502     {132, 117, 107},
503     {49, 54, 48},
504     {111, 84, 78},
505     {155, 144, 137},
506     {82, 99, 100},
507     {87, 57, 52},
508     {131, 132, 125},
509     {110, 130, 125},
510     {62, 70, 68},
511     {156, 160, 153},
512     {182, 190, 184},
513     {112, 116, 111},
514     {56, 37, 35},
515     {226, 230, 226},
516     {146, 158, 154},
517     {111, 101, 91},
518     {96, 99, 96},
519     {158, 130, 115},
520     {147, 117, 105},
521     {90, 85, 83},
522     {112, 124, 121},
523     {140, 144, 136},
524     {176, 162, 156},
525     {69, 56, 52},
526     {183, 177, 169},
527     {34, 38, 33},
528     {213, 219, 212},
529     {96, 108, 107},
530     {143, 132, 121},
531     {159, 166, 156},
532     {132, 124, 113},
533     {141, 151, 149},
534     {132, 100, 94},
535     {75, 73, 68},
536     {57, 62, 57},
537     {78, 90, 83},
538     {210, 205, 207},
539     {155, 152, 143},
540     {42, 47, 40},
541     {94, 70, 64},
542     {195, 193, 188},
543     {124, 116, 106},
544     {123, 124, 117},
545     {173, 182, 172},
546     {133, 138, 135},
547     {183, 185, 178},
548     {120, 130, 120},
549     {96, 100, 110},
550     {127, 88, 78},
551     {166, 161, 154},
552     {91, 92, 98},
553     {132, 124, 136},
554     {101, 122, 117},
555     {112, 108, 99},
556     {140, 144, 151},
557     {98, 109, 116},
558     {58, 58, 51},
559     {84, 84, 82},
560     {132, 132, 142},
561     {112, 116, 127},
562     {58, 48, 48},
563     {66, 66, 58},
564     {205, 210, 205},
565     {70, 78, 80},
566     {246, 246, 244},
567     {167, 168, 159},
568     {147, 152, 145},
569     {166, 154, 148},
570     {107, 73, 67},
571     {175, 177, 168},
572     {132, 117, 126},
573     {86, 106, 101},
574     {78, 78, 75},
575     {123, 138, 135},
576     {112, 92, 83},
577     {143, 138, 127},
578     {133, 109, 95},
579     {38, 34, 44},
580     {150, 134, 147},
581     {147, 123, 115},
582     {46, 48, 54},
583     {195, 198, 195},
584     {194, 186, 188},
585     {122, 110, 100},
586     {105, 116, 106},
587     {42, 42, 42},
588     {223, 221, 220},
589     {68, 71, 65},
590     {156, 160, 164},
591     {114, 124, 132},
592     {155, 152, 163},
593     {103, 94, 89},
594     {58, 63, 70},
595     {132, 143, 137},
596     {168, 143, 128},
597     {190, 198, 190},
598     {239, 237, 237},
599     {103, 101, 94},
600     {84, 90, 84},
601     {211, 213, 210},
602     {183, 185, 188},
603     {94, 94, 108},
604     {203, 204, 196},
605     {123, 125, 135},
606     {120, 132, 133},
607     {111, 110, 125},
608     {28, 32, 28},
609     {53, 56, 62},
610     {88, 63, 59},
611     {104, 108, 103},
612     {140, 124, 115},
613     {147, 126, 137},
614     {155, 144, 157},
615     {87, 98, 92},
616     {188, 192, 189},
617     {162, 133, 115},
618     {148, 144, 134},
619     {175, 169, 162},
620     {138, 131, 120},
621     {118, 124, 118},
622     {139, 125, 135},
623     {148, 144, 154},
624     {72, 47, 44},
625     {100, 72, 66},
626     {66, 42, 39},
627     {105, 84, 73},
628     {86, 78, 82},
629     {234, 238, 236},
630     {108, 78, 73},
631     {130, 110, 121},
632     {134, 150, 146},
633     {254, 254, 252},
634     {151, 138, 130},
635     {125, 99, 88},
636     {80, 56, 52},
637     {98, 63, 60},
638     {114, 138, 132},
639     {61, 42, 37},
640     {150, 166, 164},
641     {127, 94, 87},
642     {225, 226, 223},
643     {64, 47, 44},
644     {218, 226, 220},
645     {242, 242, 242},
646     {150, 138, 150},
647     {166, 138, 122},
648     {102, 78, 71},
649     {124, 118, 131},
650     {74, 65, 66},
651     {49, 33, 28},
652     {182, 170, 175},
653     {139, 117, 107},
654     {120, 84, 76},
655     {232, 232, 231},
656     {46, 50, 41},
657     {102, 102, 115},
658     {104, 108, 119},
659     {140, 118, 123},
660     {120, 92, 84},
661     {139, 108, 97},
662     {156, 125, 107},
663     {218, 214, 215},
664     {144, 133, 143},
665     {168, 161, 172},
666     {58, 58, 68},
667     {167, 169, 173},
668     {148, 152, 158},
669     {175, 177, 180},
670     {67, 73, 77},
671     {134, 143, 148},
672     {79, 50, 45},
673     {74, 83, 86},
674     {150, 134, 124},
675     {90, 86, 95},
676     {184, 176, 186},
677     {38, 39, 45},
678     {160, 168, 166},
679     {78, 73, 78},
680     {195, 193, 196},
681     {177, 184, 181},
682     {43, 41, 52},
683     {32, 33, 39},
684     {135, 138, 148},
685     {203, 198, 201},
686     {26, 26, 28},
687     {98, 116, 113},
688     {198, 202, 199},
689     {170, 176, 172},
690     {54, 57, 48},
691     {162, 146, 140},
692     {114, 131, 130},
693     {162, 160, 150},
694     {118, 116, 108},
695     {150, 159, 156},
696     {118, 99, 84},
697     {74, 54, 51},
698     {138, 102, 100},
699     {62, 64, 55},
700     {162, 154, 146},
701     {190, 185, 179},
702     {98, 94, 94},
703     {106, 124, 121},
704     {118, 110, 100},
705     {118, 117, 131},
706     {50, 50, 60},
707     {162, 152, 164},
708     {94, 63, 58},
709     {62, 70, 77},
710     {174, 162, 172},
711     {78, 91, 92},
712     {85, 85, 93},
713     {54, 50, 61},
714     {67, 66, 74},
715     {166, 154, 167},
716     {126, 109, 119},
717     {104, 116, 118},
718     {83, 92, 95},
719     {203, 205, 204},
720     {88, 100, 101},
721     {176, 169, 179},
722     {145, 138, 148},
723     {116, 78, 68},
724     {78, 78, 84},
725     {126, 142, 137},
726     {78, 83, 76},
727     {94, 58, 52},
728     {62, 38, 36},
729     {98, 86, 76},
730     {38, 42, 34},
731     {218, 220, 217},
732     {82, 70, 60},
733     {202, 194, 188},
734     {178, 183, 172},
735     {126, 131, 120},
736     {138, 132, 143},
737     {250, 250, 250},
738     {114, 74, 68},
739     {90, 108, 106},
740     {50, 38, 36},
741     {162, 161, 168},
742     {118, 124, 132},
743     {62, 65, 71},
744     {190, 185, 193},
745     {98, 94, 109},
746     {126, 132, 138},
747     {34, 34, 28},
748     {162, 146, 163},
749     {78, 85, 88},
750     {158, 134, 124},
751     {190, 178, 188}
752 };
753
754 static tangram_shape tsm1 = { {-0.144, -0.72, 0}, 225, false, 0 };
755 static tangram_shape tsm2 = { {0.608, 0.032, 0}, 135, false, 0 };
756 static tangram_shape tm = { {-1.584, 0.72, 0}, 0, false, 0 };
757 static tangram_shape tlg1 = { {-0.112, -0.72, 0}, 315, false, 0 };
758 static tangram_shape tlg2 = { {-0.096, -0.704, 0}, 45, false, 0 };
759 static tangram_shape sq = { {0.592, 0.016, 0}, 225, false, 0 };
760 static tangram_shape rh = { {-0.88, -0.032, 0}, 315, false, 0 };
761
762
763 #define DEF_VIEWING_TIME "5"
764 static GLuint viewing_time = 0;
765
766 static XrmOptionDescRec opts[] = {
767     {"-viewing_time", ".viewing_time", XrmoptionSepArg, 0}
768 };
769
770 static argtype vars[] = {
771     {&viewing_time, "viewing_time", "Viewing Time", DEF_VIEWING_TIME, t_Int}
772 };
773
774 ModeSpecOpt sws_opts = { countof(opts), opts, countof(vars), vars, NULL };
775
776 static int wire;
777 static int csi = -1;            /* Current Shape index */
778
779 static void get_solved_puzzle(tangram_shape * tsm1, tangram_shape * tsm2,
780                               tangram_shape * tm, tangram_shape * tlg1,
781                               tangram_shape * tlg2, tangram_shape * sq,
782                               tangram_shape * rh)
783 {
784     int sz = sizeof(solved) / sizeof(solved[0]);
785     int r;
786     GLuint t_dl;
787
788     do {
789         r = random() % sz;
790     } while (r == csi);
791     csi = r;
792
793     t_dl = tsm1->dl;
794     *tsm1 = solved[r][small_triangle1];
795     tsm1->dl = t_dl;
796
797     t_dl = tsm2->dl;
798     *tsm2 = solved[r][small_triangle2];
799     tsm2->dl = t_dl;
800
801     t_dl = tm->dl;
802     *tm = solved[r][medium_triangle];
803     tm->dl = t_dl;
804
805     t_dl = tlg1->dl;
806     *tlg1 = solved[r][large_triangle1];
807     tlg1->dl = t_dl;
808
809     t_dl = tlg2->dl;
810     *tlg2 = solved[r][large_triangle2];
811     tlg2->dl = t_dl;
812
813     t_dl = sq->dl;
814     *sq = solved[r][square];
815     sq->dl = t_dl;
816
817     t_dl = rh->dl;
818     *rh = solved[r][rhomboid];
819     rh->dl = t_dl;
820
821 }
822
823 static bool colors_match(color c1, color c2)
824 {
825     bool res = false;
826     if (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b)
827         res = true;
828     return res;
829 }
830
831 static color rand_palette(void)
832 {
833     int l = sizeof(palette) / sizeof(color);
834     int r = random() % l;
835     return palette[r];
836 }
837
838 static int approach_number(int goal, int current, int step)
839 {
840
841     int i = 0;
842
843     if (goal > current) {
844         while (i < step) {
845             current++;
846             if (goal <= current)
847                 break;
848             i++;
849         }
850     } else if (goal < current) {
851         while (i < step) {
852             current--;
853             if (goal >= current)
854                 break;
855             i++;
856         }
857     }
858
859     return current;
860 }
861
862 /* gt - floating point greater than comparison */
863 static bool gt(GLfloat x1, GLfloat x2, GLfloat per)
864 {
865     if ((x1 > x2) && (fabs(x1 - x2) > per))
866         return true;
867     else
868         return false;
869 }
870
871 /* lt - floating point less than comparison */
872 static bool lt(GLfloat x1, GLfloat x2, GLfloat per)
873 {
874     if ((x1 < x2) && (fabs(x1 - x2) > per))
875         return true;
876     else
877         return false;
878 }
879
880 /* eq - Check the equality of a pair of floating point numbers to a certain perscision */
881 static bool eq(GLfloat x1, GLfloat x2, GLfloat per)
882 {
883     if (fabs(x1 - x2) < per)
884         return true;
885     else
886         return false;
887 }
888
889
890 static GLfloat approach_float(GLfloat goal, GLfloat current,
891                               bool * changed, GLfloat per)
892 {
893     *changed = false;
894     if (gt(goal, current, per)) {
895         current += per;
896         *changed = true;
897     } else if (lt(goal, current, per)) {
898         current -= per;
899         *changed = true;
900     }
901     return current;
902 }
903
904 static bool coords_match(coord c1, coord c2, GLfloat per)
905 {
906     if (eq(c1.x, c2.x, per) && eq(c1.y, c2.y, per) && eq(c1.z, c2.z, per))
907         return true;
908     else
909         return false;
910 }
911
912 static bool xy_coords_match(coord c1, coord c2, GLfloat per)
913 {
914     if (eq(c1.x, c2.x, per) && eq(c1.y, c2.y, per))
915         return true;
916     else
917         return false;
918 }
919
920
921 #if 0
922 static void print_shape(char *s, tangram_shape sh)
923 {
924     fprintf(stderr, "%s\n", s);
925     fprintf(stderr, "(%f, %f, %f)\n", sh.crd.x, sh.crd.y, sh.crd.z);
926     fprintf(stderr, "%d\n", sh.r);
927     fprintf(stderr, "%d\n", sh.fr);
928     fprintf(stderr, "\n");
929 }
930 #endif
931
932 /* approach_shape - bring use on step closer to the new shape */
933 static tangram_shape approach_shape(tangram_shape old, tangram_shape new,
934                                     bool * b, char *name)
935 {
936
937     GLuint dl;
938     bool changed;
939     *b = false;
940
941     old.fr = approach_number(new.fr, old.fr, 2);
942     if (old.fr != new.fr) {
943         return old;
944     }
945
946     old.r = approach_number(new.r, old.r, 2);
947     if (old.r != new.r) {
948         return old;
949     }
950
951     old.crd.x = approach_float(new.crd.x, old.crd.x, &changed, 0.1);
952     if (!changed)
953         old.crd.x = approach_float(new.crd.x, old.crd.x, &changed, 0.01);
954     if (!changed)
955         old.crd.x = approach_float(new.crd.x, old.crd.x, &changed, 0.001);
956     if (!changed)
957         old.crd.x = approach_float(new.crd.x, old.crd.x, &changed, 0.0001);
958
959     old.crd.y = approach_float(new.crd.y, old.crd.y, &changed, 0.1);
960     if (!changed)
961         old.crd.y = approach_float(new.crd.y, old.crd.y, &changed, 0.01);
962     if (!changed)
963         old.crd.y = approach_float(new.crd.y, old.crd.y, &changed, 0.001);
964     if (!changed)
965         old.crd.y = approach_float(new.crd.y, old.crd.y, &changed, 0.0001);
966
967     if (xy_coords_match(new.crd, old.crd, 0.0001)) {
968         old.crd.z = approach_float(new.crd.z, old.crd.z, &changed, 0.1);
969         if (!changed)
970             old.crd.z =
971                 approach_float(new.crd.z, old.crd.z, &changed, 0.01);
972         if (!changed)
973             old.crd.z =
974                 approach_float(new.crd.z, old.crd.z, &changed, 0.001);
975         if (!changed)
976             old.crd.z =
977                 approach_float(new.crd.z, old.crd.z, &changed, 0.0001);
978     }
979
980
981     if (coords_match(new.crd, old.crd, 0.0001)) {
982         dl = old.dl;
983 #if 0
984         fprintf(stderr, "%s\n", name);
985         print_shape("old", old);
986         print_shape("new", new);
987 #endif
988         old = new;              /* pick up the rest of the settings; */
989         old.dl = dl;
990         *b = true;
991     }
992
993     return old;
994 }
995
996 static color get_color(void)
997 {
998     static color new_color = { 100, 100, 100 };
999     static color old_color = { 100, 100, 100 };
1000
1001     if (colors_match(old_color, new_color)) {
1002         old_color = new_color;
1003         new_color = rand_palette();
1004     }
1005
1006     if ((random() % 10) == 0) { /* slow down the cycle */
1007         old_color.r = approach_number(new_color.r, old_color.r, 1);
1008         old_color.g = approach_number(new_color.g, old_color.g, 1);
1009         old_color.b = approach_number(new_color.b, old_color.b, 1);
1010     }
1011
1012     return old_color;
1013 }
1014
1015 static void explode(tangram_shape * tsm1, tangram_shape * tsm2,
1016                     tangram_shape * tm, tangram_shape * tlg1,
1017                     tangram_shape * tlg2, tangram_shape * sq,
1018                     tangram_shape * rh)
1019 {
1020     tsm1->crd.z = 1;
1021     tsm1->r = 0;
1022     tsm2->crd.z = -1;
1023     tsm2->r = 0;
1024     tm->crd.z = 2;
1025     tm->r = 0;
1026     tlg1->crd.z = -2;
1027     tlg1->r = 0;
1028     tlg2->crd.z = 3;
1029     tlg2->r = 0;
1030     sq->crd.z = -3;
1031     sq->r = 0;
1032     rh->crd.z = 4;
1033     rh->r = 0;
1034 }
1035
1036
1037 static void draw_tangram_shape(tangram_shape ts)
1038 {
1039     glPushMatrix();
1040
1041     glTranslatef(ts.crd.x, ts.crd.y, ts.crd.z);
1042     glRotated(90, 1, 0, 0);
1043     glRotated(ts.fr, 1, 0, 0);
1044     glRotated(ts.r, 0, 1, 0);
1045     glCallList(ts.dl);
1046     glPopMatrix();
1047 }
1048
1049 static void draw_shapes(void)
1050 {
1051
1052     if (!wire) {
1053         color c = get_color();
1054         glColor3ub(c.r, c.g, c.b);
1055     }
1056
1057     draw_tangram_shape(tsm1);
1058
1059     draw_tangram_shape(tsm2);
1060     draw_tangram_shape(tm);
1061     draw_tangram_shape(tlg1);
1062     draw_tangram_shape(tlg2);
1063     draw_tangram_shape(sq);
1064     draw_tangram_shape(rh);
1065
1066
1067 }
1068 static void set_perspective(void)
1069 {
1070     glPushMatrix();
1071     glMatrixMode(GL_PROJECTION);
1072     glLoadIdentity();
1073     gluPerspective(60, -1, 0.1, 50);
1074     gluLookAt(0, 5, -5, 0, 0, 0, 0, -1, 0);
1075     glMatrixMode(GL_MODELVIEW);
1076     glPopMatrix();
1077
1078 }
1079
1080 void reshape_tangram(ModeInfo * mi, int w, int h)
1081 {
1082     glViewport(0, 0, w, h);
1083     set_perspective();
1084     glLoadIdentity();
1085 }
1086
1087 static void rotate_camera(void)
1088 {
1089     static GLfloat theta[3] = { 1, 1, 1 };
1090     static bool going_down[3] = { false, false, false };
1091
1092
1093     glPushMatrix();
1094     glMatrixMode(GL_PROJECTION);
1095     glLoadIdentity();
1096     gluPerspective(60, -1, 0.1, 50);
1097
1098
1099     gluLookAt(0, 5, -5, 0, 0, 0, 0, -1, 0);
1100
1101     glRotatef(theta[0], 1, 0, 0);
1102     glRotatef(theta[1], 0, 1, 0);
1103     glRotatef(theta[2], 0, 0, 1);
1104
1105     glMatrixMode(GL_MODELVIEW);
1106     glPopMatrix();
1107
1108
1109     if (going_down[0] && theta[0] < 0) {
1110
1111         going_down[0] = false;
1112     } else if ((!going_down[0]) && theta[0] > 90) {
1113
1114         going_down[0] = true;
1115     }
1116
1117     if (theta[1] > 360.0)
1118         theta[1] -= 360.0;
1119
1120     if (going_down[0])
1121         theta[0] -= 0.5;
1122     else
1123         theta[0] += 0.5;
1124     theta[1] += 1;
1125 }
1126
1127 static void init_shapes(void)
1128 {
1129     get_solved_puzzle(&tsm1, &tsm2, &tm, &tlg1, &tlg2, &sq, &rh);
1130     tsm1.dl = get_sm_tri_dl(wire);
1131     tsm2.dl = get_sm_tri_dl(wire);
1132     tm.dl = get_md_tri_dl(wire);
1133     tlg1.dl = get_lg_tri_dl(wire);
1134     tlg2.dl = get_lg_tri_dl(wire);
1135     sq.dl = get_square_dl(wire);
1136     rh.dl = get_rhomboid_dl(wire);
1137 }
1138
1139 void init_tangram(ModeInfo * mi)
1140 {
1141     GLfloat pos[4] = { 1, 1, -5, 1.00 };
1142     GLfloat pos2[4] = { 1, 1, 5, 1.00 };
1143     GLfloat lKa[4] = { 0, 0, 0, 1 };
1144     GLfloat lKd[4] = { 1, 1, 1, 1 };
1145     GLfloat lKs[4] = { 1, 1, 1, 1 };
1146
1147     wire = MI_IS_WIREFRAME(mi);
1148     init_GL(mi);
1149
1150     if (!wire) {
1151         glLightfv(GL_LIGHT0, GL_POSITION, pos);
1152         glLightfv(GL_LIGHT0, GL_AMBIENT, lKa);
1153         glLightfv(GL_LIGHT0, GL_DIFFUSE, lKd);
1154         glLightfv(GL_LIGHT0, GL_SPECULAR, lKs);
1155
1156         glLightfv(GL_LIGHT1, GL_POSITION, pos2);
1157         glLightfv(GL_LIGHT1, GL_AMBIENT, lKa);
1158         glLightfv(GL_LIGHT1, GL_DIFFUSE, lKd);
1159         glLightfv(GL_LIGHT1, GL_SPECULAR, lKs);
1160
1161         glEnable(GL_DEPTH_TEST);
1162
1163         glEnable(GL_LIGHTING);
1164         glEnable(GL_LIGHT0);
1165         glEnable(GL_LIGHT1);
1166
1167         glEnable(GL_COLOR_MATERIAL);
1168     }
1169     init_shapes();
1170
1171 }
1172
1173 static tangram_shape explode_step(tangram_shape old, tangram_shape new,
1174                                   bool * b, GLfloat per)
1175 {
1176     old.crd.z = approach_float(new.crd.z, old.crd.z, b, per);
1177     if (eq(new.crd.z, old.crd.z, per))
1178         *b = true;
1179     else
1180         *b = false;
1181
1182     return old;
1183 }
1184
1185 void draw_tangram(ModeInfo * mi)
1186 {
1187     Display *dpy = MI_DISPLAY(mi);
1188     Window window = MI_WINDOW(mi);
1189     static tangram_state state = state_solved;
1190     static tangram_shape n_tsm1, n_tsm2, n_tm, n_tlg1, n_tlg2, n_sq, n_rh;
1191     static bool b_tsm1, b_tsm2, b_tm, b_tlg1, b_tlg2, b_sq, b_rh;
1192     static time_t s_tm = 0;
1193     static time_t c_tm;
1194     rotate_camera();
1195
1196     switch (state) {
1197     case state_exploding:
1198         tsm1 = explode_step(tsm1, n_tsm1, &b_tsm1, 0.1);
1199         tsm2 = explode_step(tsm2, n_tsm2, &b_tsm2, 0.1);
1200         tm = explode_step(tm, n_tm, &b_tm, 0.1);
1201         tlg1 = explode_step(tlg1, n_tlg1, &b_tlg1, 0.1);
1202         tlg2 = explode_step(tlg2, n_tlg2, &b_tlg2, 0.1);
1203         sq = explode_step(sq, n_sq, &b_sq, 0.1);
1204         rh = explode_step(rh, n_rh, &b_rh, 0.1);
1205         if (b_tsm1 && b_tsm2 && b_tm && b_tlg1 && b_tlg2 && b_sq && b_rh) {
1206             get_solved_puzzle(&n_tsm1, &n_tsm2, &n_tm, &n_tlg1, &n_tlg2,
1207                               &n_sq, &n_rh);
1208             state = state_solving;
1209         }
1210
1211         break;
1212     case state_solving:
1213
1214         tsm1 = approach_shape(tsm1, n_tsm1, &b_tsm1, "small 1");
1215         tsm2 = approach_shape(tsm2, n_tsm2, &b_tsm2, "small 2");
1216         tm = approach_shape(tm, n_tm, &b_tm, "medium");
1217         tlg1 = approach_shape(tlg1, n_tlg1, &b_tlg1, "large 1");
1218         tlg2 = approach_shape(tlg2, n_tlg2, &b_tlg2, "large 2");
1219         sq = approach_shape(sq, n_sq, &b_sq, "square");
1220         rh = approach_shape(rh, n_rh, &b_rh, "rhomboid");
1221         if (b_tsm1 && b_tsm2 && b_tm && b_tlg1 && b_tlg2 && b_sq && b_rh) {
1222             state = state_solved;
1223             s_tm = time(0);
1224         }
1225         break;
1226     case state_solved:
1227         c_tm = time(0);
1228         if (floor(difftime(c_tm, s_tm)) >= viewing_time) {
1229             /*if ((random() % 100) == 0) { */
1230             explode(&n_tsm1, &n_tsm2, &n_tm, &n_tlg1, &n_tlg2, &n_sq,
1231                     &n_rh);
1232
1233             state = state_exploding;
1234
1235         }
1236         break;
1237     }
1238     glPushMatrix();
1239     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1240     glLoadIdentity();
1241
1242     draw_shapes();
1243     glFlush();
1244     glPopMatrix();
1245     glXSwapBuffers(dpy, window);
1246 }
1247
1248 #endif                          /* USE_GL */