Skip to content

Commit 165f5c8

Browse files
committed
Add "Pan and Zoom"
1 parent 4689f9a commit 165f5c8

File tree

11 files changed

+159
-7
lines changed

11 files changed

+159
-7
lines changed

properties.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
password=$2y$10$AQBbicv40Z3t232trs13/OdOfPBhz9w/uA3J0Nz9txPwEWTXSgkgO

resources/codex/code/step16.ecs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
set the style of MapPanel to `width:100%;flex:1`
3030

3131
create Map in MapPanel
32-
set the key of Map to reverse `QyqunMJgsVvObUg7Rc5TpE0M_9IHWnFLBySazIA`
32+
set the key of Map to reverse `QvJu1ytaD1igrbEsRX69Okgkgyoh5eWTDySazIA`
3333
set the latitude of Map to Latitude
3434
set the longitude of Map to Longitude
3535
set the zoom of Map to Zoom
File renamed without changes.

resources/codex/code/step19.ecs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
! Pan and Zoom
2+
3+
div Div
4+
img Image
5+
variable AspectW
6+
variable AspectH
7+
variable Width
8+
variable Height
9+
variable StartW
10+
variable EndW
11+
variable StartL
12+
variable EndL
13+
variable StartT
14+
variable EndT
15+
variable StepL
16+
variable StepW
17+
variable StepT
18+
variable W
19+
variable L
20+
variable T
21+
variable N
22+
variable Steps
23+
24+
! Set the aspect ratio of the container
25+
put 16 into AspectW
26+
put 9 into AspectH
27+
28+
! Create the container
29+
create Div
30+
set the style `position` of Div to `relative`
31+
set style `margin` of Div to `1em 0 0 5%`
32+
set style `width` of Div to `90%`
33+
put the width of Div into Width
34+
multiply Width by AspectH giving Height
35+
divide Height by AspectW
36+
set style `height` of Div to Height cat `px`
37+
set style `overflow` of Div to `hidden`
38+
39+
! Test values
40+
put 0 into StartL
41+
put -120 into EndL
42+
put 0 into StartT
43+
put -140 into EndT
44+
put 100 into StartW
45+
put 460 into EndW
46+
put 200 into Steps
47+
48+
! Prepare to do the pan/zoom
49+
take StartL from EndL giving L
50+
multiply L by 1000
51+
divide L by Steps giving StepL
52+
take StartT from EndT giving T
53+
multiply T by 1000
54+
divide T by Steps giving StepT
55+
take StartW from EndW giving W
56+
multiply W by 1000
57+
divide W by Steps giving StepW
58+
59+
! Create the image
60+
create Image in Div
61+
set style `position` of Image to `absolute`
62+
set attribute `src` of Image to `/resources/img/demo0.jpg`
63+
set style `left` of Image to StartL cat `%`
64+
set style `top` of Image to StartT cat `%`
65+
set style `width` of Image to StartW cat `%`
66+
67+
put StartL into L
68+
multiply L by 1000
69+
put StartT into T
70+
multiply T by 1000
71+
put StartW into W
72+
multiply W by 1000
73+
74+
wait 1
75+
76+
while true
77+
begin
78+
wait 1
79+
put 0 into N
80+
while N is less than Steps
81+
begin
82+
add StepL to L
83+
add StepT to T
84+
add StepW to W
85+
set style `left` of Image to `calc(` cat L cat `% / 1000)`
86+
set style `top` of Image to `calc(` cat T cat `% / 1000)`
87+
set style `width` of Image to `calc(` cat W cat `% / 1000)`
88+
add 1 to N
89+
wait 2 ticks
90+
end
91+
wait 1
92+
while N is greater than 0
93+
begin
94+
take 1 from N
95+
take StepL from L
96+
take StepT from T
97+
take StepW from W
98+
set style `left` of Image to `calc(` cat L cat `% / 1000)`
99+
set style `top` of Image to `calc(` cat T cat `% / 1000)`
100+
set style `width` of Image to `calc(` cat W cat `% / 1000)`
101+
wait 2 ticks
102+
end
103+
end

resources/codex/md/step18.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Solitaire #
2+
23
Solitaire is a generic name for a number of different activities/games/exercises for a single player. The most common variants are probably card games, but one of the most traditional is a game played on a wooden board having an array of holes initially filled with pegs. One hole is initially left empty and the rules are very simple; when you take a peg and jump over its neighbor into an empty space the neighbor is removed from the board. The challenge is to remove all but one peg. It's surprisingly difficult.
34

