From a6e081c98890794e310774944781f88214d87d89 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Mon, 15 Aug 2022 10:05:48 +0300 Subject: [PATCH] add new samples --- samples/anim-sample.lua | 58 +++++++++++++++++++++++++++++++++++++++++ samples/dice-widget.lua | 38 +++++++++++++++++++++++++++ samples/star-wars.lua | 37 ++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 samples/anim-sample.lua create mode 100644 samples/dice-widget.lua create mode 100644 samples/star-wars.lua diff --git a/samples/anim-sample.lua b/samples/anim-sample.lua new file mode 100644 index 0000000..39387cf --- /dev/null +++ b/samples/anim-sample.lua @@ -0,0 +1,58 @@ +local fmt = require "fmt" + +function on_resume() + ui:show_lines{ + "Tap to change text", + "Tap to change text quick", + "Tap to change text color", + "Tap to change text and back", + "Tap to typewriter", + "Tap to karaoke", + "Tap to blink", + "Tap to move", + "Tap to heartbeat", + "Tap to shake", + } +end + +function on_click(idx) + if idx == 1 then + morph:change_text(idx, "Text changed") + elseif idx == 2 then + morph:change_text(idx, "Text changed", 0) + elseif idx == 3 then + morph:change_text(idx, fmt.red("Color changed")) + elseif idx == 4 then + morph:change_text(idx, "Text changed") + morph:run_with_delay(1000, function () + morph:change_text(idx, "Type to change text and back") + end) + elseif idx == 5 then + local tab = {} + local text = "Wake up, Neo" + for i=1,text:len() do + table.insert(tab, fmt.green(text:sub(1, i))) + end + morph:change_text_seq(idx, tab, 100) + elseif idx == 6 then + local tab = {} + local text = [[ + Yesterday + All my troubles seemed so far away + Now it looks as though they're here to stay + Oh, I believe in yesterday + ]] + for i=1,text:len() do + table.insert(tab, fmt.blue(text:sub(1, i))..text:sub(i+1)) + end + morph:change_text_seq(idx, tab, 100) + elseif idx == 7 then + anim:blink(idx) + elseif idx == 8 then + anim:move(idx, 100, 0) + elseif idx == 9 then + anim:heartbeat(idx) + elseif idx == 10 then + anim:shake(idx) + end +end diff --git a/samples/dice-widget.lua b/samples/dice-widget.lua new file mode 100644 index 0000000..51d9529 --- /dev/null +++ b/samples/dice-widget.lua @@ -0,0 +1,38 @@ +-- foldable = "false" + +local dices = { + "fa:dice-one", + "fa:dice-two", + "fa:dice-three", + "fa:dice-four", + "fa:dice-five", + "fa:dice-six", +} + +function on_resume() + ui:show_buttons{ + "Roll the dice", + "fa:dice-six", + "fa:dice-six", + } +end + +function on_click(idx) + if idx == 1 then + roll_dice(2) + roll_dice(3) + else + roll_dice(idx) + end +end + +function roll_dice(idx) + local tab = {} + + for i=1,10 do + table.insert(tab, dices[math.random(1, 6)]) + end + + morph:change_text_seq(idx, tab, 150) +end + diff --git a/samples/star-wars.lua b/samples/star-wars.lua new file mode 100644 index 0000000..01af236 --- /dev/null +++ b/samples/star-wars.lua @@ -0,0 +1,37 @@ +local text = [[ +It is a period of civil war. +Rebel spaceships, striking +from a hidden base, have won +their first victory against +the evil Galactic Empire. + +During the battle, Rebel +spies managed to steal secret +plans to the Empire's +ultimate weapon, the DEATH +STAR, an armored space +station with enough power to +destroy an entire planet. + +Pursued by the Empire's +sinister agents, Princess +Leia races home aboard her +starship, custodian of the +stolen plans that can save +her people and restore +freedom to the galaxy.... +]] + +function on_resume() + ui:show_text("Start") +end + +function on_click() + local tab = {} + + for i=1,text:len() do + table.insert(tab, "%%txt%%"..text:sub(1, i)) + end + + morph:change_text_seq(1, tab, 100) +end