Skip to content

Instantly share code, notes, and snippets.

@cartazio
Created January 22, 2012 03:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cartazio/1655252 to your computer and use it in GitHub Desktop.
Save cartazio/1655252 to your computer and use it in GitHub Desktop.
gtk haskell chart
import Graphics.Rendering.Chart
import Graphics.Rendering.Chart.Gtk
import Data.Colour.Names
import Data.Colour
import Data.Accessor
chart = layout
where
am :: Double -> Double
am x = (sin (x*3.14159/45) + 1) / 2 * (sin (x*3.14159/5))
sinusoid1 = plot_lines_values ^= [[ (x,(am x)) | x <- [0,(0.5)..400]]]
$ plot_lines_style .> line_color ^= opaque blue
$ plot_lines_title ^= "am"
$ defaultPlotLines
sinusoid2 = plot_points_style ^= filledCircles 2 (opaque red)
$ plot_points_values ^= [ (x,(am x)) | x <- [0,7..400]]
$ plot_points_title ^= "am points"
$ defaultPlotPoints
layout = layout1_title ^= "Amplitude Modulation"
$ layout1_plots ^= [Left (toPlot sinusoid1),
Left (toPlot sinusoid2)]
$ defaultLayout1
main = do
renderableToWindow (toRenderable chart) 640 480
-- renderableToPDFFile (toRenderable chart) 640 480 "test.pdf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment