index.vwf.yaml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. # A-Frame & VWF simple scene
  2. # Copyright 2017 Krestianstvo.org project
  3. ---
  4. extends: http://vwf.example.com/aframe/ascene.vwf
  5. properties:
  6. assets: "assets.json"
  7. children:
  8. sky:
  9. extends: http://vwf.example.com/aframe/asky.vwf
  10. properties:
  11. color: "#ECECEC"
  12. groundPlane:
  13. extends: http://vwf.example.com/aframe/aplane.vwf
  14. properties:
  15. height: 50
  16. width: 50
  17. repeat: "10 10"
  18. rotation: [-90, 0, 0]
  19. wireframe: false
  20. src: "#bg2"
  21. turtle:
  22. extends: http://vwf.example.com/aframe/asphere.vwf
  23. properties:
  24. position: [1, 1.25, -4]
  25. color: "#e0e014"
  26. radius: 0.3
  27. wireframe: true
  28. angleInRadians: 0
  29. counter: 1
  30. iteration:
  31. set: |
  32. this.iteration = value;
  33. this.makeLSys();
  34. value: 3
  35. angle:
  36. set: |
  37. this.angle = value;
  38. this.makeLSys();
  39. value: 60
  40. stepLength:
  41. set: |
  42. this.stepLength = value;
  43. this.makeLSys();
  44. value: 0.5
  45. rule:
  46. set: |
  47. this.rule = value;
  48. this.makeLSys();
  49. value: 'F++F++F'
  50. axiomF:
  51. set: |
  52. this.axiomF = value;
  53. this.makeLSys();
  54. value: 'F-F++F-F'
  55. axiomG:
  56. set: |
  57. this.axiomG = value;
  58. this.makeLSys();
  59. value: ''
  60. lsys: ''
  61. ready: false
  62. children:
  63. drawNode:
  64. extends: http://vwf.example.com/aframe/aentity.vwf
  65. lsysLang:
  66. extends: http://vwf.example.com/ohm/node.vwf
  67. properties:
  68. grammar:
  69. semantics:
  70. ohmLang: |
  71. LSys { Gen<x>
  72. = ReadRule+
  73. ReadRule
  74. = letters | symbols
  75. letters = "F" | "G"
  76. symbols = "-" | "+" }
  77. methods:
  78. initLang:
  79. body: |
  80. console.log("add operations to semantics")
  81. this.addOperationLang();
  82. addOperationLang:
  83. body: |
  84. this.semantics.addOperation('gen(x)', {
  85. Gen: function(e)
  86. {
  87. return e.gen(this.args.x);
  88. },
  89. ReadRule: function(e)
  90. {
  91. return e.gen(this.args.x);
  92. },
  93. letters: function(_)
  94. {
  95. for (var propName in this.args.x)
  96. {
  97. if (propName == this.sourceString)
  98. return this.args.x[propName]
  99. }
  100. return this.sourceString
  101. },
  102. symbols: function(_)
  103. {
  104. return this.sourceString;
  105. }
  106. });
  107. turtleLang:
  108. extends: http://vwf.example.com/ohm/node.vwf
  109. properties:
  110. grammar:
  111. semantics:
  112. ohmLang: |
  113. Turtle {
  114. Draw<x, y>
  115. = (drawLetter | turn)+
  116. drawLetter
  117. = letter
  118. turn
  119. = "+" | "-" }
  120. methods:
  121. initLang:
  122. body: |
  123. console.log("add operations to semantics")
  124. this.addOperationLang();
  125. addOperationLang:
  126. body: |
  127. var turtleID = this.parent.id;
  128. var self = this;
  129. this.semantics.addOperation('draw(x,y)', {
  130. Draw: function(e)
  131. {
  132. e.draw(this.args.x, this.args.y);
  133. },
  134. drawLetter: function(e)
  135. {
  136. //vwf_view.kernel.callMethod(turtleID, 'goForward', [this.args.x]);
  137. self.parent.goForward(this.args.x);
  138. },
  139. turn: function(e)
  140. {
  141. if (this.sourceString == "+")
  142. //vwf_view.kernel.callMethod(turtleID, 'turn', [this.args.y]);
  143. self.parent.turn(this.args.y);
  144. if (this.sourceString == "-")
  145. // vwf_view.kernel.callMethod(turtleID, 'turn', [-1 * this.args.y]);
  146. self.parent.turn(-1*this.args.y);
  147. }
  148. });
  149. methods:
  150. clearDraw: |
  151. let self = this
  152. let drawDef = {
  153. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  154. }
  155. this.children.delete(this.drawNode);
  156. this.children.create("drawNode", drawDef);
  157. this.angleInRadians = 0
  158. //this.drawNode.children.forEach(el => {
  159. // self.drawNode.children.delete(el)
  160. //})
  161. parseLSys: |
  162. var str = this.rule;
  163. var axioms = {"F": this.axiomF, "G": this.axiomG};
  164. for (var i = 1; i < this.iteration; i++)
  165. {
  166. var match = this.lsysLang.grammar.match(str, 'Gen<"y">');
  167. if (match.succeeded()){
  168. var res = this.lsysLang.semantics(match).gen(axioms);
  169. str = res.join("");
  170. }
  171. }
  172. console.log(str);
  173. this.lsys = str;
  174. makeLSys: |
  175. if (this.ready)
  176. {
  177. this.clearDraw();
  178. this.parseLSys();
  179. this.future(0.1).drawLSys();
  180. }
  181. drawLSys: |
  182. var match = this.turtleLang.grammar.match(this.lsys, 'Draw<"1","1">');
  183. if (match.succeeded()){
  184. var res = this.turtleLang.semantics(match).draw(this.stepLength, this.angle);
  185. }
  186. makeMe:
  187. parameters:
  188. - childName
  189. - startPosition
  190. - endPosition
  191. body: |
  192. //let nodeId = this.drawNode.id;
  193. var childComponent = {
  194. "extends": "http://vwf.example.com/aframe/lineComponent.vwf",
  195. "type": "component",
  196. "properties": {
  197. "start": startPosition,
  198. "end": endPosition,
  199. "color": "green"
  200. }
  201. }
  202. //vwf_view.kernel.createChild(this.id, childName, childComponent);
  203. this.drawNode.children.create(childName, childComponent);
  204. turn:
  205. parameters:
  206. - angle
  207. body: |
  208. var angle0 = this.angleInRadians;
  209. var targetAngle = angle * Math.PI / 180.0;
  210. this.angleInRadians = angle0 + targetAngle;
  211. goForward:
  212. parameters:
  213. - step
  214. body: |
  215. let pos = AFRAME.utils.coordinates.parse(this.drawNode.position);
  216. var x0 = pos.x;
  217. var y0 = pos.y;
  218. var xx = Math.sin(this.angleInRadians);
  219. var yy = Math.cos(this.angleInRadians);
  220. let endPosition = AFRAME.utils.coordinates.stringify({x: x0 + step * xx, y: y0 + step * yy, z: pos.z});
  221. this.counter = this.counter + 1;
  222. this.makeMe('line__' + this.counter, this.drawNode.position, endPosition);
  223. this.drawNode.position = endPosition;
  224. initialize:
  225. body: |
  226. this.ready = true;
  227. console.log("initialising turtle");
  228. //vwf_view.kernel.callMethod(this.id, "testDrawLsys");
  229. methods:
  230. initialize:
  231. body: |
  232. //this.turtle.ready = true;
  233. console.log("initialising scene");
  234. //vwf_view.kernel.callMethod(this.id, "testDrawLsys");
  235. drawLSys1: |
  236. this.turtle.makeLSys()
  237. createNewTurtle: |
  238. console.log("create new turtle");
  239. let newTurtle = this.turtle;
  240. let randomName = "turtle-" + this.random();
  241. this.children.create(randomName, newTurtle);
  242. testTurtle: |
  243. this.turtle.goForward(1);
  244. this.turtle.goForward(1);
  245. this.turtle.turn(45);
  246. this.turtle.goForward(1);
  247. this.turtle.goForward(1);
  248. this.turtle.turn(45);
  249. this.turtle.goForward(1);