New better code
This commit is contained in:
parent
05a0c14d21
commit
703413c10f
1 changed files with 26 additions and 24 deletions
|
@ -17,7 +17,6 @@ a=27;b=79;c=C(-2.0,-1.0);d=C(1.0,1.0);e=C(-2.501,-1.003)
|
|||
newtype C = C (Double,Double) deriving (Show,Eq)
|
||||
instance Num C where C(x,y)*C(z,t)=C(z*x-y*t,y*z+x*t);C(x,y)+C(z,t)=C(x+z,y+t);abs(C(x,y))=C(sqrt(x*x+y*y),0.0)
|
||||
r(C(x,y))=x;i(C(x,y))=y
|
||||
f :: C -> C -> Int -> Int
|
||||
f c z 0=0;f c z n=if(r(abs(z))>2)then n else f c ((z*z)+c) (n-1)
|
||||
h j k = map (\z->(f (C z) (C(0,0)) 32,(fst z>l - q/2))) [(x,y)|y<-[p,(p+((o-p)/a))..o],x<-[m,(m + q)..l]] where o=i k;p=i j;m=r j;l=r k;q=(l-m)/b
|
||||
u j k = concat $ map v $ h j k where v (i,p)=(" .,`'°\":;-+oO0123456789=!%*§&$@#"!!i):rst p;rst True="\n";rst False=""
|
||||
|
@ -60,12 +59,12 @@ OO"-O0000000000Oo--oO0000000000O-:oO0000Oo::+++;;: ":"-++-';+oooOOoooo-::-oooo++
|
|||
Here is the more readable version. I believe with this far more readable version, no more explanation is needed.
|
||||
|
||||
<code class="zsh">
|
||||
-- Screen size
|
||||
nbvert = 27
|
||||
nbvert = 30
|
||||
nbhor = 79
|
||||
init_bottom_left = C (-2.0,-1.0)
|
||||
init_top_right = C (1.0,1.0)
|
||||
interrest = C (-2.5,-1.0)
|
||||
zoomfactor = 1.01
|
||||
init_bottom_left = C (-2.0,-2.0)
|
||||
init_top_right = C (3.0,2.0)
|
||||
interrest = C (-1.713,-0.000)
|
||||
|
||||
newtype Complex = C (Float,Float) deriving (Show,Eq)
|
||||
instance Num Complex where
|
||||
|
@ -80,17 +79,15 @@ real (C (x,y)) = x
|
|||
im :: Complex -> Float
|
||||
im (C (x,y)) = y
|
||||
|
||||
f :: Complex -> Complex -> Int -> Complex
|
||||
f c z 0 = z
|
||||
f c z n = f c ((z*z)+c) (n-1)
|
||||
|
||||
cabs :: Complex -> Float
|
||||
cabs = real.abs
|
||||
|
||||
tst :: Complex -> Bool
|
||||
tst c = (cabs (f c (C(0.0,0.0)) 32)) < 2
|
||||
f :: Complex -> Complex -> Int -> Int
|
||||
f c z 0 = 0
|
||||
f c z n = if (cabs z > 2) then n else f c ((z*z)+c) (n-1)
|
||||
|
||||
bmandel bottomleft topright = map (\z -> (tst (C z), (fst z > right - hstep/2 ))) [(x,y) | y <- [bottom,(bottom + vstep)..top], x<-[left,(left + hstep)..right]]
|
||||
|
||||
bmandel bottomleft topright = map (\z -> (f (C z) (C(0,0)) 32, (fst z > right - hstep/2 ))) [(x,y) | y <- [bottom,(bottom + vstep)..top], x<-[left,(left + hstep)..right]]
|
||||
where
|
||||
top = im topright
|
||||
bottom = im bottomleft
|
||||
|
@ -99,23 +96,28 @@ bmandel bottomleft topright = map (\z -> (tst (C z), (fst z > right - hstep/2 ))
|
|||
vstep=(top-bottom)/nbvert
|
||||
hstep=(right-left)/nbhor
|
||||
|
||||
mandel :: Complex -> Complex -> String
|
||||
mandel bottomleft topright = concat $ map treat $ bmandel bottomleft topright
|
||||
mandel :: (Complex,Complex) -> String
|
||||
mandel (bottomleft,topright) = concat $ map treat $ bmandel bottomleft topright
|
||||
where
|
||||
treat (True,jump) = " " ++ rst jump
|
||||
treat (False,jump) = "@" ++ rst jump
|
||||
treat (i,jump) = " .,:;rcuowijlbCUOW&$@#" !! (div (i*22) 32):rst jump
|
||||
rst True = "\n"
|
||||
rst False = ""
|
||||
|
||||
cdiv :: Complex -> Float -> Complex
|
||||
cdiv (C(x,y)) r = C(x/r, y/r)
|
||||
cmul :: Complex -> Float -> Complex
|
||||
cmul (C(x,y)) r = C(x*r, y*r)
|
||||
|
||||
zoom :: Complex -> Complex -> Complex -> Float -> (Complex,Complex)
|
||||
zoom bl tr center magn = (f bl, f tr)
|
||||
where
|
||||
f point = ((center `cmul` magn) + point ) `cdiv` (magn + 1)
|
||||
|
||||
|
||||
main = do
|
||||
x <- getContents
|
||||
putStrLn $ infinitemandel 0
|
||||
where
|
||||
closer n (C (x,y)) =
|
||||
let cst = (1.1**n - 1) in
|
||||
C ( (x + cst*(real interrest))/cst+1,
|
||||
(y + cst*(im interrest))/cst+1 )
|
||||
bottomleftn n = closer n init_bottom_left
|
||||
toprightn n = closer n init_top_right
|
||||
infinitemandel n = mandel (bottomleftn n) (toprightn n) ++ "\x1b[H\x1b[25A" ++ infinitemandel (n+1)
|
||||
window n = zoom init_bottom_left init_top_right interrest (zoomfactor**n)
|
||||
infinitemandel n = mandel (window n) ++ "\x1b[H\x1b[25A" ++ infinitemandel (n+1)
|
||||
</code>
|
||||
|
|
Loading…
Reference in a new issue