index.vwf.yaml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. iteration: 3
  8. angle: 60
  9. stepLength: 0.5
  10. rule: 'F++F++F'
  11. axiomF: 'F-F++F-F'
  12. axiomG: ''
  13. methods:
  14. initialize:
  15. body: |
  16. console.log("initialize");
  17. //vwf_view.kernel.callMethod(this.id, "testDrawLsys");
  18. testDrawLsys: |
  19. let lsys = this.parseLSys();
  20. var match = this.turtleLang.grammar.match(lsys, 'Draw<"1","1">');
  21. if (match.succeeded()){
  22. var res = this.turtleLang.semantics(match).draw(this.stepLength, this.angle);
  23. }
  24. testTurtle: |
  25. this.turtle.goForward(1);
  26. this.turtle.goForward(1);
  27. this.turtle.turn(45);
  28. this.turtle.goForward(1);
  29. this.turtle.goForward(1);
  30. this.turtle.turn(45);
  31. this.turtle.goForward(1);
  32. makeMe:
  33. parameters:
  34. - childName
  35. - startPosition
  36. - endPosition
  37. body: |
  38. let nodeId = this.turtleDraw.id;
  39. var childComponent = {
  40. "extends": "http://vwf.example.com/aframe/lineComponent.vwf",
  41. "type": "component",
  42. "properties": {
  43. "start": startPosition,
  44. "end": endPosition,
  45. "color": "green"
  46. }
  47. }
  48. vwf_view.kernel.createChild(nodeId, childName, childComponent);
  49. parseLSys: |
  50. var str = this.rule;
  51. var axioms = {"F": this.axiomF, "G": this.axiomG};
  52. for (var i = 1; i < this.iteration; i++)
  53. {
  54. var match = this.lsysLang.grammar.match(str, 'Gen<"y">');
  55. if (match.succeeded()){
  56. var res = this.lsysLang.semantics(match).gen(axioms);
  57. str = res.join("");
  58. }
  59. }
  60. console.log(str);
  61. return str;
  62. children:
  63. lsysLang:
  64. extends: http://vwf.example.com/ohm/node.vwf
  65. properties:
  66. grammar:
  67. semantics:
  68. ohmLang: |
  69. LSys { Gen<x>
  70. = ReadRule+
  71. ReadRule
  72. = letters | symbols
  73. letters = "F" | "G"
  74. symbols = "-" | "+" }
  75. methods:
  76. initLang:
  77. body: |
  78. console.log("add operations to semantics")
  79. this.addOperationLang();
  80. addOperationLang:
  81. body: |
  82. this.semantics.addOperation('gen(x)', {
  83. Gen: function(e)
  84. {
  85. return e.gen(this.args.x);
  86. },
  87. ReadRule: function(e)
  88. {
  89. return e.gen(this.args.x);
  90. },
  91. letters: function(_)
  92. {
  93. for (var propName in this.args.x)
  94. {
  95. if (propName == this.sourceString)
  96. return this.args.x[propName]
  97. }
  98. return this.sourceString
  99. },
  100. symbols: function(_)
  101. {
  102. return this.sourceString;
  103. }
  104. });
  105. turtleLang:
  106. extends: http://vwf.example.com/ohm/node.vwf
  107. properties:
  108. grammar:
  109. semantics:
  110. ohmLang: |
  111. Turtle {
  112. Draw<x, y>
  113. = (drawLetter | turn)+
  114. drawLetter
  115. = letter
  116. turn
  117. = "+" | "-" }
  118. methods:
  119. initLang:
  120. body: |
  121. console.log("add operations to semantics")
  122. this.addOperationLang();
  123. addOperationLang:
  124. body: |
  125. var turtleID = this.parent.turtle.id;
  126. var self = this;
  127. this.semantics.addOperation('draw(x,y)', {
  128. Draw: function(e)
  129. {
  130. e.draw(this.args.x, this.args.y);
  131. },
  132. drawLetter: function(e)
  133. {
  134. //vwf_view.kernel.callMethod(turtleID, 'goForward', [this.args.x]);
  135. self.parent.turtle.goForward(this.args.x);
  136. },
  137. turn: function(e)
  138. {
  139. if (this.sourceString == "+")
  140. //vwf_view.kernel.callMethod(turtleID, 'turn', [this.args.y]);
  141. self.parent.turtle.turn(this.args.y);
  142. if (this.sourceString == "-")
  143. // vwf_view.kernel.callMethod(turtleID, 'turn', [-1 * this.args.y]);
  144. self.parent.turtle.turn(-1*this.args.y);
  145. }
  146. });
  147. groundPlane:
  148. extends: http://vwf.example.com/aframe/aplane.vwf
  149. properties:
  150. height: 50
  151. width: 50
  152. repeat: "10 10"
  153. rotation: [-90, 0, 0]
  154. wireframe: false
  155. src: "#bg2"
  156. turtleDraw:
  157. extends: http://vwf.example.com/aframe/aentity.vwf
  158. properties:
  159. position: [1, 1.25, -4]
  160. turtle:
  161. extends: http://vwf.example.com/aframe/asphere.vwf
  162. properties:
  163. position: [1, 1.25, -4]
  164. color: "#e0e014"
  165. radius: 1
  166. wireframe: true
  167. angleInRadians: 0
  168. counter: 1
  169. methods:
  170. turn:
  171. parameters:
  172. - angle
  173. body: |
  174. var angle0 = this.angleInRadians;
  175. var targetAngle = angle * Math.PI / 180.0;
  176. this.angleInRadians = angle0 + targetAngle;
  177. goForward:
  178. parameters:
  179. - step
  180. body: |
  181. let pos = AFRAME.utils.coordinates.parse(this.position);
  182. var x0 = pos.x;
  183. var y0 = pos.y;
  184. var xx = Math.sin(this.angleInRadians);
  185. var yy = Math.cos(this.angleInRadians);
  186. let endPosition = AFRAME.utils.coordinates.stringify({x: x0 + step * xx, y: y0 + step * yy, z: pos.z});
  187. this.counter = this.counter + 1;
  188. this.parent.makeMe('line__' + this.counter, this.position, endPosition);
  189. this.position = endPosition;
  190. sky:
  191. extends: http://vwf.example.com/aframe/asky.vwf
  192. properties:
  193. color: "#ECECEC"