Skip to content

Commit ab81267

Browse files
committed
Cabal init in the folder
1 parent d58a3c6 commit ab81267

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+623
-64
lines changed

AnimV1.gif

-2.14 MB
Binary file not shown.

AnimV2.gif

-3.76 MB
Binary file not shown.

ChangeLog.md

Lines changed: 5 additions & 0 deletions

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2019 RNG
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included
12+
in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 14 additions & 14 deletions

Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

frames/1.jpg

-1.11 KB
Binary file not shown.

frames/10.jpg

-39.9 KB
Binary file not shown.

frames/11.jpg

-35.8 KB
Binary file not shown.

frames/12.jpg

-42.8 KB
Binary file not shown.

frames/13.jpg

-49.2 KB
Binary file not shown.

frames/14.jpg

-55.9 KB
Binary file not shown.

frames/15.jpg

-57.4 KB
Binary file not shown.

frames/16.jpg

-50 KB
Binary file not shown.

frames/17.jpg

-38 KB
Binary file not shown.

frames/18.jpg

-32.3 KB
Binary file not shown.

frames/19.jpg

-26.9 KB
Binary file not shown.

frames/2.jpg

-2.07 KB
Binary file not shown.

frames/20.jpg

-22.2 KB
Binary file not shown.

frames/21.jpg

-23.1 KB
Binary file not shown.

frames/22.jpg

-21.9 KB
Binary file not shown.

frames/23.jpg

-21.7 KB
Binary file not shown.

frames/24.jpg

-21.3 KB
Binary file not shown.

frames/25.jpg

-22.4 KB
Binary file not shown.

frames/26.jpg

-25.7 KB
Binary file not shown.

frames/27.jpg

-29.8 KB
Binary file not shown.

frames/28.jpg

-34.1 KB
Binary file not shown.

frames/29.jpg

-39.4 KB
Binary file not shown.

frames/3.jpg

-6.47 KB
Binary file not shown.

frames/30.jpg

-44.5 KB
Binary file not shown.

frames/31.jpg

-48 KB
Binary file not shown.

frames/32.jpg

-48.9 KB
Binary file not shown.

frames/33.jpg

-48.6 KB
Binary file not shown.

frames/34.jpg

-48.1 KB
Binary file not shown.

frames/35.jpg

-45.7 KB
Binary file not shown.

frames/36.jpg

-44.1 KB
Binary file not shown.

frames/37.jpg

-42.2 KB
Binary file not shown.

frames/38.jpg

-40.1 KB
Binary file not shown.

frames/39.jpg

-36.9 KB
Binary file not shown.

frames/4.jpg

-9.17 KB
Binary file not shown.

frames/40.jpg

-35.4 KB
Binary file not shown.

frames/41.jpg

-35.7 KB
Binary file not shown.

frames/42.jpg

-36.9 KB
Binary file not shown.

frames/43.jpg

-38.3 KB
Binary file not shown.

frames/44.jpg

-39 KB
Binary file not shown.

frames/45.jpg

-37.4 KB
Binary file not shown.

frames/46.jpg

-35.4 KB
Binary file not shown.

frames/47.jpg

-35.4 KB
Binary file not shown.

frames/48.jpg

-34.6 KB
Binary file not shown.

frames/49.jpg

-33 KB
Binary file not shown.

frames/5.jpg

-16.1 KB
Binary file not shown.

frames/50.jpg

-29.6 KB
Binary file not shown.

frames/51.jpg

-28.7 KB
Binary file not shown.

frames/52.jpg

-29.8 KB
Binary file not shown.

frames/53.jpg

-31.5 KB
Binary file not shown.

frames/54.jpg

-33.8 KB
Binary file not shown.

frames/55.jpg

-35.9 KB
Binary file not shown.

frames/56.jpg

-38.2 KB
Binary file not shown.

frames/57.jpg

-40.7 KB
Binary file not shown.

frames/58.jpg

-42.5 KB
Binary file not shown.

frames/59.jpg

-43.4 KB
Binary file not shown.

frames/6.jpg

-23.8 KB
Binary file not shown.

frames/60.jpg

-45.1 KB
Binary file not shown.

frames/61.jpg

-47 KB
Binary file not shown.

