Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,37 @@
;; (require :lispbuilder-sdl)
(defun deg-to-radian (deg)
"converts degrees to radians"
(* deg pi 1/180))
(defun cos-deg (angle)
"returns cosin of the angle expressed in degress"
(cos (deg-to-radian angle)))
(defun sin-deg (angle)
"returns sin of the angle expressed in degress"
(sin (deg-to-radian angle)))
(defun draw-tree (surface x y angle depth)
"draws a branch of the tree on the sdl-surface"
(when (plusp depth)
(let ((x2 (+ x (round (* depth 10 (cos-deg angle)))))
(y2 (+ y (round (* depth 10 (sin-deg angle))))))
(sdl:draw-line-* x y x2 y2 :surface surface :color sdl:*green*)
(draw-tree surface x2 y2 (- angle 20) (1- depth))
(draw-tree surface x2 y2 (+ angle 20) (1- depth)))))
(defun fractal-tree (depth)
"shows a window with a fractal tree"
(sdl:with-init ()
(sdl:window 800 600 :title-caption "fractal-tree")
(sdl:clear-display sdl:*black*)
(draw-tree sdl:*default-surface* 400 500 -90 depth)
(sdl:update-display)
(sdl:with-events ()
(:video-expose-event ()
(sdl:update-display))
(:quit-event ()
t))))
(fractal-tree 9)

View file

@ -1,33 +1,37 @@
<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;
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);
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);
}
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>