A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
33
Task/Fractal-tree/JavaScript/fractal-tree.js
Normal file
33
Task/Fractal-tree/JavaScript/fractal-tree.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<html>
|
||||
<body>
|
||||
<canvas id="canvas" width="600" height="500"></canvas>
|
||||
<script type="text/javascript">
|
||||
var elem = document.getElementById('canvas');
|
||||
var context = elem.getContext('2d');
|
||||
|
||||
context.fillStyle = '#000';
|
||||
context.lineWidth = 1;
|
||||
|
||||
var deg_to_rad = Math.PI / 180.0;
|
||||
var depth = 9;
|
||||
|
||||
function drawLine(x1, y1, x2, y2, brightness){
|
||||
context.moveTo(x1, y1);
|
||||
context.lineTo(x2, y2);
|
||||
}
|
||||
function drawTree(x1, y1, angle, depth){
|
||||
if (depth != 0){
|
||||
var x2 = x1 + (Math.cos(angle * deg_to_rad) * depth * 10.0);
|
||||
var y2 = y1 + (Math.sin(angle * deg_to_rad) * depth * 10.0);
|
||||
drawLine(x1, y1, x2, y2, depth);
|
||||
drawTree(x2, y2, angle - 20, depth - 1);
|
||||
drawTree(x2, y2, angle + 20, depth - 1);
|
||||
}
|
||||
}
|
||||
context.beginPath();
|
||||
drawTree(300, 500, -90, depth);
|
||||
context.closePath();
|
||||
context.stroke();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue