Skip to content

Commit 2838d89

Browse files
committed
Examples
1 parent 446b872 commit 2838d89

File tree

7 files changed

+130
-8
lines changed

7 files changed

+130
-8
lines changed

dist/easycoder-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/easycoder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7973,7 +7973,7 @@ const EasyCoder = {
79737973
scriptLines
79747974
} = source ? source : program.source;
79757975
const lino = this.compiling ? tokens[EasyCoder_Compiler.getIndex()].lino : program[program.pc].lino;
7976-
var errString = this.compiling ? `Compile error` : `Runtime error in '${program.script}'`;
7976+
var errString = (this.compiling ? `Compile` : `Runtime`) + ` error in '${program.script}'`;
79777977
errString += `:\n`;
79787978
var start = lino - 5;
79797979
start = start < 0 ? 0 : start;

js/easycoder/Main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const EasyCoder = {
4444
scriptLines
4545
} = source ? source : program.source;
4646
const lino = this.compiling ? tokens[EasyCoder_Compiler.getIndex()].lino : program[program.pc].lino;
47-
var errString = this.compiling ? `Compile error` : `Runtime error in '${program.script}'`;
47+
var errString = (this.compiling ? `Compile` : `Runtime`) + ` error in '${program.script}'`;
4848
errString += `:\n`;
4949
var start = lino - 5;
5050
start = start < 0 ? 0 : start;

resources/ecs/diceroller.ecs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
! Twin dice roller
2+
3+
script DiceRoller
4+
5+
div Container
6+
div Dice
7+
div Dot
8+
variable NDice
9+
variable M
10+
variable N
11+
variable D
12+
variable Index
13+
variable Row
14+
variable Dots
15+
variable Patterns
16+
variable Left
17+
variable Top
18+
19+
attach Container to `ex-diceroller`
20+
on message
21+
begin
22+
if the message is `hide`
23+
begin
24+
clear Container
25+
set style `height` of Container to 0
26+
end
27+
else go to Start
28+
end
29+
set ready
30+
stop
31+
32+
Start:
33+
set style `height` of Container to ``
34+
put 2 into NDice
35+
set style `.ec-dice` to `{width:100px;height:100px;margin-right:20px;`
36+
cat `background:yellow;border:1px solid black;display:inline-block;`
37+
cat `position:relative}`
38+
set style `.ec-dot` to `{width:20px;height:20;position:absolute;`
39+
cat `background:black;border-radius:10px}`
40+
41+
set Patterns to
42+
40 40 0 0 0 0 0 0 0 0 0 0
43+
10 40 70 40 0 0 0 0 0 0 0 0
44+
10 40 40 40 70 40 0 0 0 0 0 0
45+
10 10 70 10 10 70 70 70 0 0 0 0
46+
10 10 70 10 10 70 70 70 40 40 0 0
47+
10 10 10 70 40 10 40 70 70 10 70 70
48+
49+
set the elements of Dice to NDice
50+
51+
Redraw:
52+
put 0 into M
53+
while M is less than 10
54+
begin
55+
clear Container
56+
put 0 into N
57+
while N is less than NDice
58+
begin
59+
index Dice to N
60+
create Dice in Container
61+
set the class of Dice to `ec-dice`
62+
gosub to RandomiseDots
63+
add 1 to N
64+
end
65+
wait 10 ticks
66+
add 1 to M
67+
end
68+
on click Dice go to Redraw
69+
stop
70+
71+
RandomiseDots:
72+
put random 6 into Dots
73+
multiply Dots by 12 giving Row
74+
put 0 into D
75+
while D is less than 12
76+
begin
77+
add D to Row giving Index
78+
index Patterns to Index
79+
put Patterns into Top
80+
add 1 to D
81+
if Top is not 0
82+
begin
83+
add 1 to Index
84+
index Patterns to Index
85+
put Patterns into Left
86+
create Dot in Dice
87+
set the class of Dot to `ec-dot`
88+
set style `top` of Dot to Top
89+
set style `left` of Dot to Left
90+
on click Dot go to Redraw
91+
end
92+
add 1 to D
93+
end
94+
return

