Yellowstone sequence: Difference between revisions

m
Line 666:
and displaying a chart of the first 100 terms:
 
<lang haskell>import qualified GraphicsCodec.SVGFonts.ReadFont as FPicture
import Data.Bifunctor (second)
import Diagrams.Backend.Rasterific
import Diagrams.Prelude
import Graphics.Rendering.Chart.Backend.Diagrams
import Graphics.Rendering.Chart.Easy
import qualified Graphics.SVGFonts.ReadFont as F
import Diagrams.Backend.Rasterific
import Diagrams.Prelude
import Codec.Picture
import Data.Bifunctor (second)
 
----------------- YELLOWSTONE PERMUTATION ------------------
yellowstone :: [Integer]
yellowstone =
yellowstone = 1 : 2 : (active <$> iterate nextWindow (2, 3, [4 ..]))
1 :
2 :
yellowstone = 1 : 2 : (active <$> iterate nextWindow (2, 3, [4 ..]))
where
nextWindow (p2, p1, rest) = (p1, n, residue)
where
[rp2, rp1] = relativelyPrime <$> [p2, p1]
go (x : xs)
| rp1 x && not (rp2 x) = (x, xs)
| otherwise = second ((:) x) (go xs)
Line 690 ⟶ 693:
relativelyPrime a b = 1 == gcd a b
 
---------- 30 FIRST TERMS, AND CHART OF FIRST 100 ----------
main :: IO (Image PixelRGBA8)
main = do
Line 697 ⟶ 700:
return $
chartRender env $
plot
plot (line "Yellowstone terms" [zip [1 ..] (take 100 yellowstone)])
( line
 
"Yellowstone terms"
plot (line "Yellowstone terms" [zip [1 ..] (take 100 yellowstone)])
)
 
--------------------- CHART GENERATION ---------------------
chartRender ::
:: (Default r, ToRenderable r) =>
=> DEnv Double -> EC r () -> Image PixelRGBA8
EC r () ->
Image PixelRGBA8
chartRender env ec =
renderDia
renderDia Rasterific (RasterificOptions (mkWidth (fst (envOutputSize env)))) $
Rasterific
fst $ runBackendR env (toRenderable (execEC ec))
( RasterificOptions
renderDia Rasterific (RasterificOptions (mkWidth (fst (envOutputSize env)))) $
)
$ fst $ runBackendR env (toRenderable (execEC ec))
 
------------------------ LOCAL FONT ------------------------
chartEnv :: IO (DEnv Double)
chartEnv = do
Line 714 ⟶ 726:
sansRB <- F.loadFont "SourceSansPro_RB.svg"
let fontChosen fs =
case ( _font_name fs, _font_slant fs, _font_weight fs) of
_font_slant fs,
("sans-serif", FontSlantNormal, FontWeightNormal) -> sansR
_font_weight fs
("sans-serif", FontSlantNormal, FontWeightBold) -> sansRB
) of
( "sans-serif",
("sans-serif", FontSlantNormal, FontWeightBold) -> sansRB
("sans-serif", FontSlantNormal, FontWeightNormal) -> sansR
) -> sansR
( "sans-serif",
FontSlantNormal,
FontWeightBold
) -> sansRB
return $ createEnv vectorAlignmentFns 640 400 fontChosen</lang>
{{Out}}
9,655

edits