index.vwf.yaml 6.7 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. 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. - position
  36. body: |
  37. var pos = position;
  38. if (typeof position === 'string' ){
  39. pos = JSON.parse(position);}
  40. let nodeId = this.turtleDraw.id;
  41. var childComponent = {
  42. "id": childName,
  43. "uri": childName,
  44. "extends": "http://vwf.example.com/aframe/abox.vwf",
  45. "properties": {
  46. "height": "0.2",
  47. "width": "0.2",
  48. "depth": "0.2",
  49. "color": "green",
  50. "position": [pos[0], pos[1], pos[2]]
  51. },
  52. "methods": {
  53. },
  54. "scripts": []
  55. };
  56. vwf_view.kernel.createChild(nodeId, childName, childComponent);
  57. parseLSys: |
  58. var str = this.rule;
  59. var axioms = {"F": this.axiomF, "G": this.axiomG};
  60. for (var i = 1; i < this.iteration; i++)
  61. {
  62. var match = this.lsysLang.grammar.match(str, 'Gen<"y">');
  63. if (match.succeeded()){
  64. var res = this.lsysLang.semantics(match).gen(axioms);
  65. str = res.join("");
  66. }
  67. }
  68. console.log(str);
  69. return str;
  70. children:
  71. lsysLang:
  72. extends: http://vwf.example.com/ohm/node.vwf
  73. properties:
  74. grammar:
  75. semantics:
  76. ohmLang: |
  77. LSys { Gen<x>
  78. = ReadRule+
  79. ReadRule
  80. = letters | symbols
  81. letters = "F" | "G"
  82. symbols = "-" | "+" }
  83. methods:
  84. initLang:
  85. body: |
  86. console.log("add operations to semantics")
  87. this.addOperationLang();
  88. addOperationLang:
  89. body: |
  90. this.semantics.addOperation('gen(x)', {
  91. Gen: function(e)
  92. {
  93. return e.gen(this.args.x);
  94. },
  95. ReadRule: function(e)
  96. {
  97. return e.gen(this.args.x);
  98. },
  99. letters: function(_)
  100. {
  101. for (var propName in this.args.x)
  102. {
  103. if (propName == this.sourceString)
  104. return this.args.x[propName]
  105. }
  106. return this.sourceString
  107. },
  108. symbols: function(_)
  109. {
  110. return this.sourceString;
  111. }
  112. });
  113. turtleLang:
  114. extends: http://vwf.example.com/ohm/node.vwf
  115. properties:
  116. grammar:
  117. semantics:
  118. ohmLang: |
  119. Turtle {
  120. Draw<x, y>
  121. = (drawLetter | turn)+
  122. drawLetter
  123. = letter
  124. turn
  125. = "+" | "-" }
  126. methods:
  127. initLang:
  128. body: |
  129. console.log("add operations to semantics")
  130. this.addOperationLang();
  131. addOperationLang:
  132. body: |
  133. var turtleID = this.parent.turtle.id;
  134. var self = this;
  135. this.semantics.addOperation('draw(x,y)', {
  136. Draw: function(e)
  137. {
  138. e.draw(this.args.x, this.args.y);
  139. },
  140. drawLetter: function(e)
  141. {
  142. //vwf_view.kernel.callMethod(turtleID, 'goForward', [this.args.x]);
  143. self.parent.turtle.goForward(this.args.x);
  144. },
  145. turn: function(e)
  146. {
  147. if (this.sourceString == "+")
  148. //vwf_view.kernel.callMethod(turtleID, 'turn', [this.args.y]);
  149. self.parent.turtle.turn(this.args.y);
  150. if (this.sourceString == "-")
  151. // vwf_view.kernel.callMethod(turtleID, 'turn', [-1 * this.args.y]);
  152. self.parent.turtle.turn(-1*this.args.y);
  153. }
  154. });
  155. groundPlane:
  156. extends: http://vwf.example.com/aframe/aplane.vwf
  157. properties:
  158. height: 50
  159. width: 50
  160. repeat: "10 10"
  161. rotation: [-90, 0, 0]
  162. wireframe: false
  163. src: "#bg2"
  164. turtleDraw:
  165. extends: http://vwf.example.com/aframe/aentity.vwf
  166. properties:
  167. position: [1, 1.25, -4]
  168. turtle:
  169. extends: http://vwf.example.com/aframe/asphere.vwf
  170. properties:
  171. position: [1, 1.25, -4]
  172. color: "#e0e014"
  173. radius: 1
  174. wireframe: true
  175. angleInRadians: 0
  176. methods:
  177. turn:
  178. parameters:
  179. - angle
  180. body: |
  181. var angle0 = this.angleInRadians;
  182. var targetAngle = angle * Math.PI / 180.0;
  183. this.angleInRadians = angle0 + targetAngle;
  184. goForward:
  185. parameters:
  186. - step
  187. body: |
  188. var x0 = this.position[0];
  189. var y0 = this.position[1];
  190. var xx = Math.sin(this.angleInRadians);
  191. var yy = Math.cos(this.angleInRadians);
  192. this.position = [x0 + step * xx, y0 + step * yy, this.position[2]];
  193. this.parent.makeMe('draw-' + this.random(), this.position);
  194. sky:
  195. extends: http://vwf.example.com/aframe/asky.vwf
  196. properties:
  197. color: "#ECECEC"
  198. camentity:
  199. extends: http://vwf.example.com/aframe/aentity.vwf
  200. properties:
  201. position: [0, 0, 0]
  202. children:
  203. camera:
  204. extends: http://vwf.example.com/aframe/acamera.vwf
  205. properties:
  206. look-controls-enabled: true
  207. forAvatar: true
  208. children:
  209. cursor:
  210. extends: http://vwf.example.com/aframe/acursor.vwf