The Lambda Lab
/
projects
/
forth.jl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reimplemented EXPECT. Closes #1.
[forth.jl.git]
/
examples
/
mandelbrot.4th
diff --git
a/examples/mandelbrot.4th
b/examples/mandelbrot.4th
index
5707acb
..
9759a39
100644
(file)
--- a/
examples/mandelbrot.4th
+++ b/
examples/mandelbrot.4th
@@
-1,7
+1,7
@@
( --- Complex arithmetic --- )
( Location of floating point. )
( --- Complex arithmetic --- )
( Location of floating point. )
-: precision 10000 ;
+10000 value precision
: sign dup abs / ;
: sign dup abs / ;
@@
-32,28
+32,33
@@
: csq 2dup c* ;
: csq 2dup c* ;
+
+: conj ( x y -- x -y )
+ negate
+;
+
: cmagsq ( x1 y1 -- mag )
: cmagsq ( x1 y1 -- mag )
- csq abs
+ 2dup conj c* +
;
( --- Mandelbrot set calculations --- )
: iterate ( cr ci zr zi -- cr ci z'r z'i )
;
( --- Mandelbrot set calculations --- )
: iterate ( cr ci zr zi -- cr ci z'r z'i )
- csq c+
+
2over 2swap
csq c+
;
;
-: inSet? ( cr ci -- res )
- DEBUGON
+100 value maxiter
+: inSet? ( cr ci -- res )
0 0 ( z_0 = 0 )
true ( flag indicating set membership )
0 0 ( z_0 = 0 )
true ( flag indicating set membership )
-
100
0 do
+
maxiter
0 do
drop
iterate
2dup cmagsq
drop
iterate
2dup cmagsq
- 4 >scaled > if
+ 4
0
>scaled > if
false ( not in set )
leave
then
false ( not in set )
leave
then
@@
-65,21
+70,42
@@
-rot 2drop -rot 2drop
;
-rot 2drop -rot 2drop
;
-: xsteps 100 ;
-: ysteps 50 ;
+100 value xsteps
+30 value ysteps
( Draw the Mandelbrot Set!)
( Draw the Mandelbrot Set!)
-: mandel ( x1 y1 x2 y2 -- )
-
- 1 pick 4 pick -
- 2 pick 5 pick do
- i 0 inSet? if
- 42 emit
- else
- '.' emit
- then
+: mandeldraw ( x1 y1 x2 y2 -- )
+
+ cr
+
+ 0 pick 3 pick - ysteps /
+ 1 pick 4 pick do
+
+ 2 pick 5 pick - xsteps /
+ 3 pick 6 pick do
+
+ i j inSet? if
+ 42 emit
+ else
+ space
+ then
+
+ dup +loop
+ drop
+
+ cr
+
dup +loop
dup +loop
+ drop
;
( Clean up - hide non-standard multiplication def. )
hide *
;
( Clean up - hide non-standard multiplication def. )
hide *
+
+( Default picture )
+: mandel
+ -2 0 >scaled -1 0 >scaled 0 5 >scaled 1 0 >scaled
+ mandeldraw
+;
+
+CR .( Enter 'mandel' to draw the Mandelbrot Set.)