Skip to content

Instantly share code, notes, and snippets.

@rupertlssmith
Created December 6, 2022 14:41
Show Gist options
  • Save rupertlssmith/9c0787580a2f55434ece6743fd72271b to your computer and use it in GitHub Desktop.
Save rupertlssmith/9c0787580a2f55434ece6743fd72271b to your computer and use it in GitHub Desktop.
DSL for Diagrammer Clone
module DGrammar exposing (..)
import BoundingBox2d exposing (BoundingBox2d)
import Color exposing (Color)
import Point2d exposing (Point2d)
import Quantity exposing (Unitless)
import Vector2d exposing (Vector2d)
type alias DGram =
{ gram : GramAST
, origin : P2
, bbox : BBox
}
type GramAST
= Circle { radius : Float }
| Square { side : Float }
| RegularPolygon { sideCount : Float }
| Polygon { points : List P2 }
| Image
| Text
| Row
{ spacing : Float
, grams : List DGram
}
| Column
{ spacing : Float
, grams : List DGram
}
| Stack { grams : List DGram }
| Translate
{ trans : V2
, gram : DGram
}
| Scale
{ scale : Float
, gram : DGram
}
| Rotate
{ degrees : Float
, gram : DGram
}
| Fill
{ color : Color
, gram : DGram
}
| Stroke
{ color : Color
, gram : DGram
}
| Opacity
{ opacity : Float
, gram : DGram
}
type Align
= AlignTop
| AlignBottom
| AlignLeft
| AlignRight
type alias P2 =
Point2d Unitless GramAST
type alias V2 =
Vector2d Unitless GramAST
type alias BBox =
BoundingBox2d Unitless GramAST
-- Vectors
v2 : Float -> Float -> V2
v2 _ _ =
Debug.todo "v2"
-- Create
circle : { radius : Float } -> DGram
circle _ =
Debug.todo "circle"
square : { side : Float } -> DGram
square _ =
Debug.todo "square"
regularPolygon : { sideCount : Float } -> DGram
regularPolygon _ =
Debug.todo "regularPolygon"
polygon : List P2 -> a
polygon _ =
Debug.todo "polygon"
image _ =
Debug.todo "image"
text _ =
Debug.todo "text"
-- Combine
stack : List DGram -> DGram
stack _ =
Debug.todo "stack"
row : { spacing : Float } -> List DGram -> DGram
row _ =
Debug.todo "row"
column : { spacing : Float } -> List DGram -> DGram
column _ =
Debug.todo "column"
-- Transform
translate : V2 -> DGram -> DGram
translate _ =
Debug.todo "translate"
scale : Float -> DGram -> DGram
scale _ =
Debug.todo "scale"
rotate : Float -> DGram -> DGram
rotate _ =
Debug.todo "rotate"
align : Align -> List DGram -> DGram
align _ =
Debug.todo "align"
pad _ =
Debug.todo "pad"
mask _ =
Debug.todo "mask"
-- Styling
stroke : Color -> DGram -> DGram
stroke _ =
Debug.todo "stroke"
fillAndStroke : Color -> Color -> DGram -> DGram
fillAndStroke _ _ =
Debug.todo "fillAndStroke"
fill : Color -> DGram -> DGram
fill _ =
Debug.todo "fill"
opacity : Float -> DGram -> DGram
opacity _ =
Debug.todo "opacity"
-- Debug
showBoundsAndOrigin _ =
Debug.todo "showBoundsAndOrigin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment