NB. solar system

xyz=: (cos,0:,sin) @ rfd

CLEARCOLOR=: 0 0 0
RUNLENGTH=: 300
PERSPECTIVE=: 45 1 1 30
LEarthRAD=: 2.5
LEarthROT=: 2
LEarthXYZS=: -LEarthRAD * xyz"0 LEarthROT * i.RUNLENGTH
LEarthXYZ=: {.LEarthXYZS
LMoonRAD=: 0.75
LMoonROT=: 5
LMoonXYZS=: LMoonRAD * xyz"0 LMoonROT * i.RUNLENGTH
LMoonXYZ=: {.LMoonXYZS

NB. =========================================================
demo=: 3 : 0
opengl_g_paint=: solar_step
stdlist''
LQuad=: gluNewQuadric''
gluQuadricDrawStyle LQuad,GLU_FILL
gluQuadricNormals LQuad,GLU_SMOOTH
genlist 'LLight LSun LEarth'
solarlight makelist LLight ''
sun makelist LSun ''
earth makelist LEarth ''
)

NB. =========================================================
sun=: 3 : 0
glcolor YELLOW
gluSphere LQuad,0.4 30 30
)

NB. =========================================================
earth=: 3 : 0
glPushMatrix''
glRotate _5 0 0 1
glTranslate LEarthXYZ
glcolor BLUE
gluSphere LQuad,0.25 20 20
moon''
glPopMatrix''
)

NB. =========================================================
moon=: 3 : 0
glPushMatrix''
glRotate 30 0 0 1
glTranslate LMoonXYZ
glcolor GRAY
gluSphere LQuad,0.1 20 20
glPopMatrix''
)

NB. =========================================================
solarlight=: 3 : 0
glLight GL_LIGHT0, GL_AMBIENT, 0.15 0.15 0.15 1
glLight GL_LIGHT0, GL_DIFFUSE, 0.7 0.7 0.7 1
glLight GL_LIGHT0, GL_SPECULAR, 0.3 0.3 0.3 1
glEnable GL_LIGHTING
glEnable GL_LIGHT0
glEnable GL_COLOR_MATERIAL
glColorMaterial GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE
glMaterial GL_FRONT_AND_BACK,GL_SPECULAR, 1 1 1 1
glMaterial GL_FRONT_AND_BACK,GL_SHININESS, 100 0 0 1
)

NB. =========================================================
solar_step=: 3 : 0
if. RUNLENGTH do.
  RUNLENGTH=: <:RUNLENGTH
  LEarthXYZ=: RUNLENGTH{LEarthXYZS
  LMoonXYZ=: RUNLENGTH{LMoonXYZS
  earth makelist LEarth ''
  stdpaintx''
else.
  stdpaint''
end.
)