resources/ecs/examples.ecs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import module Showdown
66

7+
module DiceRollerModule
8+
div DiceRoller
9+
button ShowDiceRoller
710
module ImageSwitcherModule
811
div ImageSwitcher
912
button ShowImageSwitcher
@@ -20,6 +23,7 @@
2023
variable Message
2124

2225
rest get Content from `/resources/md/examples.md`
26+
replace `/SHOW-DICEROLLER/` with `<button id="show-diceroller">Show</button>` in Content
2327
replace `/SHOW-IMAGESWITCHER/` with `<button id="show-imageswitcher">Show</button>` in Content
2428
replace `/SHOW-USERCAPTURE/` with `<button id="show-usercapture">Show</button>` in Content
2529
replace `/SHOW-LIFE/` with `<button id="show-life">Show</button>` in Content
@@ -40,6 +44,17 @@
4044
Start:
4145
scroll to 0
4246
send Content to Showdown
47+
48+
if DiceRollerModule is not running
49+
begin
50+
wait 10 ticks
51+
rest get Script from `/resources/ecs/diceroller.ecs`
52+
run Script as DiceRollerModule
53+
attach DiceRoller to `ex-diceroller`
54+
attach ShowDiceRoller to `show-diceroller`
55+
fork to InitDiceRoller
56+
end
57+
4358
if ImageSwitcherModule is not running
4459
begin
4560
wait 10 ticks
@@ -73,9 +88,19 @@ Start:
7388
attach ShowLifeDoc to `show-lifedoc`
7489
on click ShowLifeDoc send `life` to parent
7590

76-
send to ImageSwitcherModule
7791
stop
7892

93+
InitDiceRoller:
94+
send `hide` to DiceRollerModule
95+
set the text of ShowDiceRoller to `Show`
96+
on click ShowDiceRoller
97+
begin
98+
set the text of ShowDiceRoller to `Hide`
99+
on click ShowDiceRoller go to InitDiceRoller
100+
send `show` to DiceRollerModule
101+
end
102+
stop
103+
79104
InitImageSwitcher:
80105
set style `display` of ImageSwitcher to `none`
81106
set the text of ShowImageSwitcher to `Show`

resources/ecs/usercapture.ecs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
div Dialog
1212
div Row
1313
div Label
14-
div Text
1514
span Cell
1615
input Name
1716
input Email
@@ -23,7 +22,6 @@
2322
variable W
2423
variable H
2524
variable Message
26-
variable Markup
2725
variable ECPayload
2826
variable Payload
2927
callback DecoratorCallback
@@ -192,4 +190,4 @@ Decorate:
192190
put from 5 of Payload into Payload
193191
end
194192
set the payload of DecoratorCallback to Payload
195-
stop
193+
stop

resources/md/examples.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ The following websites were all built entirely in EasyCoder script:
88
- [Rembrandt.ie](https://rembrandt.ie)
99
- [Storyteller](https://storyteller20.neocities.org)
1010

11+
## Dice roller /SHOW-DICEROLLER/
12+
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.
14+
~<div id="ex-diceroller"></div>~
15+
1116
## Image switcher /SHOW-IMAGESWITCHER/
1217

1318
There are 9 images with only 1 showing. A row of thumbnail icons lets the user move left or right or select a specific image.
@@ -17,7 +22,7 @@ There are 9 images with only 1 showing. A row of thumbnail icons lets the user m
1722

1823
This is a rewrite of a script published in [Smashing Magazine](https://www.smashingmagazine.com/2020/03/introduction-alpinejs-javascript-framework/) as an example of how to use the Alpine.js micro-framework. It represents a block added to a web page, that displays an announcement and handles feedback from users.
1924
~<div id="ex-usercapture"></div>~
20-
The User Capture can be run as an independent web page; see [User Capture](/usercapture.html). If you view the page source you will see the entire script inside its special preformatted element.
25+
The User Capture can be run as an independent web page; see [User Capture](https://easycoder.github.io/examples/usercapture). If you view the page source you will see the entire script inside its special preformatted element.
2126

2227
## Storyteller
2328

0 commit comments

Comments
 (0)