Bitmap/Midpoint circle algorithm: Difference between revisions

Content added Content deleted
m (→‎{{header|Tcl}}: link to tk library)
(CL code)
Line 201: Line 201:
}
}
#undef plot</lang>
#undef plot</lang>

=={{header|Common Lisp}}==

Based upon the OCaml version.

<pre>(defun draw-circle (draw-function x0 y0 radius)
(labels ((foo (x y)
(funcall draw-function x y))
(put (x y m)
(let ((x+ (+ x0 x))
(x- (- x0 x))
(y+ (+ y0 y))
(y- (- y0 y))
(x0y+ (+ x0 y))
(x0y- (- x0 y))
(xy0+ (+ y0 x))
(xy0- (- y0 x)))
(foo x+ y+)
(foo x+ y-)
(foo x- y+)
(foo x- y-)
(foo x0y+ xy0+)
(foo x0y+ xy0-)
(foo x0y- xy0+)
(foo x0y- xy0-)
(multiple-value-bind (y m) (if (plusp m)
(values (1- y) (- m (* 8 y)))
(values y m))
(when (<= x y)
(put (1+ x)
y
(+ m 4 (* 8 x))))))))
(put 0 radius (- 5 (* 4 radius)))
(values)))</pre>
<pre>CL-USER> (let ((buffer (make-array '(30 30)
:element-type 'bit)))
(draw-circle (lambda (x y)
(setf (bit buffer x y) 1)) 15 15 10)
buffer)
;; edited for your convenience
(( )
( 1 1 1 1 1 1 1 )
( 1 1 1 1 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 )
( 1 1 1 1 1 1 )
( 1 1 1 1 1 1 1 )
( ))
</pre>


=={{header|Forth}}==
=={{header|Forth}}==