index.vwf.json 8.0 KB

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