frames/62.jpg

-48.6 KB
Binary file not shown.

frames/63.jpg

-49.6 KB
Binary file not shown.

frames/64.jpg

-50 KB
Binary file not shown.

frames/65.jpg

-51.2 KB
Binary file not shown.

frames/66.jpg

-51.6 KB
Binary file not shown.

frames/67.jpg

-53 KB
Binary file not shown.

frames/68.jpg

-53.4 KB
Binary file not shown.

frames/69.jpg

-54.4 KB
Binary file not shown.

frames/7.jpg

-21.1 KB
Binary file not shown.

frames/70.jpg

-55.2 KB
Binary file not shown.

frames/71.jpg

-56.4 KB
Binary file not shown.

frames/72.jpg

-57 KB
Binary file not shown.

frames/73.jpg

-57.6 KB
Binary file not shown.

frames/74.jpg

-58.4 KB
Binary file not shown.

frames/75.jpg

-59.5 KB
Binary file not shown.

frames/76.jpg

-61.2 KB
Binary file not shown.

frames/77.jpg

-63.3 KB
Binary file not shown.

frames/78.jpg

-64.8 KB
Binary file not shown.

frames/79.jpg

-66.4 KB
Binary file not shown.

frames/8.jpg

-28.8 KB
Binary file not shown.

frames/80.jpg

-67.2 KB
Binary file not shown.

frames/81.jpg

-67.6 KB
Binary file not shown.

frames/82.jpg

-67.9 KB
Binary file not shown.

frames/83.jpg

-68 KB
Binary file not shown.

frames/84.jpg

-67.8 KB
Binary file not shown.

frames/85.jpg

-67.6 KB
Binary file not shown.

frames/86.jpg

-66.9 KB
Binary file not shown.

frames/87.jpg

-67.3 KB
Binary file not shown.

frames/88.jpg

-67.7 KB
Binary file not shown.

frames/89.jpg

-68.7 KB
Binary file not shown.

frames/9.jpg

-39.8 KB
Binary file not shown.

frames/90.jpg

-68.8 KB
Binary file not shown.

frames/91.jpg

-68.9 KB
Binary file not shown.

frames/92.jpg

-69 KB
Binary file not shown.

frames/93.jpg

-69.5 KB
Binary file not shown.

frames/94.jpg

-69.9 KB
Binary file not shown.

frames/95.jpg

-70.4 KB
Binary file not shown.

frames/96.jpg

-70.7 KB
Binary file not shown.

frames/97.jpg

-70.3 KB
Binary file not shown.

frames/98.jpg

-69.4 KB
Binary file not shown.

frames/99.jpg

-68.8 KB
Binary file not shown.

haskell-av-mandelbrot.cabal

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
-- Initial haskell-av-mandelbrot.cabal generated by cabal init. For
2+
-- further documentation, see http://haskell.org/cabal/users-guide/
3+
4+
-- The name of the package.
5+
name: haskell-av-mandelbrot
6+
7+
-- The package version. See the Haskell package versioning policy (PVP)
8+
-- for standards guiding when and how versions should be incremented.
9+
-- https://wiki.haskell.org/Package_versioning_policy
10+
-- PVP summary: +-+------- breaking API changes
11+
-- | | +----- non-breaking API additions
12+
-- | | | +--- code changes with no API change
13+
version: 0.1.0.0
14+
15+
-- A short (one-line) description of the package.
16+
-- synopsis:
17+
18+
-- A longer description of the package.
19+
-- description:
20+
21+
-- URL for the project homepage or repository.
22+
homepage: https://github.com/gauravnv/haskell-av-mandelbrot
23+
24+
-- The license under which the package is released.
25+
license: MIT
26+
27+
-- The file containing the license text.
28+
license-file: LICENSE
29+
30+
-- The package author(s).
31+
author: RNG
32+
33+
-- An email address to which users can send suggestions, bug reports, and
34+
-- patches.
35+
-- maintainer:
36+
37+
-- A copyright notice.
38+
-- copyright:
39+
40+
category: Graphics
41+
42+
build-type: Simple
43+
44+
-- Extra files to be distributed with the package, such as examples or a
45+
-- README.
46+
extra-source-files: ChangeLog.md, README.md
47+
48+
-- Constraint on the version of Cabal needed to build this package.
49+
cabal-version: >=1.10
50+
51+
52+
executable haskell-av-mandelbrot
53+
-- .hs or .lhs file containing the Main module.
54+
main-is: Main.hs
55+
56+
-- Modules included in this executable, other than Main.
57+
-- other-modules:
58+
59+
-- LANGUAGE extensions used by modules in this package.
60+
-- other-extensions:
61+
62+
-- Other library packages from which modules are imported.
63+
build-depends: base >=4.9 && <4.10
64+
65+
-- Directories containing source files.
66+
hs-source-dirs: src
67+
68+
-- Base language which the package is written in.
69+
default-language: Haskell2010
70+

