Commits

Slava Bacherikov committed 34115ea

Add wind ability

Comments (0)

Files changed (1)

lesson1/index.html

 </head>
 <body>
     <div class="main">
-        <canvas width="600" height="400" id="tree">
+        <canvas width="600" height="450" id="tree">
             Ваш браузер не поддерживает canvas.
         </canvas>
         <script type="text/javascript">
-            function draw_pythagoras_tree_strandard_r(ctx, first_size){
+            function draw_pythagoras_tree_strandard_r(ctx, first_size, base_angle){
                 var height = ctx.canvas.height,
                     width = ctx.canvas.width,
-                    base_angle = Math.PI/4,
-                    k = 1/Math.sqrt(2); // Math.sqrt(2)/2 or Math.sin(Math.PI/4)
+                    second_angle = Math.PI/2 - base_angle,
+                    k1 = Math.sin(base_angle),
+                    k2 = Math.cos(base_angle); // Math.sqrt(2)/2 or Math.sin(Math.PI/4)
 
                 function draw_r(x, y, size, angle, num){
                     ctx.save();
                     ctx.translate(x,y);
                     ctx.rect(0,0, size, size);
                     if(num >= 1){
-                        var newsize = k*size;
-                        draw_r(0, -newsize, newsize, -base_angle, num-1);
-                        draw_r(0, -newsize*2, newsize, base_angle, num-1);
+                        var newsize1 = k1*size,
+                            newsize2 = k2*size;
+                        draw_r(0, -newsize2, newsize2, -base_angle, num-1);
+                        draw_r(0, -newsize2-newsize1, newsize1, second_angle, num-1);
                     }
                     ctx.restore();
                 }
             var canvas = document.getElementById('tree');
             if (canvas.getContext){
                 var ctx = canvas.getContext('2d');
-                draw_pythagoras_tree_strandard_r(ctx, 100);
+                draw_pythagoras_tree_strandard_r(ctx, 100, Math.PI/6);
             } else {
                 alert("Похоже в вашем браузере Canvas не поддерживается");
             }