From 454deed731bab95fc879f0f71cf798ecb26456d7 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 30 Nov 2022 08:39:43 -0500 Subject: [PATCH] Fill out core architecture --- src/Render/Camera.idr | 22 ++++++++++++++++++++++ src/Render/Color.idr | 10 ++++++++++ src/Render/Object.idr | 17 +++++++++++++++++ src/Render/Object/Point.idr | 23 +++++++++++++++++++++++ src/Render/Scene.idr | 25 +++++++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 src/Render/Camera.idr create mode 100644 src/Render/Color.idr create mode 100644 src/Render/Object.idr create mode 100644 src/Render/Object/Point.idr create mode 100644 src/Render/Scene.idr diff --git a/src/Render/Camera.idr b/src/Render/Camera.idr new file mode 100644 index 0000000..d2e0ff7 --- /dev/null +++ b/src/Render/Camera.idr @@ -0,0 +1,22 @@ +module Render.Camera + +import Data.Nat +import Render.Color + +%default total + +public export +record Camera where + constructor MkCamera + center : (Double, Double) + scenew, sceneh : Double + pixw, pixh : Nat + + +export +pointToPix : Camera -> (Double, Double) -> (Integer, Integer) +pointToPix (MkCamera (cx,cy) sw sh pw ph) (x,y) = + let pw' = cast pw + ph' = cast ph + in (cast ((x - cx) / sw * pw' + pw' / 2), + cast ((y - cy) / sh * ph' + ph' / 2)) diff --git a/src/Render/Color.idr b/src/Render/Color.idr new file mode 100644 index 0000000..04d7d40 --- /dev/null +++ b/src/Render/Color.idr @@ -0,0 +1,10 @@ +module Render.Color + +import Data.Vect + +%default total + + +public export +Color : Type +Color = Vect 4 Bits8 diff --git a/src/Render/Object.idr b/src/Render/Object.idr new file mode 100644 index 0000000..0eeab5a --- /dev/null +++ b/src/Render/Object.idr @@ -0,0 +1,17 @@ +module Render.Object + +import Data.Vect +import Render.Camera +import Render.Color + +%default total + + +public export +interface Object' obj where + draw : obj -> Camera -> List (Integer, Integer, Color) + + +export +data Object : Type where + MkObject : Object' obj => obj -> Object diff --git a/src/Render/Object/Point.idr b/src/Render/Object/Point.idr new file mode 100644 index 0000000..c6f3e24 --- /dev/null +++ b/src/Render/Object/Point.idr @@ -0,0 +1,23 @@ +module Render.Object.Point + +import Data.Vect +import Render.Color +import Render.Camera +import Render.Picture +import Render.Object + +%default total + + + +public export +record Point where + constructor MkPoint + pos : (Double, Double) + color : Color + + +Object' Point where + draw (MkPoint pos col) cam = + let (px,py) = pointToPix cam pos + in [(px,py,col)] diff --git a/src/Render/Scene.idr b/src/Render/Scene.idr new file mode 100644 index 0000000..df1e4d3 --- /dev/null +++ b/src/Render/Scene.idr @@ -0,0 +1,25 @@ +module Render.Scene + +import Data.Vect +import Render.Color +import Render.Camera +import Render.Object + +%default total + + +public export +record Scene where + constructor MkScene + + camera : Camera + objects : List Object + bgcolor : Vect 3 Bits8 + + +public export +PictureType : Scene -> Type +PictureType sc = Vect sc.camera.pixh (Vect sc.camera.pixw (Vect 3 Bits8)) + + +