45
Here we have an electronic version of Solitaire. Pegs are moved using drag and drop, as outlined in the previous page, but here it gets somewhat more complicated. Note: Although this script will run on a mobile device it is less than ideal as a finger tends to obscure the view of where the peg is being dragged, and there seems to be no reliable way to stop the browser dragging the entire screen contents along with the item picked. There is a version of this script at [https://easycoder.software/solitaire/](https://easycoder.software/solitaire/) that uses selection instead of dragging and is better suited to mobile browsers.
@@ -25,4 +26,4 @@ All that remains to be done is to check if there are any more possible moves, an
2526

2627
Eagle-eyed programmers might notice that the algorithms for finding valid moves are implemented twice but differently. This is largely because the script is a derivative of an earler version (that didn't use drag and drop). The technique used to test if a given peg can be moved is more concise but I decided to leave as it was the code that checks if there are any moves available. Each technique uses a number of arithmetical calculations and it demonstrates how there are often 2 or more ways to achieve any given goal.
2728

28-
~next:...~
29+
~next:Pan and Zoom~

resources/codex/md/step19.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Pan and Zoom #
2+
3+
When TV programmes show a series of images they often apply something called the "Ken Burns" Effect. This causes each image to slowly pan and/or zoom before dissolving into the next, giving a sense of movement. The effect was extensively used by the American documentarian after whom it was named.
4+
5+
In this tutorial step we'll just deal with the pan and zoom; the dissolve can wait till later.
6+
7+
~copy~
8+
9+
The code here is designed to work with any size of image container, so all dimensions are calculated as a percentage of the parent element. ~ec~ only works with integers so we deal with floating point values by exploiting the fact that each one is just one integer divided by another. So the first thing is to define the aspect ratio of the main container as a width and a height component. Then we create the container, giving it 90% of the width of its parent. We can immediately ask the system how wide this is in pixels, then we calculate the corresponding height and set it. We also get it to hide any content that falls outside its boundary.
10+
11+
Next we set up some test values. All except the last one are percentages of the width or height of the container and they define the values at the start of the animatuion and at the finish. L is "left", T is "top" and W is "width". The final value is the number of steps in the animation.
12+
13+
Next we calculate the sizes of each step for the left, top and width. Because these are actually fractional values we scale everything by a large value (1000) to maintain precision in the division operations. You'll see shortly how this is used to achieve a smooth pan or zoom.
14+
15+
Now we can create the image, give it a source URL and set its size and position to the initial values in the test data. The position style attribute is ~code:absolute~ so we can use specific dimensions inside the container.
16+
17+
Next we create high-precision working variables L, T and W, initialised to the starting values.
18+
19+
~code:while true~ ensures that the animation will run forever. Inside, each step of the animation adds the step values to the working variables and uses these to set the location and size of the image. Here we exploit a very clever feature of the browser's style processing engine, by giving it a calculation to do. To explain: if we ask for a position or size value using a calculation such as ~code:calc(142581px / 1000)~ the actual value used will be 142.581 pixels; a fractional value. The amazing thing is that the browser actually uses this value to position the image. If it were to just use the nearest integer the image would jitter badly as it moves or scales, but with the fractional value the jitter disappears and the movement is smooth. This technique works on all the browsers I've tested.
20+
21+
~next:...~

resources/ecs/codex.ecs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ Decorate:
808808
end
809809
else if left 5 of Payload is `code:`
810810
begin
811-
put `<span style="font-family:mono;font-size:90%;color:darkred">`
811+
put `<span style="font-family:Courier New;color:darkred">`
812812
cat from 5 of Payload into Payload
813813
put Payload cat `</span>` into Payload
814814
end
@@ -988,5 +988,5 @@ GetPassword:
988988
return
989989

990990
SetPasswordValid:
991-
set PasswordValid
991+
set PasswordValid
992992
return

resources/ecs/pages.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,14 @@
128128
"index":19,
129129
"file":"step18",
130130
"title":"Solitaire",
131-
"prev":"step17"
131+
"prev":"step17",
132+
"next":"step19"
133+
},
134+
"step19": {
135+
"index":20,
136+
"file":"step19",
137+
"title":"Pan and Zoom",
138+
"prev":"step18"
132139
},
133140
"gap": {
134141
"index":50,

resources/md/home.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,4 @@ Also look at some of our examples (/SIDEBAR/). These are complete web pages you
2626

2727
After that it's time to add an ~ec~ script to your web page. The links /SIDEBAR/ include examples that should help you understand what you need to add to your website. If you need further help you can contact us in our [Slack](https://easycoder-software.slack.com/) channel. Don't be afraid to ask; everybody was a beginner once.
2828

29-
All the source code for EasyCoder is in our repository. Go to [Github](https://github.com) and search for "easycoder".
30-
29+
All of the source code of this website can be found in the [EasyCoder Repository](https:github.com/easycoder/easycoder.github.io).

resources/scripts/select

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
! Select
2+
3+
debug step
4+
variable List
5+
select Select
6+
set List to array
7+
append `One` to List
8+
append `Two` to List
9+
append `Three` to List
10+
print List
11+
create Select
12+
set Select from List
13+
stop

resources/scripts/test.ecs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
! Test
2+
3+
variable V
4+
5+
set V to array
6+
print V
7+
exit

0 commit comments

Comments
 (0)