#!/usr/bin/newlisp

;;; This program requires v.10.2.0 (or later) of newLISP and
;;; will not run on the original FOOP as introduced in 10.0

(print "Content-Type: text/html\r\n\r\n")

(println [text]
<html>
<FONT FACE ="Helvetica, Arial, sans-serif">
<A HREF="http://newlisp.org">Home</A>&nbsp;|
<A HREF="http:syntax.cgi?complex.txt">Source</A>
</FONT>
<CENTER>
[/text])

(set ' colors '(
  "800000" "800080" "8000FF" "808000" "808080" "8080FF" "80FF00" "80FF80" 
  "80FFFF" "FF0000" "FF0080" "FF00FF" "FF8000" "FF8080" "FF80FF" "FFFF00"))

;; adapted from a program witten by Michael Michaels and Cormullion
;; this is a FOOP (Functional Object Oriented Programming) application

; (define (Class:Class) (cons (context) (args))) ; predefined since version 10.0

(new Class 'Complex)

(define (Complex:rad)
	(sqrt (add (pow (self 1) ) (pow (self 2))))
)

(define (Complex:add b) 
	(Complex (add (self 1) (b 1)) (add (self 2) (b 2)))
) 

(define (Complex:mul b) 
	(let (a-re (self 1) a-im (self 2) b-re (b 1) b-im (b 2))
		(Complex 
			(sub (mul a-re b-re) (mul a-im b-im)) 
			(add (mul a-re b-im) (mul a-im b-re)) )
))
 
(define (draw) 
	(print "<table bgcolor=#f0f0f0>\n")
	(for (y -1 1.1 0.08) 
		(for (x -2 1 0.04) 
			(set 'z (Complex x y) 'c 85 'a z ) 
			(while (and (< (abs (:rad (set 'z (:add (:mul z z) a)))) 2) (> (dec c) 32)) )
			(if (= c 32)
				(print "<td bgcolor=#000000>&nbsp;</td>")
				(print "<td bgcolor=#" (colors (% c  16)) ">&nbsp;</td>"))
		) 
		(println "</tr>") )
	(println "</table>")
)

(draw) 

(print " </CENTER> <br><center><h4>created by newLISP v." (sys-info -2) "</h4></center></html>")

;; eof


syntax highlighting with newLISP and syntax.cgi