From 8d11c64a80e4d45de6f84d012c2a0e5fe4fec0b2 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Sun, 7 Jul 2019 11:33:14 +0800 Subject: [PATCH] Clean up fourier_draw sligthly. Former-commit-id: 6143b4950db9145cf720c0f6c2d3c825d23ae9d0 --- examples/fourier_draw.hs | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/examples/fourier_draw.hs b/examples/fourier_draw.hs index 5b4eac5..b53ee93 100755 --- a/examples/fourier_draw.hs +++ b/examples/fourier_draw.hs @@ -1,10 +1,9 @@ #!/usr/bin/env stack --- stack --resolver lts-12.26 runghc --package reanimate +-- stack --resolver lts-13.14 runghc --package reanimate {-# LANGUAGE OverloadedStrings #-} module Main (main) where import Control.Lens -import Control.Monad import Data.Complex import qualified Data.Text as T @@ -14,11 +13,6 @@ import Reanimate.Driver (reanimate) import Reanimate.LaTeX import Reanimate.Monad import Reanimate.Svg -import Reanimate.Combinators - -waveMultiplier :: Int --- waveMultiplier = 1 -- Sawtooth wave -waveMultiplier = 2 -- Square wave main :: IO () main = reanimate $ pauseAtEnd 2 $ @@ -37,6 +31,7 @@ main = reanimate $ pauseAtEnd 2 $ fourierAnimation 25 40 `before` fourierAnimation 40 40 +sWidth :: Double sWidth = 0.5 applyMorph :: Int -> [Complex Double] -> Complex Double -> [Complex Double] @@ -69,7 +64,7 @@ piPoints = lineToPoints 500 $ findCoefficient :: Int -> Complex Double findCoefficient n = sum [ toComplex point * exp (negate (fromIntegral n) * 2 *pi * i*t) * deltaT - | (idx, point) <- zip [0..] piPoints, let t = fromIntegral idx/nPoints ] + | (idx, point) <- zip [0::Int ..] piPoints, let t = fromIntegral idx/nPoints ] where i = 0 :+ 1 toComplex (V2 x y) = x :+ y @@ -116,6 +111,7 @@ drawNCircles circles = do & circleRadius .~ Num radius mapF (translate x y) $ worker rest +mkCirclePath :: [Complex Double] -> [(Double, Double)] mkCirclePath circles = [ (x, y) | idx <- [0 .. granularity] @@ -124,14 +120,3 @@ mkCirclePath circles = ] where granularity = 500 - -fourierYValue n phi = - imagPart (sum [ nthCircle i phi | i <- [0..n-1]]) - -nthCircle :: Int -> Double -> Complex Double -nthCircle n phi = x :+ y - where - n' = fromIntegral (n*waveMultiplier+1) - x = cos (n'*phi) * radius - y = sin (n'*phi) * radius - radius = 40 * (2 / (n'*pi))