From f5edad4b66a69eda9a72c57e84ed7106a5ee7731 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 30 Nov 2022 15:52:47 -0500 Subject: [PATCH] Add Rectangle object --- src/Render/Color.idr | 1 + src/Render/Object.idr | 1 + src/Render/Object/Point.idr | 1 - src/Render/Object/Rectangle.idr | 25 +++++++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/Render/Object/Rectangle.idr diff --git a/src/Render/Color.idr b/src/Render/Color.idr index 030a3d3..ad62b74 100644 --- a/src/Render/Color.idr +++ b/src/Render/Color.idr @@ -13,6 +13,7 @@ public export ColorAlpha : Type ColorAlpha = Vect 4 Double + export withAlpha : Double -> Color -> ColorAlpha withAlpha a [r,g,b] = [r,g,b,a] diff --git a/src/Render/Object.idr b/src/Render/Object.idr index be6ccc5..bef533e 100644 --- a/src/Render/Object.idr +++ b/src/Render/Object.idr @@ -5,6 +5,7 @@ import Render.Camera import Render.Color import public Render.Object.Interface import public Render.Object.Point +import public Render.Object.Rectangle %default total diff --git a/src/Render/Object/Point.idr b/src/Render/Object/Point.idr index 70bab8b..fa3a548 100644 --- a/src/Render/Object/Point.idr +++ b/src/Render/Object/Point.idr @@ -3,7 +3,6 @@ module Render.Object.Point import Data.Vect import Render.Color import Render.Camera -import Render.Picture import Render.Object.Interface %default total diff --git a/src/Render/Object/Rectangle.idr b/src/Render/Object/Rectangle.idr new file mode 100644 index 0000000..a7093f1 --- /dev/null +++ b/src/Render/Object/Rectangle.idr @@ -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]