Base.hs renamed to src/Base.hs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
import Codec.Picture
2-
import Codec.Picture.Types
3-
import System.Environment
4-
-- import Codec.FFmpeg
5-
6-
main :: IO ()
7-
main = do
8-
putStrLn "Beginning rendering of image."
9-
makenframes 1 100
10-
11-
makenframes :: Int -> Int -> IO ()
12-
makenframes n end
13-
| n >= end = putStrLn "Completed all"
14-
| otherwise = do
15-
savePngImage ("frames\\"++(show n)++".jpg") (generateFractal n)
16-
putStrLn ("Completed"++(show n))
17-
makenframes (n+1) end
18-
offset :: (Float, Float)
19-
offset = (0.099, 0.89398)
20-
21-
zoomfactor :: Float
22-
zoomfactor = 0.03
23-
24-
width :: Int
25-
width = 400
26-
27-
height :: Int
28-
height = 300
29-
30-
generateFractal :: Int -> DynamicImage
31-
generateFractal n = ImageRGB8 $ (generateImage (mandelbrot n)) width height
32-
33-
iters :: Int -> Int
34-
iters n = 25 + n*n
35-
36-
palette :: Int -> [PixelRGB8]
37-
palette n = foldr (\a -> \b -> (PixelRGB8 (fromIntegral a*10) (fromIntegral a*5) (fromIntegral a*2)):b) [] [0..(iters n)]
38-
39-
mandelbrot :: Int -> Int -> Int -> PixelRGB8
40-
mandelbrot n x0 y0 = getColor 0 0 0 n
41-
where getColor :: Float -> Float -> Int -> Int -> PixelRGB8
42-
getColor x y i n = if x*x + y*y < 2*2 && i < (iters n)
43-
then getColor (x*x - y*y + (scaleX x0 n)) (2*x*y + (scaleY y0 n)) (i+1) n
44-
else (palette n)!!i
45-
46-
scaleX :: Int -> Int -> Float
47-
scaleX x n = (3.5/ (zoomfactor*(fromIntegral (n*n*n)))) * (fromIntegral x) / (fromIntegral width) - fst offset-- - zoomfactor * (fromIntegral n))
48-
49-
scaleY :: Int -> Int -> Float
50-
scaleY y n = (2/ (zoomfactor*(fromIntegral (n*n*n)))) * (fromIntegral y) / (fromIntegral height) - snd offset-- - zoomfactor * (fromIntegral n))
1+
import Codec.Picture
2+
import Codec.Picture.Types
3+
import System.Environment
4+
-- import Codec.FFmpeg
5+
6+
main :: IO ()
7+
main = do
8+
putStrLn "Beginning rendering of image."
9+
makenframes 1 100
10+
11+
makenframes :: Int -> Int -> IO ()
12+
makenframes n end
13+
| n >= end = putStrLn "Completed all"
14+
| otherwise = do
15+
savePngImage ("frames\\"++(show n)++".jpg") (generateFractal n)
16+
putStrLn ("Completed"++(show n))
17+
makenframes (n+1) end
18+
offset :: (Float, Float)
19+
offset = (0.099, 0.89398)
20+
21+
zoomfactor :: Float
22+
zoomfactor = 0.03
23+
24+
width :: Int
25+
width = 400
26+
27+
height :: Int
28+
height = 300
29+
30+
generateFractal :: Int -> DynamicImage
31+
generateFractal n = ImageRGB8 $ (generateImage (mandelbrot n)) width height
32+
33+
iters :: Int -> Int
34+
iters n = 25 + n*n
35+
36+
palette :: Int -> [PixelRGB8]
37+
palette n = foldr (\a -> \b -> (PixelRGB8 (fromIntegral a*10) (fromIntegral a*5) (fromIntegral a*2)):b) [] [0..(iters n)]
38+
39+
mandelbrot :: Int -> Int -> Int -> PixelRGB8
40+
mandelbrot n x0 y0 = getColor 0 0 0 n
41+
where getColor :: Float -> Float -> Int -> Int -> PixelRGB8
42+
getColor x y i n = if x*x + y*y < 2*2 && i < (iters n)
43+
then getColor (x*x - y*y + (scaleX x0 n)) (2*x*y + (scaleY y0 n)) (i+1) n
44+
else (palette n)!!i
45+
46+
scaleX :: Int -> Int -> Float
47+
scaleX x n = (3.5/ (zoomfactor*(fromIntegral (n*n*n)))) * (fromIntegral x) / (fromIntegral width) - fst offset-- - zoomfactor * (fromIntegral n))
48+
49+
scaleY :: Int -> Int -> Float
50+
scaleY y n = (2/ (zoomfactor*(fromIntegral (n*n*n)))) * (fromIntegral y) / (fromIntegral height) - snd offset-- - zoomfactor * (fromIntegral n))

