mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 07:49:17 +03:00
52 lines
1.5 KiB
Plaintext
52 lines
1.5 KiB
Plaintext
app "breakout"
|
|
packages { pf: "platform" }
|
|
imports []# [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ]
|
|
provides [ program ] to pf
|
|
|
|
program = { render }
|
|
|
|
render = \state ->
|
|
numRows = 4
|
|
numCols = 8
|
|
numBlocks = numRows * numCols
|
|
|
|
blocks = List.map (List.range 0 numBlocks) \index ->
|
|
col =
|
|
Num.rem index numCols
|
|
|> Result.withDefault 0
|
|
|> Num.toF32
|
|
|
|
row =
|
|
index // numCols
|
|
|> Result.withDefault 0
|
|
|> Num.toF32
|
|
|
|
red = (col / Num.toF32 numCols) |> Result.withDefault 0
|
|
green = ((row / Num.toF32 numRows) |> Result.withDefault 0)
|
|
blue = (Num.toF32 index / Num.toF32 numBlocks) |> Result.withDefault 0
|
|
|
|
color = { r: red * 0.8, g: 0.2 + green * 0.6, b: 0.2 + blue * 0.8, a: 1 }
|
|
|
|
{ row, col, color }
|
|
|
|
blockWidth = state.width / numCols |> Result.withDefault 0
|
|
blockHeight = 80
|
|
|
|
rects =
|
|
List.map blocks \{ row, col, color } ->
|
|
left = Num.toF32 col * blockWidth
|
|
top = Num.toF32 (row * blockHeight)
|
|
|
|
Rect { left, top, width: blockWidth, height: blockHeight, color }
|
|
|
|
paddle =
|
|
color = { r: 0.8, g: 0.8, b: 0.8, a: 1.0 }
|
|
width = state.width * 0.1
|
|
height = state.height * 0.1
|
|
left = state.width - (state.width * 0.1)
|
|
top = state.height - (height * 2)
|
|
|
|
Rect { left, top, width, height, color }
|
|
|
|
List.append rects paddle
|