index.vwf.yaml 8.6 KB

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