src/fractal-0.0.1/Fractal.hs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import Data.Complex
2+
import Data.Maybe (listToMaybe, isNothing, maybe, catMaybes)
3+
import Control.Monad
4+
import Control.Applicative ((<$>))
5+
import System.Environment (getArgs)
6+
import System.Console.GetOpt
7+
import Control.Arrow ((***), second)
8+
9+
type Point = Complex Double
10+
type Image c = Point -> c
11+
type Fractal c = Int -> Image c -- | given an iteration count, generates an image
12+
13+
fractal :: (Point -> (a -> a)) -- | iterated function
14+
-> (a -> Maybe c) -- | convergence criterion
15+
-> (Point -> a) -- | iteration start
16+
-> Int -- | iteration limit
17+
-> Image (Maybe (Int, c))
18+
fractal f cc sf l p = listToMaybe . catMaybes . zipWith ((<$>) . (,)) [0..l] . map cc . iterate (f p) . sf $ p
19+
20+
newton :: (Point -> Point) -- | the function
21+
-> (Point -> Point) -- | its derivative
22+
-> Fractal (Maybe (Int, Point))
23+
newton f f' = fractal (const next)
24+
(\z -> if next z == z then Just z else Nothing)
25+
id
26+
where
27+
next z = z - f z/f' z
28+
29+
mandelbrot :: Fractal (Maybe (Int, ()))
30+
mandelbrot = fractal (\c z -> z*z + c)
31+
(\z -> if magnitude z > 2 then Just () else Nothing)
32+
(const 0)
33+
34+
julia :: Point -> Fractal (Maybe (Int, ()))
35+
julia p = fractal (\c z -> z*z + p)
36+
(\z -> if magnitude z > 2 then Just () else Nothing)
37+
id
38+
39+
convergence :: Image (Maybe (Int, a)) -> Image Int
40+
convergence = fmap (maybe 0 ((+1) . fst))
41+
42+
writePgm :: Image Int -> Point -> Point -> Double -> IO ()
43+
writePgm f ll ur scale =
44+
do
45+
putStrLn "P5"
46+
print width
47+
print height
48+
putStrLn "255"
49+
forM_ [0.. height-1] $ \i -> let y = fromIntegral i/scale in
50+
forM_ [0.. width-1] $ \j -> let x = fromIntegral j/scale in
51+
let z = (x :+ y) + ll in (putChar . toEnum . f $ z)
52+
where
53+
width = floor $ scale * realPart (ur-ll)
54+
height = floor $ scale * imagPart (ur-ll)
55+
56+
fractSpec :: FractSpec -> Fractal Int
57+
fractSpec Mandelbrot = convergence . mandelbrot
58+
fractSpec (Julia p) = convergence . julia p
59+
fractSpec (Newton roots) = convergence . newton f f'
60+
where
61+
f z = product $ map (z-) roots
62+
f' z = let factors = map (z-) roots
63+
in sum . map product . dropEach $ factors
64+
dropEach [] = []
65+
dropEach (x:xs) = xs:map (x:) (dropEach xs)
66+
67+
data FractSpec = Newton [Point] | Mandelbrot | Julia Point
68+
data Options = Options
69+
{ optScale :: Double
70+
, optBotLeft :: Complex Double
71+
, optTopRight :: Complex Double
72+
, optType :: FractSpec
73+
}
74+
75+
defaultOptions = Options
76+
{ optScale=100.0
77+
, optBotLeft=negate (1 :+ 1)
78+
, optTopRight=(1 :+ 1)
79+
, optType=Mandelbrot
80+
}
81+
82+
options :: [OptDescr (Options -> Options)]
83+
options = [ Option ['s'] ["scale"] (ReqArg (\x opt -> opt { optScale=read x } ) "SCALE")
84+
"scale 1 unit to SCALE pixels"
85+
, Option [] ["ll", "lower-left"] (ReqArg (\x opt -> opt { optBotLeft=readC x } ) "X,Y")
86+
"set lower left of viewport to X,Y"
87+
, Option [] ["ur", "upper-right"] (ReqArg (\x opt -> opt { optTopRight=readC x } ) "X,Y")
88+
"set upper right of viewport to X,Y"
89+
, Option ['m'] ["mandelbrot"] (NoArg (\opt -> opt { optType=Mandelbrot } ))
90+
"render the Mandelbrot set"
91+
, Option ['j'] ["julia"] (ReqArg (\x opt -> opt { optType=Julia (readC x) } ) "X,Y")
92+
"render the Julia set at X,Y"
93+
, Option ['n'] ["newton"] (ReqArg (\x opt -> opt { optType=Newton (readCs x) } ) "X1,Y1:X2,Y2:...")
94+
"render the Newton fractal for a polynomial with roots at X1,Y1, X2,Y2, ..."
95+
]
96+
where
97+
readC :: String -> Complex Double
98+
readC = uncurry (:+) . (read *** (read . tail)) . span (/= ',')
99+
readCs = map readC . split
100+
101+
split :: String -> [String]
102+
split [] = []
103+
split (':':xs) = split xs
104+
split xs = uncurry (:) . second split . span (/= ':') $ xs
105+
106+
getOpts :: [String] -> IO Options
107+
getOpts argv =
108+
case getOpt Permute options argv of
109+
(o,[],[] ) -> return $ foldl (flip ($)) defaultOptions o
110+
(_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))
111+
where header = "Usage: fractal [OPTION...]"
112+
113+
main = do
114+
opts <- getOpts =<< getArgs
115+
writePgm (fractSpec (optType opts) 254)
116+
(optBotLeft opts) (optTopRight opts)
117+
(optScale opts)

