index.vwf.yaml 6.4 KB

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