console.log('Hello World') var boundsx,boundsy, mouse = { down: false, button:1, x:0, y:0, px:0,py:0 }; var ic = 0x1000000; var random_color = '#0'; function Params() { this.iterations= 2; this.theta= 18; this.thetaRandomness= 0; this.angle= 0; this.scale= 5; this.scaleRandomness= 0; this.constantWidth= true; this.deltarota =30; } function Colors() { this.background = "#000000"; this.general = "#111faa"; this.random= true; this.alpha= 0.8; } function Rules() { this.axiom = 'F'; this.mainRule = 'FF-[-F+F+F]+[+F-F-F]'; this.Rule2 = ''; } var rules = new Rules(); var params = new Params(); var colors = new Colors(); var clear = { clear: function(){ canvas.width = canvas.width; } }; window.addEventListener('mousemove', function (event) { mouse.x = event.clientX; mouse.y = event.clientY; }); window.onmousemove = function(e) { mouse.px = mouse.x; mouse.py = mouse.y; mouse.x = e.clientX - window.innerWidth/2; mouse.y = -(e.clientY - window.innerHeight/2); if (mouse.down) { } e.preventDefault(); }; window.onmousedown = function(e){ mouse.down = true; mouse.px = mouse.x; mouse.py = mouse.y; mouse.x = e.clientX - window.innerWidth/2; mouse.y = -(e.clientY - window.innerHeight/2); public_color = getRandomColor(); } window.onmouseup = function(e){ mouse.down = false; } window.onload = function(){ } function drawLine(x,y, x0,y0, color, width) { ctx.beginPath(); ctx.moveTo(x,y); ctx.lineTo(x0,y0); ctx.strokeStyle = color; if (params.constantWidth) ctx.lineWidth = 1; else ctx.lineWidth = width; ctx.stroke(); } function getRandomColor() { var r = ~~( 255 * Math.random()); var g = ~~( 255 * Math.random()); var b = ~~( 255 * Math.random() ); var a = colors.alpha; return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')'; } function GetAxiomTree() { var Waxiom = rules.axiom; var newf = rules.mainRule; var newb = 'bb'; var newx = rules.Rule2; var level = params.iterations; while (level > 0) { var m = Waxiom.length; var T = ''; for (var j=0; j < m; j++) { var a = Waxiom[j]; if (a == 'F') {T += newf;} else if (a == 'b') {T += newb;} else if (a == 'X') {T += newx;} else T += a; } Waxiom = T; level--; } return Waxiom; } function DrawTheTree(geom, x_init, y_init, z_init){ var geometry = geom; var Wrule = GetAxiomTree(); var n = Wrule.length; var stackX = []; var stackY = []; var stackZ = []; var stackA = []; var stackV = []; var stackAxis = []; var theta = params.theta * Math.PI / 180; var scale = params.scale; var angle = params.angle * Math.PI / 180; var x0 = x_init; var y0 = y_init; var z0 = z_init ; var x; var y; var z; var rota = 0, rota2 = 0, deltarota = 18 * Math.PI/180; var newbranch = false; var axis_x = new THREE.Vector3( 1, 0, 0 ); var axis_y = new THREE.Vector3( 0, 1, 0 ); var axis_z = new THREE.Vector3( 0, 0, 1 ); var zero = new THREE.Vector3( 0, 0, 0 ); var axis_delta = new THREE.Vector3(), prev_startpoint = new THREE.Vector3(); var startpoint = new THREE.Vector3(x0,y0,z0), endpoint = new THREE.Vector3(); var bush_mark; var vector_delta = new THREE.Vector3(scale, scale, 0); for (var j=0; j