Files
loop/src/Picture/Text.hs
T

30 lines
1.1 KiB
Haskell

module Picture.Text where
import Geometry.Data
import Picture.Data
import Color
textGrad :: Color -> Color -> String -> Picture
{-# INLINE textGrad #-}
textGrad topc botc = map f . stringToListGrad topc botc
where
f (pos, col, V2 a b) = Verx pos col [a, b] minBound TextShad
-- no premature optimisation, consider changing to use texture arrays
stringToListGrad :: Color -> Color -> String -> [(Point3, Point4, Point2)]
{-# INLINE stringToListGrad #-}
stringToListGrad topc botc = concatMap (uncurry (charToTupleGrad topc botc)) . zip [0, 0.9 * dimText ..]
where
dimText = 100
charToTupleGrad :: Color -> Color -> Float -> Char -> [(Point3, Point4, Point2)]
{-# INLINE charToTupleGrad #-}
charToTupleGrad topc botc x c =
[ (V3 (x -50) (-100) 0, botc, V2 offset 1)
, (V3 (x -50) 100 0, topc, V2 offset 0)
, (V3 (x + 50) 100 0, topc, V2 (offset + 1) 0)
, (V3 (x -50) (-100) 0, botc, V2 offset 1)
, (V3 (x + 50) (-100) 0, botc, V2 (offset + 1) 1)
, (V3 (x + 50) 100 0, topc, V2 (offset + 1) 0)
]
where
offset = fromIntegral (fromEnum c) - 32