Skip to content

Commit 4d9f0e7

Browse files
authored
Merge pull request #41 from easycoder/dev
Examples
2 parents d746f85 + 4d2d15e commit 4d9f0e7

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

resources/ecs/diceroller.ecs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
div Container
66
div Dice
77
div Dot
8+
div Text
89
variable NDice
910
variable M
1011
variable N
@@ -15,6 +16,10 @@
1516
variable Patterns
1617
variable Left
1718
variable Top
19+
variable Markup
20+
variable ECPayload
21+
variable Payload
22+
callback DecoratorCallback
1823

1924
attach Container to `ex-diceroller`
2025
on message
@@ -47,17 +52,24 @@ Start:
4752
10 10 10 70 40 10 40 70 70 10 70 70
4853

4954
set the elements of Dice to NDice
55+
put 0 into N
56+
while N is less than NDice
57+
begin
58+
index Dice to N
59+
create Dice in Container
60+
add 1 to N
61+
end
62+
gosub to AddDescription
5063

5164
Redraw:
5265
put 0 into M
5366
while M is less than 10
5467
begin
55-
clear Container
5668
put 0 into N
5769
while N is less than NDice
5870
begin
5971
index Dice to N
60-
create Dice in Container
72+
clear Dice
6173
set the class of Dice to `ec-dice`
6274
gosub to RandomiseDots
6375
add 1 to N
@@ -92,3 +104,26 @@ RandomiseDots:
92104
add 1 to D
93105
end
94106
return
107+
108+
! Add the description text
109+
AddDescription:
110+
on DecoratorCallback go to Decorate
111+
rest get Markup from `/resources/md/diceroller.md`
112+
create Text in Container
113+
set the content of Text to showdown decode Markup with DecoratorCallback
114+
return
115+
116+
Decorate:
117+
put the payload of DecoratorCallback into Payload
118+
if Payload is `ec` put ECPayload into Payload
119+
else if left 5 of Payload is `code:`
120+
begin
121+
put `<span style="font-family:mono;color:darkred">` cat from 5 of Payload into Payload
122+
put Payload cat `</span>` into Payload
123+
end
124+
else if left 5 of Payload is `html:`
125+
begin
126+
put from 5 of Payload into Payload
127+
end
128+
set the payload of DecoratorCallback to Payload
129+
stop

resources/ecs/imageswitcher.ecs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
img Thumb
1111
img Image
1212
a Link
13-
variable Markup
1413
variable ImageCount
1514
variable N
1615
variable M
1716
variable Width
17+
variable Markup
1818
variable ECPayload
1919
variable Payload
2020
callback DecoratorCallback
@@ -101,6 +101,7 @@ DoThumb:
101101
index Image to N
102102
go to Select
103103

104+
! Add the description text
104105
AddDescription:
105106
on DecoratorCallback go to Decorate
106107
rest get Markup from `/resources/md/imageswitcher.md`
@@ -121,4 +122,4 @@ Decorate:
121122
put from 5 of Payload into Payload
122123
end
123124
set the payload of DecoratorCallback to Payload
124-
stop
125+
stop

resources/md/diceroller.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Notes
2+
3+
Dice Roller can be run as an independent web page; see [Dice Roller](https://easycoder.github.io/examples/dice). If you view the page source you will see the entire script inside its special preformatted element.
4+
5+
After declaring all its variables, the script attaches a variable to the &lt;div&gt; element defined at the top of the file. It then creates 2 dice and paints onto each one the number of spots chosen by a random election. Both the dice and its spots are &lt;div&gt; elements; the latter have rounded corners of 50% radius so they appear as circles.
6+
7+
There are many ways of drawing dots on a dice. In this example we use a table with 6 rows, one for each possible value. In each of these rows are 6 pairs of top/left values giving the position of a dot. The renderer finds the right line then works its way along it, taking each pair of values and creating a dot using absolute positioning. When it reaches a zero in the line it stops.

resources/md/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The following websites were all built entirely in EasyCoder script:
1010

1111
## Dice roller /SHOW-DICEROLLER/
1212

13-
This simple demo shows two dice with a random choice of faces. Click either dice to select a new pair of value. A simple animation simulates the rolling of the dice.
13+
This simple demo shows two dice with a random choice of faces. Click either dice to select a new pair of value. A simple animation mimics the rolling of the dice.
1414
~<div id="ex-diceroller"></div>~
1515

1616
## Image switcher /SHOW-IMAGESWITCHER/

0 commit comments

Comments
 (0)