figures for all

For the Compleat Fan
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

figures for all

Post by newdep »

Just for the fun I created a program that prints itself as a triangle..
(http://www.nodep.nl/downloads/newlisp/triangle.lsp)

But would be nice to see some other figures around here ;-)

Regards, Norman.
-- (define? (Cornflakes))

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

I like it!

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

This diagram is a bit lossy, so you might not be able to reconstruct the source from it...

(and choose a small font)

Code: Select all

(set 'display-size '(250 250))

(setq B (clean (lambda (x) (find x '( "\n" "\r" "\t" ))) 
	(explode (read-file (main-args 1)))))

(set 'screen (array (first display-size) (last display-size) '(" ")))

(define (draw-screen)
	(dotimes (r (first display-size))
		(dotimes (c (last display-size))
			(print (screen r c)))
		(println)))

(define (squeeze-in n low high) 
	(and 
		(max n low)
		(min n high)))

(define (draw-point x y (c "X"))
	(nth-set 
		(squeeze-in x 0 (- (first display-size) 1))
		(squeeze-in y 0 (- (last display-size) 1)) screen c))

(set 'PI 3.1415 'r 100 'c 0 'step 0.15)

(for (i 0.5 (mul 200 PI) step (> c (length B)))
	(set 'r (mul 1.1 i))
	(dec 'step 0.05)
	(draw-point 
		(int (add (/ (first display-size) 2) (mul r (cos i)))) 
		(int (add (/ (last display-size) 2) (mul r (sin i))))
		(nth (inc 'c) B )))

(draw-screen)
(exit)

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

aaah a spiral ! nice work! ;-)
-- (define? (Cornflakes))

Sleeper
Posts: 24
Joined: Fri Nov 24, 2006 2:24 pm

Post by Sleeper »

great, i like it!

Code: Select all

; circle.lsp --
;    prints itself in a circle

(set 'cc (find-all "[^\t\n\r]" (read-file (main-args 1))))
(set 'w (int (sqrt (div (length cc) 1.7 0.25))))
(set 'h (int (div w 1.5)))
(set 'g (dup (dup " " w true) h true))
(set 'r (div w 2.2))

(for (i 1 h) (for (j 1 w)
    (if (> (length cc) 0) (begin
       (set 'y (mul (sub (div h 2) i) 1.5))
       (set 'x (sub (div w 2) j))
       (if (< (sqrt (add (* x x) (* y y))) r)
       (nth-set (g i j) (pop cc)
   ))))))
       
(dolist (x g) (println (join x)))

(exit)
a quite ugly circle :p

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

nice nice a Circle .. the figures get complete ;-)
-- (define? (Cornflakes))

Locked