aboutsummaryrefslogtreecommitdiffstats
path: root/prototypes/workbench/examples
diff options
context:
space:
mode:
Diffstat (limited to 'prototypes/workbench/examples')
-rw-r--r--prototypes/workbench/examples/charge.pure34
-rw-r--r--prototypes/workbench/examples/counter.pure8
-rw-r--r--prototypes/workbench/examples/direct.pure47
-rw-r--r--prototypes/workbench/examples/document.pure6
-rw-r--r--prototypes/workbench/examples/layout.pure92
-rw-r--r--prototypes/workbench/examples/routed-layout.pure70
-rw-r--r--prototypes/workbench/examples/shared-layout.pure75
-rw-r--r--prototypes/workbench/examples/toggle.pure17
8 files changed, 349 insertions, 0 deletions
diff --git a/prototypes/workbench/examples/charge.pure b/prototypes/workbench/examples/charge.pure
new file mode 100644
index 0000000..eac55c4
--- /dev/null
+++ b/prototypes/workbench/examples/charge.pure
@@ -0,0 +1,34 @@
+# All holding, charging, gravity, jumping, and floor behavior is authored here.
+state holding = 0
+state charge = 0
+state y = 240
+state velocity = 0
+input jump = Space
+box floor(40, 261, 560, 4, "#356548")
+circle actor(180, y, 20, "#c78638")
+box meter(80, 80, charge * 200, 12, "#c78638")
+text amount(80, 60, charge, "Charge: ")
+on jump.down {
+ if y >= 240 {
+ holding = 1
+ charge = 0
+ }
+}
+on jump.up {
+ if holding {
+ velocity = -(160 + charge * 300)
+ holding = 0
+ charge = 0
+ }
+}
+on frame {
+ if holding {
+ charge = clamp(charge + dt, 0, 1)
+ }
+ velocity = velocity + 600 * dt
+ y = y + velocity * dt
+ if y >= 240 {
+ y = 240
+ velocity = 0
+ }
+}
diff --git a/prototypes/workbench/examples/counter.pure b/prototypes/workbench/examples/counter.pure
new file mode 100644
index 0000000..ca5f18e
--- /dev/null
+++ b/prototypes/workbench/examples/counter.pure
@@ -0,0 +1,8 @@
+# Space or the tap control increments a state that is displayed and drawn.
+state count = 0
+input tap = Space
+text label(80, 90, count, "Count: ")
+box tile(80, 150, 40 + min(count, 20) * 8, 60, "#356548")
+on tap.down {
+ count = count + 1
+}
diff --git a/prototypes/workbench/examples/direct.pure b/prototypes/workbench/examples/direct.pure
new file mode 100644
index 0000000..b29721c
--- /dev/null
+++ b/prototypes/workbench/examples/direct.pure
@@ -0,0 +1,47 @@
+# 도형을 잡은 위치를 유지해 이동합니다. 취소하면 잡기 전 위치로 돌아갑니다.
+state x = 80
+state y = 160
+state grab_x = 0
+state grab_y = 0
+state start_x = 80
+state start_y = 160
+state dragging = 0
+
+input drag = pointer(tile)
+input left = ArrowLeft
+input right = ArrowRight
+
+box left_area(20, 100, 280, 220, "#233a31")
+box right_area(340, 100, 280, 220, "#343b25")
+box tile(x, y, 56, 44, "#c9f08b")
+text horizontal(30, 45, x, "x: ")
+text vertical(180, 45, y, "y: ")
+text region(350, 70, x >= 320, "오른쪽 영역: ")
+text active(30, 75, dragging, "잡고 있음: ")
+
+on drag.down {
+ start_x = x
+ start_y = y
+ grab_x = event_x - x
+ grab_y = event_y - y
+ dragging = 1
+}
+on drag.move {
+ x = clamp(event_x - grab_x, 20, 564)
+ y = clamp(event_y - grab_y, 100, 276)
+}
+on drag.up {
+ # 놓기는 마지막으로 표시한 위치를 확정합니다.
+ dragging = 0
+}
+on drag.cancel {
+ x = start_x
+ y = start_y
+ dragging = 0
+}
+on left.down {
+ if dragging == 0 { x = max(20, x - 10) }
+}
+on right.down {
+ if dragging == 0 { x = min(564, x + 10) }
+}
diff --git a/prototypes/workbench/examples/document.pure b/prototypes/workbench/examples/document.pure
new file mode 100644
index 0000000..6d78f8c
--- /dev/null
+++ b/prototypes/workbench/examples/document.pure
@@ -0,0 +1,6 @@
+# 웹 컨트롤이 요청한 분할 비율을 받습니다. 레이아웃과 문서는 브라우저가 소유합니다.
+state ratio = 50
+input split = value
+input reset = KeyR
+on split.change { ratio = clamp(event_value, 20, 80) }
+on reset.down { ratio = 50 }
diff --git a/prototypes/workbench/examples/layout.pure b/prototypes/workbench/examples/layout.pure
new file mode 100644
index 0000000..41cf149
--- /dev/null
+++ b/prototypes/workbench/examples/layout.pure
@@ -0,0 +1,92 @@
+# 세 도형을 배치하고 배치 저장으로 결과를 보관하세요.
+# 마지막으로 잡은 도형은 방향키로 10씩 이동합니다.
+state selected = 0
+input left = ArrowLeft
+input right = ArrowRight
+input up = ArrowUp
+input down = ArrowDown
+state x1 = 80
+state y1 = 120
+state ox1 = 0
+state oy1 = 0
+state sx1 = 80
+state sy1 = 120
+state held1 = 0
+input drag1 = pointer(tile1)
+state x2 = 280
+state y2 = 160
+state ox2 = 0
+state oy2 = 0
+state sx2 = 280
+state sy2 = 160
+state held2 = 0
+input drag2 = pointer(tile2)
+state x3 = 450
+state y3 = 220
+state ox3 = 0
+state oy3 = 0
+state sx3 = 450
+state sy3 = 220
+state held3 = 0
+input drag3 = pointer(tile3)
+box board(20,90,600,240,"#233a31")
+text help(25,40,selected,"선택한 도형: ")
+box tile1(x1,y1,56,44,"#c9f08b")
+box tile2(x2,y2,56,44,"#74c4d4")
+box tile3(x3,y3,56,44,"#dfb184")
+on drag1.down {
+ selected = 1
+ sx1 = x1; sy1 = y1
+ ox1 = event_x - x1; oy1 = event_y - y1
+ held1 = 1
+}
+on drag1.move {
+ x1 = clamp(event_x - ox1, 20, 564)
+ y1 = clamp(event_y - oy1, 90, 286)
+}
+on drag1.up { held1 = 0 }
+on drag1.cancel { x1 = sx1; y1 = sy1; held1 = 0 }
+on drag2.down {
+ selected = 2
+ sx2 = x2; sy2 = y2
+ ox2 = event_x - x2; oy2 = event_y - y2
+ held2 = 1
+}
+on drag2.move {
+ x2 = clamp(event_x - ox2, 20, 564)
+ y2 = clamp(event_y - oy2, 90, 286)
+}
+on drag2.up { held2 = 0 }
+on drag2.cancel { x2 = sx2; y2 = sy2; held2 = 0 }
+on drag3.down {
+ selected = 3
+ sx3 = x3; sy3 = y3
+ ox3 = event_x - x3; oy3 = event_y - y3
+ held3 = 1
+}
+on drag3.move {
+ x3 = clamp(event_x - ox3, 20, 564)
+ y3 = clamp(event_y - oy3, 90, 286)
+}
+on drag3.up { held3 = 0 }
+on drag3.cancel { x3 = sx3; y3 = sy3; held3 = 0 }
+on left.down {
+ if selected == 1 && held1 == 0 { x1 = clamp(x1 + -10, 20, 564) }
+ if selected == 2 && held2 == 0 { x2 = clamp(x2 + -10, 20, 564) }
+ if selected == 3 && held3 == 0 { x3 = clamp(x3 + -10, 20, 564) }
+}
+on right.down {
+ if selected == 1 && held1 == 0 { x1 = clamp(x1 + 10, 20, 564) }
+ if selected == 2 && held2 == 0 { x2 = clamp(x2 + 10, 20, 564) }
+ if selected == 3 && held3 == 0 { x3 = clamp(x3 + 10, 20, 564) }
+}
+on up.down {
+ if selected == 1 && held1 == 0 { y1 = clamp(y1 + -10, 90, 286) }
+ if selected == 2 && held2 == 0 { y2 = clamp(y2 + -10, 90, 286) }
+ if selected == 3 && held3 == 0 { y3 = clamp(y3 + -10, 90, 286) }
+}
+on down.down {
+ if selected == 1 && held1 == 0 { y1 = clamp(y1 + 10, 90, 286) }
+ if selected == 2 && held2 == 0 { y2 = clamp(y2 + 10, 90, 286) }
+ if selected == 3 && held3 == 0 { y3 = clamp(y3 + 10, 90, 286) }
+}
diff --git a/prototypes/workbench/examples/routed-layout.pure b/prototypes/workbench/examples/routed-layout.pure
new file mode 100644
index 0000000..8933c70
--- /dev/null
+++ b/prototypes/workbench/examples/routed-layout.pure
@@ -0,0 +1,70 @@
+# 하나의 포인터 입력과 네 반응을 모든 도형이 공유합니다.
+state selected = 0
+record Tile {
+ x = 0; y = 0
+ ox = 0; oy = 0
+ sx = 0; sy = 0
+ held = 0; id = 0
+}
+item green = Tile(x=80, y=120, sx=80, sy=120, id=1)
+item blue = Tile(x=280, y=160, sx=280, sy=160, id=2)
+item amber = Tile(x=450, y=220, sx=450, sy=220, id=3)
+input left = ArrowLeft
+input right = ArrowRight
+input up = ArrowUp
+input down = ArrowDown
+input drag = pointer {
+ green_box: green
+ blue_box: blue
+ amber_box: amber
+}
+box board(20,90,600,240,"#233a31")
+text help(25,40,selected,"선택한 도형: ")
+box green_box(green.x,green.y,56,44,"#c9f08b")
+box blue_box(blue.x,blue.y,56,44,"#74c4d4")
+box amber_box(amber.x,amber.y,56,44,"#dfb184")
+
+rule grab(t: Tile) {
+ selected = t.id
+ t.sx = t.x; t.sy = t.y
+ t.ox = event_x - t.x; t.oy = event_y - t.y
+ t.held = 1
+}
+rule move(t: Tile) {
+ t.x = clamp(event_x - t.ox, 20, 564)
+ t.y = clamp(event_y - t.oy, 90, 286)
+}
+rule drop(t: Tile) { t.held = 0 }
+rule cancel(t: Tile) { t.x = t.sx; t.y = t.sy; t.held = 0 }
+rule go_left(t: Tile) {
+ if selected == t.id && t.held == 0 { t.x = clamp(t.x - 10, 20, 564) }
+}
+rule go_right(t: Tile) {
+ if selected == t.id && t.held == 0 { t.x = clamp(t.x + 10, 20, 564) }
+}
+rule go_up(t: Tile) {
+ if selected == t.id && t.held == 0 { t.y = clamp(t.y - 10, 90, 286) }
+}
+rule go_down(t: Tile) {
+ if selected == t.id && t.held == 0 { t.y = clamp(t.y + 10, 90, 286) }
+}
+
+on drag.down use grab(drag.target)
+on drag.move use move(drag.target)
+on drag.up use drop(drag.target)
+on drag.cancel use cancel(drag.target)
+
+on left.down use go_left(green)
+on right.down use go_right(green)
+on up.down use go_up(green)
+on down.down use go_down(green)
+
+on left.down use go_left(blue)
+on right.down use go_right(blue)
+on up.down use go_up(blue)
+on down.down use go_down(blue)
+
+on left.down use go_left(amber)
+on right.down use go_right(amber)
+on up.down use go_up(amber)
+on down.down use go_down(amber)
diff --git a/prototypes/workbench/examples/shared-layout.pure b/prototypes/workbench/examples/shared-layout.pure
new file mode 100644
index 0000000..38c001d
--- /dev/null
+++ b/prototypes/workbench/examples/shared-layout.pure
@@ -0,0 +1,75 @@
+# 대상별 값은 item에, 공통 반응은 rule에 한 번만 작성합니다.
+state selected = 0
+record Tile {
+ x = 0; y = 0
+ ox = 0; oy = 0
+ sx = 0; sy = 0
+ held = 0; id = 0
+}
+item green = Tile(x=80, y=120, sx=80, sy=120, id=1)
+item blue = Tile(x=280, y=160, sx=280, sy=160, id=2)
+item amber = Tile(x=450, y=220, sx=450, sy=220, id=3)
+input left = ArrowLeft
+input right = ArrowRight
+input up = ArrowUp
+input down = ArrowDown
+input drag_green = pointer(green_box)
+input drag_blue = pointer(blue_box)
+input drag_amber = pointer(amber_box)
+box board(20,90,600,240,"#233a31")
+text help(25,40,selected,"선택한 도형: ")
+box green_box(green.x,green.y,56,44,"#c9f08b")
+box blue_box(blue.x,blue.y,56,44,"#74c4d4")
+box amber_box(amber.x,amber.y,56,44,"#dfb184")
+
+rule grab(t: Tile) {
+ selected = t.id
+ t.sx = t.x; t.sy = t.y
+ t.ox = event_x - t.x; t.oy = event_y - t.y
+ t.held = 1
+}
+rule move(t: Tile) {
+ t.x = clamp(event_x - t.ox, 20, 564)
+ t.y = clamp(event_y - t.oy, 90, 286)
+}
+rule drop(t: Tile) { t.held = 0 }
+rule cancel(t: Tile) { t.x = t.sx; t.y = t.sy; t.held = 0 }
+rule go_left(t: Tile) {
+ if selected == t.id && t.held == 0 { t.x = clamp(t.x - 10, 20, 564) }
+}
+rule go_right(t: Tile) {
+ if selected == t.id && t.held == 0 { t.x = clamp(t.x + 10, 20, 564) }
+}
+rule go_up(t: Tile) {
+ if selected == t.id && t.held == 0 { t.y = clamp(t.y - 10, 90, 286) }
+}
+rule go_down(t: Tile) {
+ if selected == t.id && t.held == 0 { t.y = clamp(t.y + 10, 90, 286) }
+}
+
+on drag_green.down use grab(green)
+on drag_green.move use move(green)
+on drag_green.up use drop(green)
+on drag_green.cancel use cancel(green)
+on left.down use go_left(green)
+on right.down use go_right(green)
+on up.down use go_up(green)
+on down.down use go_down(green)
+
+on drag_blue.down use grab(blue)
+on drag_blue.move use move(blue)
+on drag_blue.up use drop(blue)
+on drag_blue.cancel use cancel(blue)
+on left.down use go_left(blue)
+on right.down use go_right(blue)
+on up.down use go_up(blue)
+on down.down use go_down(blue)
+
+on drag_amber.down use grab(amber)
+on drag_amber.move use move(amber)
+on drag_amber.up use drop(amber)
+on drag_amber.cancel use cancel(amber)
+on left.down use go_left(amber)
+on right.down use go_right(amber)
+on up.down use go_up(amber)
+on down.down use go_down(amber)
diff --git a/prototypes/workbench/examples/toggle.pure b/prototypes/workbench/examples/toggle.pure
new file mode 100644
index 0000000..a29f38f
--- /dev/null
+++ b/prototypes/workbench/examples/toggle.pure
@@ -0,0 +1,17 @@
+# Space toggles the circle. Right arrow moves the tile.
+state visible = 1
+state position = 120
+input toggle = Space
+input move = ArrowRight
+circle marker(position, 140, visible * 24, "#c78638")
+box tile(position - 24, 190, 48, 48, "#356548")
+text value(80, 80, visible, "Visible: ")
+on toggle.down {
+ visible = !visible
+}
+on move.down {
+ position = position + 40
+ if position > 560 {
+ position = 80
+ }
+}