index.vwf.yaml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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/a-sun-sky.vwf
  10. properties:
  11. sunPosition: "-0.2 5 -5"
  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.2
  27. wireframe: true
  28. angleInRadians: 0
  29. iteration: 3
  30. angle: 60
  31. stepLength: 0.5
  32. rule: 'F++F++F'
  33. axiomF: 'F-F++F-F'
  34. axiomG: ''
  35. lsys: ''
  36. readyForDraw: true
  37. children:
  38. drawNode:
  39. extends: http://vwf.example.com/aframe/aentity.vwf
  40. children:
  41. linepath:
  42. extends: http://vwf.example.com/aframe/linepath.vwf
  43. properties:
  44. color: "#445447"
  45. path: []
  46. width: 0.02
  47. lsysLang:
  48. extends: http://vwf.example.com/ohm/node.vwf
  49. properties:
  50. grammar:
  51. semantics:
  52. ohmLang: |
  53. LSys { Gen<x>
  54. = ReadRule+
  55. ReadRule
  56. = letters | symbols
  57. letters = "F" | "G"
  58. symbols = "-" | "+" }
  59. methods:
  60. initLang:
  61. body: |
  62. console.log("add operations to semantics")
  63. this.addOperationLang();
  64. addOperationLang:
  65. body: |
  66. this.semantics.addOperation('gen(x)', {
  67. Gen: function(e)
  68. {
  69. return e.gen(this.args.x);
  70. },
  71. ReadRule: function(e)
  72. {
  73. return e.gen(this.args.x);
  74. },
  75. letters: function(_)
  76. {
  77. for (var propName in this.args.x)
  78. {
  79. if (propName == this.sourceString)
  80. return this.args.x[propName]
  81. }
  82. return this.sourceString
  83. },
  84. symbols: function(_)
  85. {
  86. return this.sourceString;
  87. }
  88. });
  89. turtleLang:
  90. extends: http://vwf.example.com/ohm/node.vwf
  91. properties:
  92. grammar:
  93. semantics:
  94. ohmLang: |
  95. Turtle {
  96. Draw<x, y>
  97. = (drawLetter | turn)+
  98. drawLetter
  99. = letter
  100. turn
  101. = "+" | "-" }
  102. methods:
  103. initLang:
  104. body: |
  105. console.log("add operations to semantics")
  106. this.addOperationLang();
  107. addOperationLang:
  108. body: |
  109. var turtleID = this.parent.id;
  110. var self = this;
  111. this.semantics.addOperation('draw(x,y)', {
  112. Draw: function(e)
  113. {
  114. e.draw(this.args.x, this.args.y);
  115. },
  116. drawLetter: function(e)
  117. {
  118. //vwf_view.kernel.callMethod(turtleID, 'goForward', [this.args.x]);
  119. self.parent.goForward(this.args.x);
  120. },
  121. turn: function(e)
  122. {
  123. if (this.sourceString == "+")
  124. //vwf_view.kernel.callMethod(turtleID, 'turn', [this.args.y]);
  125. self.parent.turn(this.args.y);
  126. if (this.sourceString == "-")
  127. //vwf_view.kernel.callMethod(turtleID, 'turn', [-1 * this.args.y]);
  128. self.parent.turn(-1*this.args.y);
  129. }
  130. });
  131. methods:
  132. parseLSys: |
  133. var str = this.rule;
  134. var axioms = {"F": this.axiomF, "G": this.axiomG};
  135. for (var i = 1; i < this.iteration; i++)
  136. {
  137. var match = this.lsysLang.grammar.match(str, 'Gen<"y">');
  138. if (match.succeeded()){
  139. var res = this.lsysLang.semantics(match).gen(axioms);
  140. str = res.join("");
  141. }
  142. }
  143. console.log(str);
  144. this.lsys = str;
  145. makeLSys: |
  146. if (this.readyForDraw){
  147. this.drawNode.position = [0, 0, 0]
  148. this.angleInRadians = 0;
  149. this.drawNode.linepath.path = [];
  150. this.parseLSys();
  151. this.drawLSys();
  152. this.drawNode.position = [0, 0, 0]
  153. }
  154. drawLSys: |
  155. var match = this.turtleLang.grammar.match(this.lsys, 'Draw<"1","1">');
  156. if (match.succeeded()){
  157. var res = this.turtleLang.semantics(match).draw(this.stepLength, this.angle);
  158. }
  159. turn:
  160. parameters:
  161. - angle
  162. body: |
  163. var angle0 = this.angleInRadians;
  164. var targetAngle = angle * Math.PI / 180.0;
  165. this.angleInRadians = angle0 + targetAngle;
  166. goForward:
  167. parameters:
  168. - step
  169. body: |
  170. let pos = AFRAME.utils.coordinates.parse(this.drawNode.position);
  171. var x0 = pos.x;
  172. var y0 = pos.y;
  173. var xx = Math.sin(this.angleInRadians);
  174. var yy = Math.cos(this.angleInRadians);
  175. let startPosition = AFRAME.utils.coordinates.parse(this.drawNode.position);
  176. let endPosition = {x: x0 + step * xx, y: y0 + step * yy, z: pos.z};
  177. var drawPath = this.drawNode.linepath.path;
  178. drawPath.push(startPosition);
  179. drawPath.push(endPosition);
  180. vwf_view.kernel.setProperty(this.drawNode.linepath.id, 'path', drawPath);
  181. this.drawNode.position = endPosition;
  182. setTurtleParams:
  183. parameters:
  184. - val
  185. body: |
  186. this.readyForDraw = false;
  187. val.forEach(el => {
  188. this[el[0]] = el[1]
  189. })
  190. this.readyForDraw = true;
  191. this.makeLSys();
  192. initialize:
  193. body: |
  194. //this.redrawEvent = function(){this.makeLSys()}
  195. vwf_view.kernel.callMethod(this.id, "makeLSys");
  196. console.log("initialising turtle");
  197. methods:
  198. initialize:
  199. body: |
  200. console.log("initialising scene");
  201. drawLSys1: |
  202. this.turtle.makeLSys()
  203. testTurtle: |
  204. this.turtle.goForward(1);
  205. this.turtle.goForward(1);
  206. this.turtle.turn(45);
  207. this.turtle.goForward(1);
  208. this.turtle.goForward(1);
  209. this.turtle.turn(45);
  210. this.turtle.goForward(1);