Holyday greeting !
This is a OpenGL for Happy Holyday
Dance of Sugar Plum faily? , Tchaikovsky 's Nutz cracker suite
 Dodecahedron and Icosahedron are Dancing according to key x y x
This Script is written by Nishikawa Toshio for JAPLA 2009 05/DEC/2009
----------------------------------------------------------
run 0  and run 1 
and press Key x y z or X Y Z 
and please enjoy dancing
------------------------------------------------------
 m.shimura /Japan APL Association
  jcd02...@nifty.ne.jp


NB. --------------------cut here -------------------------
NB. OpGLN_polyh.ijs 

NB. run 0 / run '' => Dodecahedron
NB. run 1          => Icosahedron
NB. rotate => key-in: x y z or X Y Z 


require'opengl gl3'
coinsert'jgl3'

A=: 0 : 0
pc a closeok;
xywh 0 0 220 200;cc g isigraph opengl rightmove bottommove;
pas 0 0;
rem form end;
)

run=: a_run
a_run=: 3 : 0
N =: y
if. N = 0
  do. Vd =: dodec 0.4
  else. Vc =: icosa 0.5
end.
wd A
ogl=: ''conew'jzopengl'
R=: 0 0 0
wd'pshow;'
)

a_close=: 3 : 0
destroy__ogl''
wd'pclose'
)

a_g_paint=: 3 : 0
RC =: rc__ogl ''
if. RC do. g_draw_init wh__ogl end.
g_draw''
show__ogl''
)

a_g_char =: 3 : 0
wd'psel a'
R=: 360 | R + 2 * 'xyz' = {.sysdata
R=: 360 | R - 2 * 'XYZ' = {.sysdata
a_g_paint''
)

g_draw_init=: 3 : 0
glViewport 0 0,y
('arial';30) glaUseFontBitmaps__ogl 32 95 32
glMatrixMode GL_PROJECTION
glLoadIdentity''
glOrtho _1 1 _1 1 _1 1
NB. gluPerspective 30, (%/y),1 10
)

g_draw=: 3 : 0
glClearColor 1 1 1 0
glClear GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT
glEnable GL_DEPTH_TEST
glMatrixMode GL_MODELVIEW
glLoadIdentity''
glColor 0 0 0 0
glRasterPos _0.4 _0.65 0
glaCallLists '    X     Y     Z'
glRasterPos _0.4 _0.8 0
glaCallLists 5 ": R
glTranslated 0 0 0
glRotated R ,. 3 3 $ 1 0 0 0
NB. glPolygonMode GL_FRONT_AND_BACK, GL_LINE  NB. Wired
if. N = 0
   do. draw_dodec ''
   else. draw_icosa ''
end.
NB. drawbox ''
)

BLUE=:  0 0 1 0
GREEN=: 0 1 0 0
RED=:   1 0 0 0

