Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Draw-a-sphere/PicoLisp/draw-a-sphere-1.l
Normal file
26
Task/Draw-a-sphere/PicoLisp/draw-a-sphere-1.l
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(load "@lib/openGl.l")
|
||||
|
||||
(glutInit)
|
||||
(glutInitDisplayMode (| GLUT_RGBA GLUT_DOUBLE GLUT_ALPHA GLUT_DEPTH))
|
||||
(glutInitWindowSize 400 400)
|
||||
(glutCreateWindow "Sphere")
|
||||
|
||||
(glEnable GL_LIGHTING)
|
||||
(glEnable GL_LIGHT0)
|
||||
(glLightiv GL_LIGHT0 GL_POSITION (10 10 -10 0))
|
||||
|
||||
(glEnable GL_COLOR_MATERIAL)
|
||||
(glColorMaterial GL_FRONT_AND_BACK GL_AMBIENT_AND_DIFFUSE)
|
||||
|
||||
(glClearColor 0.3 0.3 0.5 0)
|
||||
(glColor4f 0.0 0.8 0.0 1.0)
|
||||
|
||||
(displayPrg
|
||||
(glClear (| GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
|
||||
(glutSolidSphere 0.9 40 32)
|
||||
(glFlush)
|
||||
(glutSwapBuffers) )
|
||||
|
||||
# Exit upon mouse click
|
||||
(mouseFunc '((Btn State X Y) (bye)))
|
||||
(glutMainLoop)
|
||||
60
Task/Draw-a-sphere/PicoLisp/draw-a-sphere-2.l
Normal file
60
Task/Draw-a-sphere/PicoLisp/draw-a-sphere-2.l
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
(scl 24)
|
||||
|
||||
(setq *Shades
|
||||
(list "." ":" "!" "*" "o" "e" "&" "#" "%" "@"))
|
||||
|
||||
(setq *Light
|
||||
(list 30.0 30.0 -50.0))
|
||||
|
||||
(de normalize (V)
|
||||
(let Len
|
||||
(sqrt
|
||||
(sum
|
||||
(quote (X)
|
||||
(** X 2))
|
||||
V))
|
||||
(mapcar
|
||||
(quote (X)
|
||||
(*/ X 1.0 Len))
|
||||
V)))
|
||||
|
||||
(de dot (X Y)
|
||||
(let D (sum (quote (A B) (*/ A B 1.0)) X Y)
|
||||
(if (< D 0) (- D) 0)))
|
||||
|
||||
(de floor (N)
|
||||
(* 1.0 (*/ (- N 0.5) 1.0)))
|
||||
|
||||
(de ceil (N)
|
||||
(* 1.0 (*/ (+ N 0.5) 1.0)))
|
||||
|
||||
(de drawSphere (R K Ambient)
|
||||
(let Vec NIL
|
||||
(for (I (floor (- R)) (<= I (ceil R)) (+ I 1.0))
|
||||
(let X (+ I 0.5)
|
||||
(for (J (floor (* -2 R)) (<= J (ceil (* 2 R))) (+ J 1.0))
|
||||
(let Y (+ (/ J 2) 0.5)
|
||||
(if (<= (+ (*/ X X 1.0) (*/ Y Y 1.0)) (*/ R R 1.0))
|
||||
(prog
|
||||
(setq Vec
|
||||
(list X Y
|
||||
(sqrt
|
||||
(* 1.0
|
||||
(- (*/ R R 1.0)
|
||||
(*/ X X 1.0)
|
||||
(*/ Y Y 1.0))))))
|
||||
(setq Vec (normalize Vec))
|
||||
(let (B NIL
|
||||
Intensity NIL)
|
||||
(setq B (+ (/ (** (dot *Light Vec) K) (** 1.0 (- K 1))) Ambient))
|
||||
(setq Intensity
|
||||
(if (<= B 0)
|
||||
(- (length *Shades) 2)
|
||||
(max (format (round (*/ (- 1.0 B) (* (- (length *Shades) 1) 1.0) 1.0) 0)) 0)))
|
||||
(prin (nth *Shades (+ Intensity 1) 1))))
|
||||
(prin " "))))
|
||||
(prinl)))))
|
||||
|
||||
(setq *Light (normalize *Light))
|
||||
(drawSphere 20.0 4 0.1)
|
||||
(drawSphere 10.0 2 0.4)
|
||||
Loading…
Add table
Add a link
Reference in a new issue