OpenGL xscreensaver ants in python

This is just to see how the xscreensaver opengl extension ant for ant maze turing machine looks. It is translated from C to python fairly easily , and would go to webgl, just as easily. The sphere ant is utterly ripped off from the GL screensavers in linux with no value added whatsoever.



#/* filled sphere */
def sphere(radius): 
  quadratic = gluNewQuadric()
#  gluDisk(quadratic,0.5,1.5,32,32)
  gluSphere(quadratic,radius,32,32)

#/* draw method for ant */
def antshow():
  ant_step=10
  cos1 = cos(ant_step);
  cos2 = cos(ant_step + 2 * pi / 3);
  cos3 = cos(ant_step + 4 * pi / 3);
  sin1 = sin(ant_step);
  sin2 = sin(ant_step + 2 * pi / 3);
  sin3 = sin(ant_step + 4 * pi / 3);

  glPushMatrix();
  glScalef(1, 1.3, 1);
  sphere(0.18)
  glScalef(1, 1 / 1.3, 1);
  glTranslatef(0.00, 0.30, 0.00);
  sphere(0.2)
  glTranslatef(-0.05, 0.17, 0.05);
  glRotatef(-90, 1, 0, 0);
  glRotatef(-25, 0, 1, 0);
#  cone)(0.05)
  glTranslatef(0.00, 0.10, 0.00);
#  cone(0.05)
  glRotatef(25, 0, 1, 0);
  glRotatef(90, 1, 0, 0);
  glScalef(1, 1.3, 1);
  glTranslatef(0.15, -0.65, 0.05);
  sphere(0.25)
  glScalef(1, 1 / 1.3, 1);
  glPopMatrix();


  glBegin(GL_LINES)
  glColor3f(1,1,1)
  glVertex3f(0.00, 0.30, 0.00);
  glVertex3f(0.40, 0.70, 0.40);
  glVertex3f(0.00, 0.30, 0.00);
  glVertex3f(0.40, 0.70, -0.40);
  glEnd()
#  /* LEFT-FRONT ARM */
  glBegin(GL_LINE_STRIP);
  glVertex3f(0.00, 0.05, 0.18);
  glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25);
  glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
  glEnd();

#  /* LEFT-CENTER ARM */
  glBegin(GL_LINE_STRIP);
  glVertex3f(0.00, 0.00, 0.18);
  glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25);
  glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
  glEnd();

#  /* LEFT-BACK ARM */
  glBegin(GL_LINE_STRIP);
  glVertex3f(0.00, -0.05, 0.18);
  glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25);
  glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
  glEnd();

#  /* RIGHT-FRONT ARM */
  glBegin(GL_LINE_STRIP);
  glVertex3f(0.00, 0.05, -0.18);
  glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25);
  glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
  glEnd();

#  /* RIGHT-CENTER ARM */
  glBegin(GL_LINE_STRIP);
  glVertex3f(0.00, 0.00, -0.18);
  glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25);
  glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
  glEnd();

#  /* RIGHT-BACK ARM */
  glBegin(GL_LINE_STRIP);
  glVertex3f(0.00, -0.05, -0.18);
  glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25);
  glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
  glEnd();


..
 Python with OpenGL seems very capable of presenting a 3D interface to a complex model structure capable of realistically representing a simulated ant environment in real time.

0 comments:

Contributors

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen