?

Log in

No account? Create an account

yrk

Previous Entry Share Next Entry
11:44 pm: Circle squared

circle^2
It is time for another mathhack: This time ASCII art generated from the formula for the graph of a circle, x^2+y^2. This algorithm is due to to John E. Connet of the University of Minnesota. In order to actually see what is going on, you should turn the font size in your terminal way down. Start by playing around with different values for SIDE (0 to 100), then run (CONNET-DRIVER :SEC 0.3), sit back and enjoy.

(defun connet (side)
  (let ((monitor (make-array '(100 100) :initial-element nil)))
    (loop for i from 0 below 100 do
	 (loop for j from 0 below 100 do
	      (let* ((x (* side (/ i 100)))
		     (y (* side (/ j 100)))
		     (c (round (+ (* x x) (* y y)))))
		(when (evenp c) (setf (aref monitor i j) t)))))
    (loop for x from 0 below 100 do
	 (format t "~%")
	 (loop for y from 0 below 100 do
	      (format t "~A" (if (aref monitor x y) "*" " "))))
    (format t "~%")))

(defun connet-driver (&key (sec 0))
  (loop for side from 1 below 100 do
       (sleep sec)
       (connet side)))




Powered by LiveJournal.com