forked from sheaf/Polynomial-roots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plotting.hs
43 lines (34 loc) · 1.51 KB
/
Plotting.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
module Plotting where
import Overture
import Prelude ()
import qualified Data.Colour.RGBSpace as RGB
import qualified Data.Colour.RGBSpace.HSV as HSV
import Control.Applicative
import Data.Complex
import Data.Monoid
import Data.Word
import Rendering.Gradient
import Types
import Interval
import Rendering.Colour
data RootPlot a = RootPlot (Polynomial a) Root
newtype IFSPlot a = IFSPlot (Complex Double)
type PixelOrig = Integer
type PlotData = (Pixel, PixelOrig)
instance Show (RootPlot a) where show (RootPlot _ x) = show x
toCoords roots (rx,ry) c w = map((\z->(floor(realPart z),ry-floor(imagPart z)))
.(\z -> (rx'/w :+ 0) * (z-p)))
$ filter (\z -> elemI z (p,p')) roots
where [rx',ry'] = map fromIntegral [rx,ry]
h = w * ry'/rx'
p = c - ( w/2 :+ h/2)
p'= c + ( w/2 :+ h/2)
--Density colouring.
density :: p -> r -> Sum Double
density _ _ = Sum 0.001 -- this should be a parameter!
--Colouring by source polynomial, "base n" and "scale factor" methods.
source1, source2 :: (Coefficient a) => IterCoeffs a -> Polynomial a -> Complex Double -> SourceSum
source1 cfs p _ = Source $ (\(a,b,c) -> (a,b,c,1)) $ toRGB $ hsv (toGValue1 cfs p) 1 1
source2 cfs p r = Source $ (\(a,b,c) -> (a,b,c,1)) $ toRGB $ hsv (toGValue2 cfs p r) 1 1