drawbox=:3 : 0
p=: _1 ^ #: i.8
p=. 0.3*p
BLUE         polygon 0 1 3 2{p
GREEN        polygon 0 1 5 4{p
RED          polygon 0 2 6 4{p
(RED+BLUE)   polygon 4 5 7 6{p  NB. Violet
(RED+GREEN)  polygon 1 3 7 5{p  NB. Yellow
(BLUE+GREEN) polygon 2 3 7 6{p  NB. Aqua
)


polygon=: 4 : 0
glColor4d 4{.x, 1
glBegin GL_POLYGON
 glVertex y
glEnd ''
)

NB. Color Data
COLA=:  1    0    0
COLB=:  0    1    0
COLC=:  0    0    1
COLD=:  1    1    0
COLE=:  0    0.5    1
COLF=:  1    0    1
COLG=:  1    0.5  0
COLH=:  0.5  1    0
COLI=:  1    0    0.5  
COLJ=:  0.5  0    1
COLK=:  0    0.5  1
COLL=:  0.5  0.5  0.5
COLM=:  0.7  0    0
COLN=:  0.7  1    0
COLO=:  0.7  0    1
COLP=:  0.7  1    1
COLQ=:  0.3  0.3    0
COLR=:  0.3  0.3    1
COLS=:  0.3  1    0.3
COLT=:  0.3  1    1

NB. Dodecahedron Vertex
draw_dodec=:verb define
COLA         polygon   0  1   2  3  4  {Vd  NB. あか

COLB         polygon   0  5  11  6  1  {Vd  NB. みどり
COLC         polygon   1  6  12  7  2  {Vd  NB. あお 
COLD         polygon   2  7  13  8  3  {Vd  NB. き
COLE         polygon   3  8  14  9  4  {Vd  NB. みずいろ
COLF         polygon   4  9  10  5  0  {Vd  NB. むらさき

COLG         polygon   19 14  9 10 15  {Vd  NB. ちゃいろ
COLH         polygon   18 13  8 14 19  {Vd  NB. きみどり
COLI         polygon   17 12  7 13 18  {Vd  NB. あかむらさき
COLJ         polygon   16 11  6 12 17  {Vd  NB. こいあお
COLK         polygon   15 10  5 11 16  {Vd  NB. そらいろ

COLL         polygon   15 19 18 17 16  {Vd  NB. はいいろ 
)

NB. Icosahedron Vertex
draw_icosa=:verb define
COLA         polygon   0  1  2  {Vc  NB. あか
COLB         polygon   0  2  3  {Vc  NB. みどり
COLC         polygon   0  3  4  {Vc  NB. あお 
COLD         polygon   0  4  5  {Vc  NB. き
COLE         polygon   0  5  1  {Vc  NB. みずいろ

COLF         polygon   1  2  7  {Vc  NB. むらさき
COLG         polygon   2  3  8  {Vc  NB. ちゃいろ
COLH         polygon   3  4  9  {Vc  NB. きみどり
COLI         polygon   4  5 10  {Vc  NB. あかむらさき
COLJ         polygon   5  1  6  {Vc  NB. こいあお

COLK         polygon   1  6  7  {Vc  NB. そらいろ
COLL         polygon   2  7  8  {Vc  NB. はいいろ
COLM         polygon   3  8  9  {Vc  NB. 
COLN         polygon   4  9 10  {Vc  NB. 
COLO         polygon   5 10  6  {Vc  NB. 

COLP         polygon   6  7 11  {Vc  NB. 
COLQ         polygon   7  8 11  {Vc  NB. 
COLR         polygon   8  9 11  {Vc  NB. 
COLS         polygon   9 10 11  {Vc  NB. 
COLT         polygon   10 6 11  {Vc  NB.  
)



NB. polyhedron vertex imported from polyhedron.ijs =====================
NB. polyhedron.ijs
NB. 正12面体と正20面体の頂点座標を求める
NB.   2009/11/2 
NB.   2009/11/9   一辺=2a に変更する

load 'trig'

polyh =: 3 : 0
:
a =. x % 2                 NB. 正多面体を構成する正多角形の一辺
'p q' =. y                 NB. シェフリのパラメータ
delta =. %: 1 - ( ((cos 1p1%p)^2) + (cos 1p1%q)^2 )
NB. R = 正多面体の外接球の半径
R =. a * (sin 1p1 % q) % (delta)  
l =. a * (cos 1p1 % p) % (delta)
NB. r = 正多面体の内接球の半径
r =. a * (% tan 1p1 % p) * (cos 1p1 % q) % (delta)
NB. r5 = 正5角形の外接円の半径
r5 =. (a) % sin 1p1 % 5   
h5 =. %: (R^2) - (r5^2)     
NB. h5=r: 正5角形の板の高さ=正5角形と重心との距離=正多面体の内接球の半径
R, r, r5
)

NB. 正12面体の頂点座標
dodec =: 3 : 0              
a =. y                                        
'R r r5' =. a polyh 5 3
'p q' =. 5, 3
NB. R=正12面体の外接球の半径
NB. r=正12面体の内接球の半径=正5角形の板と重心との距離
NB. r5=正5角形の外接円の半径
TH =. (2p1 % p) * i.5
DA =. (r5 * (cos TH),. (sin TH)),"(1 0) r
'D0 D1 D2 D3 D4' =. DA 
D0 =. 0{DA
'D0X D0Y D0Z' =. D0
sin_alph =. (a%2) % R
cos_alph =. %: 1 - sin_alph^2
sin_2alph =. 2 * sin_alph * cos_alph
cos_2alph =. (cos_alph^2) - (sin_alph^2)
D5X =. (D0X*cos_2alph) + (D0Z*sin_2alph)
D5Z =. (-D0X*sin_2alph) + (D0Z*cos_2alph)
D5Y =. D0Y
D5 =. D5X, D5Y, D5Z 
DBX =. (D5X * cos TH) - (D5Y * sin TH)
DBY =. (D5X * sin TH) + (D5Y * cos TH)
DB =. (DBX,.DBY),"(1) D5Z
'D5 D6 D7 D8 D9' =. DB
NB. 対蹠点を求めた後、順序を調整する 09/11/11
DC0 =. -|. DB
DC1 =. 1 _1 1*"(1 1) DC0
DC =. 1 |. DC1
'D10 D11 D12 D13 D14' =. DC
DDX =. -|. DA
DDY =. 1 _1 1*"(1 1) DDX
DD =. 1 |. DDY
'D15 D16 D17 D18 D19' =. DD 
DA, DB, DC, DD
)

NB. 正20面体の頂点座標
icosa =: 3 : 0
a =. y                                        
'R r r5' =. a polyh 3 5
'p q' =. 3, 5
NB. R=正20面体の外接球の半径
C0 =. 0, 0, R
'C0X C0Y C0Z' =. C0
sin_beta =. (a%2) % R
cos_beta =. %: 1 - sin_beta^2
sin_2beta =. 2 * sin_beta * cos_beta
cos_2beta =. (cos_beta^2) - (sin_beta^2)
C1X =.  (C0X*cos_2beta) + (C0Z*sin_2beta)
C1Z =. (-C0X*sin_2beta) + (C0Z*cos_2beta)
C1Y =. C0Y
C1 =. C1X, C1Y, C1Z
TH =. (2p1 % 5) * i.5
CA =. (C1X * (cos TH),. (sin TH)),"(1 0) C1Z
'C1 C2 C3 C4 C5' =. CA
CAXY =. 0 1{"(1) CA
NB. 対蹠点を求めた後、順序を調整する 09/11/11
CB0 =. (_1* CAXY),"(1 0) (-C1Z)
CB =. 2 |. CB0
'C6 C7 C8 C9 C10' =. CB
C11 =. - C0
C0, CA, CB, C11
)


NB. Distance for Check
NB. eg. D1 dist D6 => 5, D6 dist D12 => 5, D6 dist D13 => 5
dist =: 3 : 0
:
'ax ay az' =. x
'bx by bz' =. y
%: (*: ax-bx) + (*: ay-by) + (*: az-bz)
)

NB.  ---------------end of File--------------------------------



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to