Add Rectangle object

This commit is contained in:
Kiana Sheibani 2022-11-30 15:52:47 -05:00
parent fb18cce4ec
commit f5edad4b66
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 27 additions and 1 deletions

View file

@ -13,6 +13,7 @@ public export
ColorAlpha : Type ColorAlpha : Type
ColorAlpha = Vect 4 Double ColorAlpha = Vect 4 Double
export export
withAlpha : Double -> Color -> ColorAlpha withAlpha : Double -> Color -> ColorAlpha
withAlpha a [r,g,b] = [r,g,b,a] withAlpha a [r,g,b] = [r,g,b,a]

View file

@ -5,6 +5,7 @@ import Render.Camera
import Render.Color import Render.Color
import public Render.Object.Interface import public Render.Object.Interface
import public Render.Object.Point import public Render.Object.Point
import public Render.Object.Rectangle
%default total %default total

View file

@ -3,7 +3,6 @@ module Render.Object.Point
import Data.Vect import Data.Vect
import Render.Color import Render.Color
import Render.Camera import Render.Camera
import Render.Picture
import Render.Object.Interface import Render.Object.Interface
%default total %default total

View file

@ -0,0 +1,25 @@
module Render.Object.Rectangle
import Data.Vect
import Render.Color
import Render.Camera
import Render.Object.Interface
%default total
public export
record Rectangle where
constructor MkRect
pos : (Double, Double)
width, height : Double
color : ColorAlpha
export
IsObject Rectangle where
draw (MkRect pos w h col) cam =
let (px,py) = pointToPix cam pos
pw = cast (w / cam.scenew * cast cam.pixw)
ph = cast (h / cam.sceneh * cast cam.pixh)
in (,,col) <$> [px..px+pw-1] <*> [py..py+ph-1]