src/fractal-0.0.1/LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) Max Rabkin
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions
7+
are met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the author nor the names of his contributors
17+
may be used to endorse or promote products derived from this software
18+
without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
21+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
24+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
POSSIBILITY OF SUCH DAMAGE.

src/fractal-0.0.1/README

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
The fractal program generates Newton, Julia and Mandelbrot fractals. Output is
2+
to standard output in PGM (Portable Graymap) format. There is currently no
3+
support for colour. I suggest using a general-purpose image editor such as the
4+
GIMP to adjust brightness levels and add colour.
5+
6+
Fractal accepts the following options:
7+
8+
-s SCALE --scale=SCALE scale 1 unit to SCALE pixels
9+
--ll=X,Y, --lower-left=X,Y set lower left of viewport to X,Y
10+
--tr=X,Y, --upper-right=X,Y set upper right of viewport to X,Y
11+
-m --mandelbrot render the Mandelbrot set
12+
-j X,Y --julia=X,Y render the Julia set at X,Y
13+
-n X1,Y1:X2,Y2;... --newton=X1,Y1:X2,Y2;... render the Newton fractal for a polynomial with roots at X1,Y1, X2,Y2, ...
14+
15+
(Newton fractals for functions other than polynomials are supported by the
16+
underlying code, but there is currently no way to specify them on the command
17+
line.)

0 commit comments

Comments
 (0)