Fill out core architecture

This commit is contained in:
Kiana Sheibani 2022-11-30 08:39:43 -05:00
parent 7e4888af48
commit 454deed731
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
5 changed files with 97 additions and 0 deletions

22
src/Render/Camera.idr Normal file
View file

@ -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))

10
src/Render/Color.idr Normal file
View file

@ -0,0 +1,10 @@
module Render.Color
import Data.Vect
%default total
public export
Color : Type
Color = Vect 4 Bits8

17
src/Render/Object.idr Normal file
View file

@ -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

View file

@ -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)]

25
src/Render/Scene.idr Normal file
View file

@ -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))