NB. OpGLN_Asagao.ijs NB. from OpGLN_Moebius.ijs personally made version by T.N NB. modified executable standalone T.N 2013/5/28 NB. 2015/11/22 NB. run 0 => NFLOWER0 for test NB. run 1 => Asagao NB. run 2 => Asagao + light NB. run 11 => Moebius Line NB. run 12 => Moebius Strip wr =: 1!:2&2 rd =: 1!:1 NB. vector product ========================= NB. (1,2,3) vecprod (2,3,4) NB. +--+-+--+ NB. |_1|2|_1| NB. +--+-+--+ vecprod =: 3 : 0 : a =: x. b =. y. ( ((1{a)*(2{b)) - (2{a)*(1{b));( ((2{a)*(0{b)) - (0{a)*(2{b) );((0{a)*(1{b)) - (1{a)*(0{b) ) require 'trig' NB. Import from Asagao.ijs ===================== asagao =: 3 : 0 MM =. 10 NN =. 40 PI =. 3.1416 ZMIN =. 0 ZMAX =. 180 POW =. 5 CONST =. (ZMAX-ZMIN)%MM^POW Z0 =. ZMAX-CONST*((i.>:MM)^POW) TT =. 2*PI*(i.>:NN)%NN RHO =. 1 + 0.07*(|sin (2.5*TT))^0.2 RCT =. RHO*cos TT RST =. RHO*sin TT RZERO =. 70 RR =. RZERO*(1.03-(i.>:MM)%MM) ALPHA0 =: PI*5%6 BETA0 =: PI%2.5 XL =: RR */ RCT YL =: RR */ RST ZL =: - ($XL)$(({:$XL)#Z0) XYZ =: <"(1) (XL,"(0) YL),"(1 0) ZL NFLOWER =. 0.02*L:0 XYZ NFLOWER =: (0, 0, 2)+L:0 NFLOWER '*** imported asagao ***' ) NB. Test usung NFLOWER0 ========================== NB. run 0 stepn =: 3 : 0 'f t n' =. y. f + (t-f) * (i. >: n) % n ) cleanz =: * | >: 1e_10"_ NS =: 6 NT =: 3 SS =: stepn 0, 2p1, NS TT =: stepn _1, 1, NT makeflower0 =: 3 : 0 NB. calc. flower x, y, z values 's t' =. y. x =. 5 * (% 5 - t) * sin s y =. 5 * (% 5 - t) * cos s z =. t + 1.5 NB. z =. t + 1 cleanz |: > x;y;z ) NFLOWER0 =: |: makeflower0 L:0 { SS ; TT NB. NFLOWER0 =: 2 3$1 0 0.5;1 1 0.5;0 1 0.5;1 0 1.5;1 1 1.5;0 1 1.5 require 'gl3' NB. import from jzopengl load 'jzopengl' NB. e.g. coinsert 'jzopengl' ======================= coinsert=: 3 : 0 n=. ;: :: ] y. p=. ; (, 18!:2) @ < each n p=. ~. (18!:2 coname''), p (p /: p = <,'z') 18!:2 coname'' ) coinsert 'jzopengl' A=: noun define pc a closeok; xywh 0 0 340 300;cc g isigraph ws_clipchildren ws_clipsiblings rightmove bottommove; pas 0 0; rem form end; ) run=: a_run a_run=: verb define JOB =: y. wd A glaRC'' NB. R =: 120 0 0 R =: 218 8 0 NB. R =: 90 0 0 NB. T =: 0 0 0 T =: 0 0.5 _6 SC =: 0.5 NB. SC =: 1 NB. JOB =: 0 glaFont 'arial 30' glaUseFontBitmaps 0 32 26 32 setfocus g wd 'pshow;ptop' ) a_g_size=:verb define wh=.glqwh'' glViewport 0 0,wh glMatrixMode GL_PROJECTION glLoadIdentity'' gluPerspective 45, (%/wh),1 8 ) NB. Key-In Command ======================== a_g_char =: verb define R =: 360 | R + 2 * 'xyz' = 0 { sysdata R =: 360 | R - 2 * 'XYZ' = 0 { sysdata T =: T + 0.5 * 'run' = 0 { sysdata NB. r(right) = +x, u(up) = +y, n(near) = +z T =: T - 0.5 * 'ldf' = 0 { sysdata NB. l(left) = -x, d(down) = -y, f(far) = -z SC =: SC * 1 + 0.25 * 'b' = 0 { sysdata NB. bigger SC =: SC * 1 - 0.25 * 's' = 0 { sysdata NB. smaller NB. Select by JOB Number 0, 1, 2 NB. JOB =: 3 | ('j' = 0{sysdata){JOB, (>: JOB) glpaintx'' ) NB. Paint on the Display ======================== a_g_paint =: verb define glClearColor 1 1 1 1 glClear GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT glEnable GL_DEPTH_TEST glMatrixMode GL_MODELVIEW glLoadIdentity'' glTranslate T glRotate R ,. 3 3 $ 1 0 0 0 glScale 3#SC select. JOB NB. case. 0 do. nflower NFLOWER0 NB. Flower Test Line case. 0 do. nflower3 NFLOWER0 NB. Flower Test Fill and Line case. 1 do. asagao '' NB. Set Asagao Data NB. nflower NFLOWER nflower3 NFLOWER NB. front=> fill, back=>line case. 2 do. light '' asagao '' NB. Set Asagao Data nflower3 NFLOWER NB. front=> fill, back=>line case. 11 do. ntest11 '' NB. Moebius LINE_STRIP by TN case. 12 do. ntest2 '' NB. Moebius QUAD_STRIP by TN end. NB. light '' NB. surface '' NB. testm '' NB. demo1 '' Do not run ! drawtext '' glaSwapBuffers '' ) NB. Write Data on the display ============================= NB. indicate rotated angle x, y, z in degree drawtext =: verb define glMatrixMode GL_MODELVIEW glLoadIdentity '' glColor 0 0 0 1 NB. color is determined by glMaterial Command glRasterPos _1.5 _1.5 _6 NB. be carefull, not change position glCallLists 10 ": R, JOB glpaintx'' ) NB. Color Triangle ================================== colortriangle =: 3 : 0 glBegin GL_TRIANGLES glColor 1 0 0 1 glVertex 0 0 0 glColor 0 0 1 1 glVertex _1 1 0 glColor 0 1 0 1 glVertex 1 1 0 glColor 1 0 0 1 glVertex 0 0 0 glColor 0 0 0 1 glVertex _1 _1 0 glVertex 1 _1 0 glEnd '' ) NB. Moebius Generate =========================== moebius=: 3 : 0 N =. 6 NB. N =. 20 u=. steps 0 2p1, N v=. steps _0.3 0.3, N x=. (cos u) + ((cos u) * cos u%2) */ v y=. (sin u) + ((sin u) * cos u%2) */ v z=. (sin u%2) */ v cleanz 1.5 *"1 fit11 makexyz x;y;z ) NB. test for moebius =========================== tcol =: 1 0 0 1;1 1 0 1;0 1 0 1;0 0 1 1;0 1 1 1 tcolA =: 4#tcol tcolB =: (20, 4)$ ;tcol TDATA=: moebius'' testm =: 3 : 0 glBegin GL_POLYGON i =. 0 while. i < <: {. $TDATA do. glColor i{ > tcolA glVertex"(1) > i{TDATA i =. i + 1 end. glEnd '' ) wr =: 1!:2&2 NB. Moebius Strip from J Lab Demo ================== NB Moebius Original Program ======================= TDATA=: moebius'' TCLR=: (0 0 0 ,: 1 1 1) hue fit01 2{"1 TDATA TPATTERN=: 16 16$, RGBA WHITE,GRAY,YELLOW,:WHITE TPATPOS=: */~ int01 <:#TDATA ROTXYZ=: 325 205 155 CLEARCOLOR=: 0.9 0.9 1 COLORMATERIAL=: 0 AMBIENT=: 0.8 DIFFUSE=: LIMEGREEN SPECULAR=: DIFFUSE SHININESS=: 50 0 0 1 demo=: 3 : 0 stdlistlight'' gentexture2D TPATTERN 2 drawsurface makenewlist TDATA;TCLR;TPATPOS ) demo1=: 3 : 0 stdlistlight'' gentexture2D TPATTERN demo1x '' NB. 2 drawsurface makenewlist TDATA;TCLR;TPATPOS ) demo1x=: 3 : 0 glNewList DEMOX, GL_COMPLIE 2 drawsurface TDATA;TCLR;TPATPOS glEndList '' ) demo2=: 3 : 0 stdlistlight'' gentexture2D TPATTERN demo2x '' NB. 2 drawsurface makenewlist TDATA;TCLR;TPATPOS ) demo2x=: 3 : 0 glNewList DEMOX, GL_COMPLIE 2 drawsurface (Another_moebius '');TCLR;TPATPOS glEndList '' ) NB. test moebius by TN / 2013/5/29, 6/9 ===================== stepn =: 3 : 0 'f t n' =. y. f + (t - f) * (i. >: n) % n ) NB. NS =: 6 NS =: 36 NB. NT =: 4 NT =: 6 SS =: stepn 0, 2p1, NS NB. SS =: stepn 0, 1p1, NS TT =: stepn _1, 1, NT makedata =: 3 : 0 NB. calc. moebius x, y, z values 's t' =. y. x =. (2 + t*cos(s%2)) * sin s y =. (2 + t*cos(s%2)) * cos s z =. t*sin(s%2) cleanz |: > x;y;z ) maketest =: 3 : 0 NB. calc. moebius x, y, z values 's t' =. y. x =. (2 + t) * sin s y =. (2 + t) * cos s z =. t*sin(s%2) cleanz |: > x;y;z ) NDATA =: makedata L:0 { SS ; TT NDATA0 =: maketest L:0 { SS ; TT NCOLOR =: 1 0 0 1;1 1 0 1;0 1 0 1;0 0 1 1;0 1 1 1;1 0 1 1 ntest =: 3 : 0 glPointSize 4 NB. glColor 0 0 1 1 NB. glVertex L:0 NDATA i =. 0 while. i < NS do. glBegin GL_POINTS glColor >(NT|i){NCOLOR NB. glColor 0 0 0 1 NB. glVertex >i{NDATA glVertex >i{ |: NDATA0 glEnd '' i =. i + 1 end. ) NDATA1 =: |: makedata L:0 { SS ; TT NB. Moebius Point by TN ntest1 =: 3 : 0 glPointSize 4 NB. glColor 0 0 1 1 NB. glVertex L:0 NDATA i =. 0 while. i < NT do. glBegin GL_POINTS glColor >(NT|i){NCOLOR glVertex >i{NDATA1 glEnd '' i =. i + 1 end. ) NB. Moebius LINE_STRIP by TN ntest11 =: 3 : 0 glLineWidth 4 NB. glColor 0 0 1 1 NB. glVertex L:0 NDATA i =. 0 while. i < NT do. glBegin GL_LINE_STRIP glColor >(NT|i){NCOLOR glVertex >i{NDATA1 glEnd '' i =. i + 1 end. glLineWidth 1 glBegin GL_LINES glColor 0 0 0 1 NB. X-axis glVertex 0 0 0 glVertex 3 0 0 glColor 0 0 1 1 NB. Y-axis glVertex 0 0 0 glVertex 0 3 0 glColor 1 0 0 1 NB. Z-axis glVertex 0 0 0 glVertex 0 0 3 glEnd '' ) NB. NFLOWER0 =: 2 3$1 0 0.5;1 1 0.5;0 1 0.5;1 0 1.5;1 1 1.5;0 1 1.5 nflower =: 3 : 0 NF =. y. glLineWidth 4 i =. 0 while. i < #NF do. glBegin GL_LINE_STRIP glColor >(NT|i){NCOLOR glVertex >i{NF glEnd '' i =. i + 1 end. NB. X, Y, Z axis lines ==================== glLineWidth 1 glBegin GL_LINES glColor 0 0 0 1 NB. X-axis, Black glVertex 0 0 0 glVertex 3 0 0 glColor 0 0 1 1 NB. Y-axis, Blue glVertex 0 0 0 glVertex 0 3 0 glColor 1 0 0 1 NB. Z-axis, Red glVertex 0 0 0 glVertex 0 0 3 glEnd '' ) nflower3 =: 3 : 0 NF =. y. 'PN QN' =. $NF glPolygonMode GL_FRONT, GL_FILL glPolygonMode GL_BACK, GL_LINE NB. Hid =. 0 NB. glPolygonMode GL_BACK, Hid{GL_LINE, GL_POINT glLineWidth 2 glBegin GL_TRIANGLES p =. 0 while. p < (<:PN) do. q =. 0 while. q < (<:QN) do. p1 =. p + 1 q1 =. q + 1 NF0 =. (
NF0, NF1, NF2
NG0 =. ( ( ( ( (
(NT|i){NCOLOR
NB. glVertex >i{NF
NB. glEnd ''
NB. i =. i + 1
NB. end.
NB. X, Y, Z axis lines ====================
glLineWidth 1
glBegin GL_LINES
glColor 0 0 0 1 NB. X-axis, Black
glVertex 0 0 0
glVertex 3 0 0
glColor 0 0 1 1 NB. Y-axis, Blue
glVertex 0 0 0
glVertex 0 3 0
glColor 1 0 0 1 NB. Z-axis, Red
glVertex 0 0 0
glVertex 0 0 3
glEnd ''
)
NB. Moebius QUAD_STRIP by TN ========================
NB. using testmap(below) routine
ntest2 =: 3 : 0
NDATA2 =: 1 * L:0 makedata L:0 |: { SS; TT
NB. NDATA2 =: 0.6 * L:0 maketest L:0 |: { SS; TT
testmap NDATA2
)
light=:verb define
glLight GL_LIGHT0, GL_AMBIENT, 0.1 0.1 0.1 1
glLight GL_LIGHT0, GL_DIFFUSE, 0.7 0.7 0.7 1
glLight GL_LIGHT0,GL_SPECULAR, 0.0 0.0 0.0 1
glEnable GL_LIGHTING
glEnable GL_LIGHT0
glMaterial GL_FRONT,GL_AMBIENT_AND_DIFFUSE, 1 0 0.5 1
)
b2dpts=: noun define
_1.5 _1.5 4
_0.5 _1.5 2
0.5 _1.5 _1
1.5 _1.5 2
_1.5 _0.5 1
_0.5 _0.5 3
0.5 _0.5 0
1.5 _0.5 _1
_1.5 0.5 4
_0.5 0.5 0
0.5 0.5 3
1.5 0.5 4
_1.5 1.5 _2
_0.5 1.5 _2
0.5 1.5 0
1.5 1.5 _1
)
surface=:verb define
STEPS =. 4
if. JOB = 0 do. x=.b2dpts else. x=. VP0 end.
x=. ' ' ((x=LF)#i.#x)} x
points=: 0.5 * ".x
glClearColor 1 1 1 1
glClear GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT
glColor 1 1 1 1
glMatrixMode GL_MODELVIEW
glLoadIdentity''
glMap2 GL_MAP2_VERTEX_3,0 1 3 4 0 1 12 4, points
glEnable GL_MAP2_VERTEX_3
glEnable GL_AUTO_NORMAL
glMapGrid2 STEPS,0 1,STEPS,0 1
glEnable GL_DEPTH_TEST
glShadeModel GL_FLAT
glRotate R ,. 3 3 $ 1 0 0 0
NB. glRotate 85 1 1 1
NB. glTranslate T
glTranslate 0 _1 0
glScale 3#SC
glEvalMesh2 GL_FILL,0,STEPS,0,STEPS
)
NB. test / make QUAD_STRIP ========================================
wr =: 1!:2&2
rd =: 1!:1
NB. DA =: i. 3 4
NB. V =: 2 ]\0 1 2
NB. U =: 2 ]\0 1 2 3
NB. transpose along axis left_down to up_right 2013/6/10=========
NB. adapted to GL_QUAD_STRIP vertex order
NB. i. 2 2
NB. 0 1
NB. 2 3
NB. trt i. 2 2
NB. 0 2
NB. 1 3
trt =: 3 : '($y.) $ (, y.) (0 2 1 3) } , y.'
NB. =============================================================
testm_wr =: 3 : 0
'v u' =. <: $ y.
V =. 2 ]\ i. {. $ y.
U =. 2 ]\ i. {: $ y.
i =. 0
while. i < v
do.
j =. 0
while. j < u
do.
wr 'i:',(":i), ', j:',(":j)
wr 'color: ', ": >(NT|i){NCOLOR
NB. wr (i{V), (j{U)
NB. wr (<(i{V);(j{U)) { y.
wr trt (<(i{V);(j{U)) { y.
NB. wr VA =. 0 { 0 { (<(i{V);(j{U)) { y.
NB. wr VB =. 1 { 0 { (<(i{V);(j{U)) { y.
NB. wr VC =. 0 { 1 { (<(i{V);(j{U)) { y.
NB. wr VD =. 1 { 1 { (<(i{V);(j{U)) { y.
wr '---------'
if. 'n' = rd 1 do. 'quit' return. end.
j =. j + 1
end.
i =. i + 1
end.
'***'
)
nmap =: 3 : 0
NB. select. 3 | JOB
NB. case. 0 do. x=. VP1
NB. case. 1 do. x=. VP0
NB. case. 2 do. x=. b2dpts
NB. end.
x=. y.
x=. ' ' ((x=LF)#i.#x)} x
points=: SIZE * ".x
DAT =. <"(1) _3 [\ points
DA =: (4 4)$DAT
testmap DA
)
testmap =: 3 : 0
'v u' =. <: $ y.
V =. 2 ]\ i. {. $ y.
U =. 2 ]\ i. {: $ y.
i =. 0
while. i < v
do.
glBegin GL_QUAD_STRIP
j =. 0
while. j < u
do.
NB. wr (<(i{V);(j{U)) { y.
glColor >(NT|i){NCOLOR
NB. glVertex L:0 (<(i{V);(j{U)) { y.
NB. transpose along axis left_down to up_right
NB. trt =: 3 : '($y.) $ (, y.) (0 2 1 3) } , y.'
glVertex L:0 trt (<(i{V);(j{U)) { y. NB. using trt 2013/6/10
j =. j + 1
end.
glEnd ''
i =. i + 1
end.
)
a_Moebius_button=: 3 : 0
JOB =: 0
wd 'setfocus g'
)
a_Flower_button=: 3 : 0
JOB =: 10
wd 'setfocus g'
)