index.vwf.yaml 8.9 KB

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