Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. module Main where
  2.  
  3. import Prelude hiding (add)
  4. import Control.Monad.Eff
  5. import Data.Foreign
  6. import Data.Foreign.Class
  7. import Data.List
  8. import Data.Maybe
  9. import Prim as P
  10. import Math as Math
  11.  
  12. import Mathbox.Classes as C
  13. import Mathbox.Field
  14. import Mathbox.Mathbox
  15. import Mathbox.Types as T
  16.  
  17. matrixData = write $ [
  18. [
  19. [-1, -1, -1],
  20. [-1, -1, -1],
  21. [ 1, -1, -1],
  22. [ 1, -1, -1]],
  23. [
  24. [-1, -1, 1],
  25. [-1, -1, 1],
  26. [ 1, -1, 1],
  27. [ 1, -1, 1]]
  28. ]
  29.  
  30. mathbox :: MathboxPrimitive
  31. mathbox =
  32. cartesian [
  33. cam,
  34. matrix,
  35. cube 0.9,
  36. transform (T.mkVec3 0 4 0) [],
  37. cube 0.5,
  38. transform (T.mkVec3 4 0 0) [],
  39. cube 0.1
  40. ]
  41.  
  42. cartesian :: Array MathboxPrimitive -> MathboxPrimitive
  43. cartesian nested =
  44. (Cartesian $ C.mkCartesian {
  45. range = Val [T.mkVec2 (-5) 5, T.mkVec2 (-5) 5, T.mkVec2 (-5) 5],
  46. scale = Val (T.mkVec3 1 1 1)
  47. }) ( fromFoldable nested )
  48.  
  49. cam :: MathboxPrimitive
  50. cam = Camera $ C.mkCamera { proxy = Val true, position = Just $ Val $ T.mkVec3 2 3 3 }
  51.  
  52. matrix :: MathboxPrimitive
  53. matrix = Matrix $ C.mkMatrix { data = Just $ Val matrixData, channels = Val 3 }
  54.  
  55. surface :: String -> Number -> MathboxPrimitive
  56. surface c o = Surface $ C.mkSurface { color = Val $ T.unsafeMkColor c, opacity = Val o }
  57.  
  58. transform :: T.Vec3 -> Array MathboxPrimitive -> MathboxPrimitive
  59. transform v3 nested = (Transform3 $ C.mkTransform3 { position = Val $ v3 }) ( fromFoldable nested )
  60.  
  61. group :: Array MathboxPrimitive -> MathboxPrimitive
  62. group nested = (Group $ C.mkGroup { active = Val true }) ( fromFoldable nested )
  63.  
  64. swizzle :: Array Int -> MathboxPrimitive
  65. swizzle s = Swizzle $ C.mkSwizzle { order = Val $ T.mkSwizzle1 s }
  66.  
  67. cube :: Number -> MathboxPrimitive
  68. cube opacity =
  69. group [
  70. surface "blue" opacity,
  71. transform (T.mkVec3 0 2 0) [
  72. surface "blue" opacity,
  73. transform (T.mkVec3 0 (-2) 0) [
  74. swizzle [2, 3, 1],
  75. surface "red" opacity,
  76. transform (T.mkVec3 2 0 0) [
  77. surface "red" opacity,
  78. transform (T.mkVec3 (-2) 0 0) [
  79. swizzle [3, 2, 1],
  80. surface "yellow" opacity,
  81. transform (T.mkVec3 0 0 2) [
  82. surface "yellow" opacity
  83. ]
  84. ]
  85. ]
  86. ]
  87. ]
  88. ]
  89.  
  90.  
  91. main = do
  92. mkMathbox { plugins: ["core", "controls", "cursor"]
  93. , controls: { klass: orbitControls }
  94. , fullscreen: true
  95. } >>=
  96. applyOnThree (setThreeClearColor colorWhite 1.0) >>=
  97. set { focus: Just 3.0, scale: Just 720.0 } >>=
  98. add (toJs mathbox)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement