Penrose.tcl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Generate set of boxes resembling OCC logo and arranged in the shape of
  2. # Penrose triangle on perspective view.
  3. # The sample shows how the viewer can be manipulated to produce required
  4. # visual effect
  5. #Category: Visualization
  6. #Title: Penrose triangle on perspective view
  7. pload MODELING VISUALIZATION
  8. # Ray-Tracing doesn't work with Compatible Profile on macOS
  9. if { $::tcl_platform(os) == "Darwin" } { vcaps -core }
  10. # procedure to define box dimensions
  11. set scale 1.
  12. set ratio 0.94
  13. proc defbox {} {
  14. global scale ratio
  15. set scale [expr $scale * $ratio]
  16. return [list 1.8*$scale 1.8*$scale 1.3*$scale]
  17. }
  18. # make set of boxes
  19. eval box b1 0 0 0 [defbox]
  20. eval box b2 2 0 0 [defbox]
  21. eval box b3 4 0 0 [defbox]
  22. eval box b4 6 0 0 [defbox]
  23. eval box b5 6 -1.5 0 [defbox]
  24. eval box b6 6 -3 0 [defbox]
  25. eval box b7 6 -4.5 0 [defbox]
  26. eval box b8 6 -6 0 [defbox]
  27. eval box b9 6 -6 1 [defbox]
  28. eval box b10 6 -6 2 [defbox]
  29. # cut last box by prisms created from the first two to make impression
  30. # that it is overlapped by these on selected view (see vviewparams below)
  31. explode b1 f
  32. explode b2 f
  33. prism p0 b1_5 12.3 -14 6.8
  34. bcut bx b10 p0
  35. prism p1 b2_3 12 -14 6.8
  36. bcut bxx bx p1
  37. tcopy bxx b10
  38. # make some boxes hollow
  39. for {set i 1} {$i <= 1} {incr i} {
  40. set dim [bounding b$i -save xmin ymin zmin xmax ymax zmax]
  41. set dx [dval xmax-xmin]
  42. set x1 [dval xmin+0.1*$dx]
  43. set x2 [dval ymin+0.1*$dx]
  44. set x3 [dval zmin+0.1*$dx]
  45. box bc $x1 $x2 $x3 0.8*$dx 0.8*$dx $dx
  46. bcut bb b$i bc
  47. tcopy bb b$i
  48. }
  49. # prepare a view
  50. vinit Penrose w=1024 h=512
  51. vbackground -color WHITE
  52. vrenderparams -rayTrace -fsaa on -reflections off -shadows off
  53. # set camera position and adjust lights
  54. vcamera -persp -fovy 25
  55. vviewparams -eye 14 -14 6.8 -up 0 0 1 -at 4 -4 0 -scale 70
  56. vsetdispmode 1
  57. vlight -defaults
  58. vlight dirlight1 -type DIRECTIONAL -direction 1 -2 -10 -head 1 -color WHITE
  59. vlight dirlight2 -type DIRECTIONAL -direction 0 -10 0 -head 1 -color WHITE
  60. # display boxes
  61. vdisplay b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
  62. # set colors like in boxes of on OCC logo
  63. vsetcolor b1 DD0029
  64. vsetcolor b2 F6DD00
  65. vsetcolor b3 98F918
  66. vsetcolor b4 E9007A
  67. vsetcolor b5 007ABC
  68. vsetcolor b6 93007A
  69. vsetcolor b7 EE9800
  70. vsetcolor b8 00B489
  71. vsetcolor b9 00A47A
  72. vsetcolor b10 007ABC
  73. # set material to plastic for better look
  74. for {set i 1} {$i <= 10} {incr i} {vsetmaterial b$i plastic}
  75. vdrawtext label "Which\nbox\nis\ncloser\nto\nyou?" -pos 0 -6 -2 -color BLACK -halign left -valign bottom -angle 0 -zoom 0 -height 40