index.vwf.json 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. {
  2. "extends": "proxy/aframe/ascene.vwf",
  3. "methods": {
  4. "initialize": {
  5. "body": " console.log(\"initialising scene\");\n",
  6. "type": "application/javascript"
  7. },
  8. "drawLSys1": {
  9. "body": " this.turtle.makeLSys()\n",
  10. "type": "application/javascript"
  11. },
  12. "testTurtle": {
  13. "body": " this.turtle.goForward(1);\n this.turtle.goForward(1);\n this.turtle.turn(45);\n this.turtle.goForward(1);\n this.turtle.goForward(1);\n this.turtle.turn(45);\n this.turtle.goForward(1);\n",
  14. "type": "application/javascript"
  15. }
  16. },
  17. "children": {
  18. "assetBG2": {
  19. "extends": "proxy/aframe/a-asset-image-item.vwf",
  20. "properties": {
  21. "itemID": "bg2",
  22. "itemSrc": "/defaults/assets/checker.jpg"
  23. }
  24. },
  25. "skySun": {
  26. "extends": "proxy/aframe/aentity.vwf",
  27. "children": {
  28. "sun": {
  29. "extends": "proxy/aframe/app-sun-component.vwf"
  30. }
  31. }
  32. },
  33. "newSky": {
  34. "extends": "proxy/aframe/aentity.vwf",
  35. "children": {
  36. "skyshader": {
  37. "extends": "proxy/aframe/app-skyshader-component.vwf"
  38. }
  39. }
  40. },
  41. "groundPlane": {
  42. "extends": "proxy/aframe/aplane.vwf",
  43. "properties": {
  44. "height": "50",
  45. "width": "50",
  46. "rotation": [
  47. -90,
  48. 0,
  49. 0
  50. ]
  51. },
  52. "children": {
  53. "material": {
  54. "extends": "proxy/aframe/aMaterialComponent.vwf",
  55. "properties": {
  56. "wireframe": false,
  57. "src": "#bg2",
  58. "repeat": "10 10"
  59. }
  60. }
  61. }
  62. },
  63. "turtle": {
  64. "extends": "proxy/aframe/asphere.vwf",
  65. "properties": {
  66. "position": [
  67. 1,
  68. 1.25,
  69. -4
  70. ],
  71. "radius": "0.2",
  72. "angleInRadians": {
  73. "value": 0,
  74. "get": "",
  75. "set": ""
  76. },
  77. "iteration": {
  78. "value": 5,
  79. "get": "",
  80. "set": ""
  81. },
  82. "angle": {
  83. "value": 60,
  84. "get": "",
  85. "set": ""
  86. },
  87. "stepLength": {
  88. "value": 0.3,
  89. "get": "",
  90. "set": ""
  91. },
  92. "rule": {
  93. "value": "F",
  94. "get": "",
  95. "set": ""
  96. },
  97. "axiomF": {
  98. "value": "G-F-G",
  99. "get": "",
  100. "set": ""
  101. },
  102. "axiomG": {
  103. "value": "F+G+F",
  104. "get": "",
  105. "set": ""
  106. },
  107. "lsys": {
  108. "value": "",
  109. "get": "",
  110. "set": ""
  111. },
  112. "readyForDraw": {
  113. "value": true,
  114. "get": "",
  115. "set": ""
  116. }
  117. },
  118. "methods": {
  119. "parseLSys": {
  120. "body": " var str = this.rule;\n var axioms = {\"F\": this.axiomF, \"G\": this.axiomG};\n for (var i = 1; i < this.iteration; i++)\n {\n var match = this.lsysLang.grammar.match(str, 'Gen<\"y\">');\n if (match.succeeded()){\n var res = this.lsysLang.semantics(match).gen(axioms);\n str = res.join(\"\");\n }\n }\n console.log(str);\n this.lsys = str;\n",
  121. "type": "application/javascript"
  122. },
  123. "makeLSys": {
  124. "body": " if (this.readyForDraw){\n this.drawNode.position = [0, 0, 0]\n this.angleInRadians = 0;\n this.drawNode.linepath.path = [];\n this.parseLSys();\n this.drawLSys();\n this.drawNode.position = [0, 0, 0]\n }\n",
  125. "type": "application/javascript"
  126. },
  127. "drawLSys": {
  128. "body": " var match = this.turtleLang.grammar.match(this.lsys, 'Draw<\"1\",\"1\">');\n if (match.succeeded()){\n var res = this.turtleLang.semantics(match).draw(this.stepLength, this.angle);\n }\n",
  129. "type": "application/javascript"
  130. },
  131. "turn": {
  132. "parameters": [
  133. "angle"
  134. ],
  135. "body": " var angle0 = this.angleInRadians;\n var targetAngle = angle * Math.PI / 180.0;\n this.angleInRadians = angle0 + targetAngle;\n",
  136. "type": "application/javascript"
  137. },
  138. "goForward": {
  139. "parameters": [
  140. "step"
  141. ],
  142. "body": " let pos = this.drawNode.position;\n var x0 = pos[0];\n var y0 = pos[1];\n var xx = Math.sin(this.angleInRadians);\n var yy = Math.cos(this.angleInRadians);\n let startPosition = {x: pos[0], y: pos[1], z:pos[2]};\n let endPosition = {x: x0 + step * xx, y: y0 + step * yy, z: pos[2]};\n var drawPath = this.drawNode.linepath.path.slice();\n drawPath.push(startPosition);\n drawPath.push(endPosition);\n this.drawNode.linepath.path = drawPath;\n this.drawNode.position = [endPosition.x, endPosition.y, endPosition.z];\n",
  143. "type": "application/javascript"
  144. },
  145. "setTurtleParams": {
  146. "parameters": [
  147. "val"
  148. ],
  149. "body": " this.readyForDraw = false;\n val.forEach(el => {\n this[el[0]] = el[1]\n })\n this.readyForDraw = true;\n this.makeLSys();\n",
  150. "type": "application/javascript"
  151. },
  152. "initialize": {
  153. "body": " //this.redrawEvent = function(){this.makeLSys()}\n vwf_view.kernel.callMethod(this.id, \"makeLSys\");\n console.log(\"initialising turtle\");\n",
  154. "type": "application/javascript"
  155. }
  156. },
  157. "children": {
  158. "interpolation": {
  159. "extends": "proxy/aframe/interpolation-component.vwf",
  160. "properties": {
  161. "enabled": true
  162. }
  163. },
  164. "material": {
  165. "extends": "proxy/aframe/aMaterialComponent.vwf",
  166. "properties": {
  167. "wireframe": true,
  168. "color": "#e0e014"
  169. }
  170. },
  171. "drawNode": {
  172. "extends": "proxy/aframe/aentity.vwf",
  173. "properties": {
  174. "position": [
  175. 0,
  176. 0,
  177. 0
  178. ]
  179. },
  180. "children": {
  181. "linepath": {
  182. "extends": "proxy/aframe/linepath.vwf",
  183. "properties": {
  184. "color": "#445447",
  185. "path": [
  186. ],
  187. "width": 0.02
  188. }
  189. }
  190. }
  191. },
  192. "lsysLang": {
  193. "extends": "proxy/ohm/node.vwf",
  194. "properties": {
  195. "ohmLang": "LSys { Gen<x> \n = ReadRule+ \n ReadRule \n = letters | symbols\n letters = \"F\" | \"G\" \n symbols = \"-\" | \"+\" }\n"
  196. },
  197. "methods": {
  198. "initLang": {
  199. "body": " console.log(\"add operations to semantics\")\n this.addOperationLang();\n",
  200. "type": "application/javascript"
  201. },
  202. "addOperationLang": {
  203. "body": " this.semantics.addOperation('gen(x)', {\n Gen: function(e)\n {\n return e.gen(this.args.x);\n },\n ReadRule: function(e)\n {\n return e.gen(this.args.x);\n },\n letters: function(_)\n {\n for (var propName in this.args.x)\n {\n if (propName == this.sourceString)\n return this.args.x[propName]\n }\n return this.sourceString\n },\n symbols: function(_)\n {\n return this.sourceString;\n }\n });\n",
  204. "type": "application/javascript"
  205. }
  206. }
  207. },
  208. "turtleLang": {
  209. "extends": "proxy/ohm/node.vwf",
  210. "properties": {
  211. "ohmLang": "Turtle {\nDraw<x, y> \n = (drawLetter | turn)+ \ndrawLetter \n = letter\nturn \n = \"+\" | \"-\" }\n"
  212. },
  213. "methods": {
  214. "initLang": {
  215. "body": " console.log(\"add operations to semantics\")\n this.addOperationLang();\n",
  216. "type": "application/javascript"
  217. },
  218. "addOperationLang": {
  219. "body": " var turtleID = this.parent.id;\n var self = this;\n this.semantics.addOperation('draw(x,y)', {\n Draw: function(e)\n {\n e.draw(this.args.x, this.args.y);\n },\n drawLetter: function(e)\n {\n //vwf_view.kernel.callMethod(turtleID, 'goForward', [this.args.x]);\n self.parent.goForward(this.args.x);\n },\n turn: function(e)\n {\n if (this.sourceString == \"+\")\n //vwf_view.kernel.callMethod(turtleID, 'turn', [this.args.y]);\n self.parent.turn(this.args.y);\n if (this.sourceString == \"-\")\n //vwf_view.kernel.callMethod(turtleID, 'turn', [-1 * this.args.y]);\n self.parent.turn(-1*this.args.y);\n }\n });\n",
  220. "type": "application/javascript"
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }