%%HP: T(3)A(R)F(.);
DIR

MAND
@ Set up the custom menu for the mandelbrot set program
@ Check: # 54125d  Bytes: 293
\<<
	{ { "SAVE" {SAVE } }
	  { "LOAD" {LOAD } }
	  { "EDIT" { \<< 33 MENU PICT RCL \->LCD 3 FREEZE \>> } }
	  { "NEW" { \<< DEFAULTppar 'PPAR' STO 100 'nITTR' STO 33 MENU \>> } }
	  { "ITTER" { ITTER } }
	  { "QUIT" { \<< 0 MENU \>> } }
	} TMENU
\>>

SAVE
@ Saves a graphical image allong with it's plotting parameters
@ Check: # 58326d  Bytes: 77
\<<
	"Enter name to save as" "" INPUT
	OBJ\-> PICT RCL
	PPAR
	2 \->LIST
	SWAP STO
\>>

LOAD
@ Loads a graphical image into PICT and sets the current plotting parameters
@ Check: # 19949d  Bytes: 102.5
\<<
	"Enter Picture to load" "" INPUT OBJ\->
	OBJ\-> DROP
	'PPAR' STO
	DUP PICT STO \->LCD
	3 FREEZE
	33 MENU
\>>

ITTER
@ prompts for number of itterations
@ Check: # 13905d  Bytes: 77.5
\<<
	"Enter number of
itterations" "" INPUT OBJ\->
	'nITTR' STO
\>>

Q MANDGEN

MANDGEN
@ Generates a TRUE (1) or FALSE (0) for a single pixel based on the number
@ of itterations it took in the Z=Z^2+C calculation, and the dither pattern.
@ Check: # 19488d  Bytes: 132
\<<
	X Y R\->C
	nITTR ITR
	nITTR /
	IF DUP 1 == THEN
	  DROP 1
	ELSE
	  16 * 4 MOD IP X Y R\->C DITH?
	END
\>>

DEFAULTppar
@ Check # 54257d  Bytes: 90
{
	(-1.5,-1) (1.5,1)
	X 0 (100,100)
	TRUTH Y
}

PPAR
@ Check # 4776d  Bytes: 83
{
	(-1.5,-1) (1.5,1)
	X 0 (100,100)
	TRUTH Y
}

@ The current number of itterations
nITTR 50

DITH?
@ takes a color (from 0 to 4) and a point (in complex coords) from the stack
@ and returns a 1 or 0 if that pixel should be set.
@ Check: # 55653d  Bytes: 108
\<<
	C\->PX OBJ\-> DROP
	B\->R SWAP B\->R
	\-> c x y
	\<<
		PAT c 1 + GET
		y 2 MOD 1 + GET
		x 2 MOD 1 + GET
	\>>
\>>

PAT
@ 4x4 dither patterns
@ 00 10 10 11 11
@ 00 00 01 01 11
@ Check: # 26668d  Bytes: 137.5
{
	{ { 0 0 } { 0 0 } }
	{ { 1 0 } { 0 0 } }
	{ { 1 0 } { 0 1 } }
	{ { 1 1 } { 0 1 } }
	{ { 1 1 } { 1 1 } }
}

ITR
@ takes a complex point and the number of itterations and performs the
@ Z = Z^2 + C calculation
@ Check: # 15058d  Bytes 149.5
\<<
	0 \-> c itter i
	\<<
		c PIXON c PIXOFF
		(0,0)
		DO
		  DUP * c +
		  'i' INCR
		UNTIL itter > OVER C\->R * ABS 4 > OR END
		DROP
		i 1 -
	\>>
\>>

END
