+ if(js->color_style != COLOR_STYLE_CHROME) {
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_LIGHT1);
+
+ glLightfv(GL_LIGHT0, GL_POSITION, lpos0);
+ glLightfv(GL_LIGHT1, GL_POSITION, lpos1);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, lcol0);
+ glLightfv(GL_LIGHT1, GL_DIFFUSE, lcol1);
+
+ glEnable(GL_COLOR_MATERIAL);
+ glColor4fv(js->jiggly_color);
+
+ glMaterialfv(GL_FRONT, GL_SPECULAR, scolor);
+ glMateriali(GL_FRONT, GL_SHININESS, js->shininess);
+ }
+ else { /* chrome */
+ init_texture(mi);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
+ glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
+ glEnable(GL_TEXTURE_GEN_S);
+ glEnable(GL_TEXTURE_GEN_T);
+ glEnable(GL_TEXTURE_2D);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ }
+}
+
+static int parse_color(jigglystruct *js)
+{
+ unsigned int r, g, b;
+ if(!strcmp(color, "clownbarf")) {
+ js->color_style = COLOR_STYLE_CLOWNBARF;
+ return 1;
+ }
+ else if(!strcmp(color, "flowerbox")) {
+ js->color_style = COLOR_STYLE_FLOWERBOX;
+ return 1;
+ }
+# ifndef HAVE_JWZGLES /* SPHERE_MAP unimplemented */
+ else if(!strcmp(color, "chrome")) {
+ js->color_style = COLOR_STYLE_CHROME;
+ return 1;
+ }
+# endif
+ else if(!strcmp(color, "cycle")) {
+ js->color_style = COLOR_STYLE_CYCLE;
+ js->jiggly_color[0] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
+ js->jiggly_color[1] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
+ js->jiggly_color[2] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
+ js->jiggly_color[3] = 1.0f;
+ js->color_dir[0] = ((float)random()) / REAL_RAND_MAX / 100.0;
+ js->color_dir[1] = ((float)random()) / REAL_RAND_MAX / 100.0;
+ js->color_dir[2] = ((float)random()) / REAL_RAND_MAX / 100.0;
+ return 1;
+ }
+ else
+ js->color_style = 0;
+ if(strlen(color) != 7)
+ return 0;
+ if(sscanf(color,"#%02x%02x%02x", &r, &g, &b) != 3) {
+ return 0;
+ }
+ js->jiggly_color[0] = ((float)r)/255;
+ js->jiggly_color[1] = ((float)g)/255;
+ js->jiggly_color[2] = ((float)b)/255;
+ js->jiggly_color[3] = 1.0f;
+
+ return 1;
+}
+
+static void randomize_parameters(jigglystruct *js) {
+ do_tetrahedron = random() & 1;
+# ifndef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */
+ js->do_wireframe = !(random() & 3);
+# endif
+ js->color_style = random() % 5;
+# ifdef HAVE_JWZGLES /* #### SPHERE_MAP unimplemented */
+ while (js->color_style == COLOR_STYLE_CHROME)
+ js->color_style = random() % 5;;
+# endif
+ if(js->color_style == COLOR_STYLE_NORMAL
+ || js->color_style == COLOR_STYLE_CYCLE) {
+ js->jiggly_color[0] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
+ js->jiggly_color[1] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
+ js->jiggly_color[2] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
+ js->jiggly_color[3] = 1.0f;
+ if(js->color_style == COLOR_STYLE_CYCLE) {
+ js->color_dir[0] = ((float)random()) / REAL_RAND_MAX / 100.0;
+ js->color_dir[1] = ((float)random()) / REAL_RAND_MAX / 100.0;
+ js->color_dir[2] = ((float)random()) / REAL_RAND_MAX / 100.0;
+ }
+ }
+ if((js->color_style != COLOR_STYLE_CHROME) && (random() & 1))
+ js->spooky = (random() % 6) + 4;
+ else
+ js->spooky = 0;
+ js->shininess = random() % 200;
+ speed = (random() % 700) + 50;
+ /* It' kind of dull if this is too high when it starts as a sphere */
+ spherism = do_tetrahedron ? (random() % 500) + 20 : (random() % 100) + 10;
+ hold = (random() % 800) + 100;
+ distance = (random() % 500) + 100;
+ damping = (random() % 800) + 50;
+}
+
+static void calculate_parameters(jigglystruct *js, int subdivs) {
+ /* try to compensate for the inherent instability at
+ * low complexity. */
+ float dist_factor = (subdivs == 6) ? 2 : (subdivs == 5) ? 1 : 0.5;
+
+ js->stable_distance = ((float)distance / 500.0)
+ * (STABLE_DISTANCE / dist_factor);
+ js->hold_strength = (float)hold / 10000.0;
+ js->spherify_strength = (float)spherism / 10000.0;
+ js->damping_velocity = (float)damping / 100000.0;
+ js->damping_factor =
+ 0.001/max(js->hold_strength, js->spherify_strength);