Created
December 17, 2019 08:53
-
-
Save lispandfound/1677ecf18c8e2c55b92b43bd892e1862 to your computer and use it in GitHub Desktop.
Ulam Spiral Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Lib | |
where | |
import Graphics.Gloss | |
density :: Float | |
density = 0.1 | |
spiral :: [Float] -> [(Float, Float)] | |
spiral pts = map f pts | |
where f t = (density * t * cos t, density * t * sin t) | |
primeSieve :: [Integer] -> [Integer] | |
primeSieve (x:xs) = x : (primeSieve $ filter (\y -> y `mod` x /= 0) xs) | |
primeSieve [] = [] | |
primes :: [Integer] | |
primes = primeSieve [2..] | |
ulamSpiral :: [(Float, Float)] | |
ulamSpiral = spiral . map fromIntegral $ primes | |
pointRadius :: Float | |
pointRadius = 10 | |
ulamPoint :: (Float, Float) -> Picture | |
ulamPoint (x, y) = translate x y $ circleSolid pointRadius | |
ulamPoints :: [Picture] | |
ulamPoints = map ulamPoint ulamSpiral | |
window :: Display | |
window = InWindow "Ulam Spiral" (200, 200) (0, 0) | |
someFunc :: IO () | |
someFunc = display window white (pictures . take 1000 $ ulamPoints) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment