summaryrefslogtreecommitdiff
authorplurSKI <black.gavin@gmail.com>2010-11-20 15:42:29 (GMT)
committer plurSKI <black.gavin@gmail.com>2010-11-20 15:42:29 (GMT)
commitc3f60a5c18401f9affde2871fce3f81b8361865c (patch)
tree7b40456ae722a057c7ec3eeb6a9f1189d3be1092
parent008b9b811b0542813afd22d888a32c631cbff5af (diff)
downloadsingularityViewer-master.zip
singularityViewer-master.tar.gz
Cleaned up code, added readme and movieScriptmaster
-rw-r--r--README15
-rw-r--r--Singularity.hs40
-rwxr-xr-xdata/movieScript2
3 files changed, 34 insertions, 23 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..59bfb33
--- a/dev/null
+++ b/README
@@ -0,0 +1,15 @@
+Author: Gavin Black
+Description: Plots a given complex function as it approaches 0
+License: BSD
+Dependencies: ffmpeg, GD, Haskell Platform
+
+To use:
+ Open Singularity.hs and change the following constants as desired
+ -- imgSize: The square size of the resulting pngs
+ -- eqn z: The equation to model, z is the complex variable
+ -- radiusStep: How much the radius should change each step = 0.001
+ -- radiusMin: The smallest radius
+ -- radiusMax: The largest radius
+ -- targetPts: The number of points to check for each image (larger is slower)
+ Run: cabal install && ~/.cabal/bin/singularityViewer
+ When Finished: cd data && ./movieScript
diff --git a/Singularity.hs b/Singularity.hs
index 0a483ba..b2aeb59 100644
--- a/Singularity.hs
+++ b/Singularity.hs
@@ -5,13 +5,15 @@ import Complex
type RgbColor = (Int, Int, Int)
type ColorPoint = (Int, Int, RgbColor)
-imgSize = 1000
-eqn z = exp ( 1 / z )-- 1 / (z ^ 6 + z ^ 5 + z ^ 3 + z^2) -- exp ( 1 / z )
-radiusStep = 0.002
-radiusMin = 0.001
+-- Constants to change (Described in README)
+imgSize = 1000
+eqn z = exp(1/z)
+radiusStep = 0.001
+radiusMin = 0.0001
+radiusMax = 0.75
+targetPts = 2000000
circumf = 2*pi
-targetPts = 2000000
halfSize = imgSize `div` 2
convertPolar :: Double -> (Double, Double) -> ColorPoint
@@ -21,8 +23,10 @@ convertPolar radius (x, y) = (x' , y' , (red',green',blue'))
red' = floor (255 * red)
green' = floor (255 * green)
blue' = floor (255 * blue)
- (red,green,blue) = hsv2rgb $ calcColor radius (y, x)
- expand = 100 / radius
+ (red,green,blue) = hsv2rgb (h, s, 1)
+ expand = 100 / radius -- Spread pixels out more, away from the center
+ h = (y / circumf) * 360
+ s = x / radius
cartesianPointsWithRGB :: Double -> [ColorPoint]
cartesianPointsWithRGB radius = filter isInRange $ map (convertPolar radius) points
@@ -35,18 +39,9 @@ cartesianPointsWithRGB radius = filter isInRange $ map (convertPolar radius) poi
linePoints = [0,resolution..radius]
resolution = sqrt $ circumf * radius / targetPts
-calcColor radius (a,r) = (h, s, 1)
- where h = (a / circumf) * 360
- s = r / radius
-
--- Converts hsv2 rgb
+-- Converts hsv2rgb
-- Takes in values (0-360, 0-1, 0-1)
-- returns (0-1, 0-1, 0-1)
-mod1 x | pf < 0 = pf+1
- | otherwise = pf
- where
- (_,pf) = properFraction x
-
hsv2rgb :: (RealFrac a, Ord a) => (a,a,a) -> (a,a,a)
hsv2rgb (h,s,v) = case hi of
0 -> (v,t,p)
@@ -61,16 +56,15 @@ hsv2rgb (h,s,v) = case hi of
p = v*(1-s)
q = v*(1-f*s)
t = v*(1-(1-f)*s)
-
-makePixel :: Image -> ColorPoint -> IO ()
-makePixel img (x,y, (r,g,b)) = do
- setPixel ( halfSize + x, halfSize + y) (rgb r g b) img
+ mod1 x | pf x < 0 = pf x +1
+ | otherwise = pf x
+ pf = snd . properFraction
makeImg (radius, num) = do
img <- newImage (imgSize, imgSize)
mapM_ (makePixel img) $ cartesianPointsWithRGB radius
savePngFile ("data/test" ++ show num ++ ".png") img
+ where makePixel img (x,y, (r,g,b)) = setPixel ( halfSize + x, halfSize + y) (rgb r g b) img
--- Radius of the circles to use
-rArray = reverse [radiusMin,radiusMin + radiusStep..1]
main = mapM_ makeImg $ zip rArray [1..length rArray]
+ where rArray = reverse [radiusMin,radiusMin + radiusStep..radiusMax]
diff --git a/data/movieScript b/data/movieScript
new file mode 100755
index 0000000..c2c8da4
--- a/dev/null
+++ b/data/movieScript
@@ -0,0 +1,2 @@
+ffmpeg -y -i test%1d.png -b 9800000 test$1.mpg
+mplayer test$1.mpg