aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport/Draw.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chelleport/Draw.hs')
-rw-r--r--src/Chelleport/Draw.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Chelleport/Draw.hs b/src/Chelleport/Draw.hs
index 4ee5b31..1c23ee0 100644
--- a/src/Chelleport/Draw.hs
+++ b/src/Chelleport/Draw.hs
@@ -2,6 +2,7 @@ module Chelleport.Draw where
import Chelleport.Types
import Data.Text (Text)
+import qualified Data.Vector.Storable as Vector
import Data.Word (Word8)
import Foreign.C (CInt)
import qualified SDL
@@ -34,6 +35,9 @@ colorAxisLines = colorAccent
colorBackground :: SDL.V4 Word8
colorBackground = SDL.V4 15 12 25 0
+colorFineGrainGrid :: SDL.V4 Word8
+colorFineGrainGrid = SDL.V4 55 52 65 100
+
drawText :: DrawContext -> SDL.V2 CInt -> SDL.V4 Word8 -> Text -> IO (CInt, CInt)
drawText ctx@(DrawContext {ctxRenderer = renderer}) position color text = do
surface <- TTF.blended (ctxFont ctx) color text
@@ -64,3 +68,14 @@ drawVerticalLine :: DrawContext -> CInt -> IO ()
drawVerticalLine ctx@(DrawContext {ctxRenderer = renderer}) x = do
(SDL.V2 _width height) <- windowSize ctx
SDL.drawLine renderer (SDL.P $ SDL.V2 x 0) (SDL.P $ SDL.V2 x height)
+
+drawCircle :: DrawContext -> Int -> (CInt, CInt) -> IO ()
+drawCircle (DrawContext {ctxRenderer = renderer}) radius (x, y) = do
+ let renderedPoints = radius * 7
+ let toTheta n = fromIntegral n * (2 * pi) / fromIntegral renderedPoints
+ let toPointOnCircle n =
+ SDL.V2
+ (x + round ((fromIntegral radius :: Float) * cos (toTheta n)))
+ (y + round ((fromIntegral radius :: Float) * sin (toTheta n)))
+ let points = Vector.generate renderedPoints (SDL.P . toPointOnCircle)
+ SDL.drawPoints renderer points