Babies love mazes.
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Babies love mazes.
This week I had some seven year olds working out instructions to navigate a person through a maze:
- -
Here a small girl who was as keen as mustard is doing great stuff.
- -
Here a small girl who was as keen as mustard is doing great stuff.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now, what would be really great fun would be to do this sort of thing in OXT Lite.
So, let's get started:
- -
We can make a new stack that is 1000 pixels wide and 700 pixels high, and call it "Maze", and remember to save it.
So, let's get started:
- -
We can make a new stack that is 1000 pixels wide and 700 pixels high, and call it "Maze", and remember to save it.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now, as you can see from the photograph we need to make a 12 by 12 grid of square, so we should select a square vector from the tools palette:
- -
and place it on your stack, and set its size to 50 by 50 pixels:
- -
set its name to "xx"
This will be your TEMPLATE to make your grid.
Next to it place a button.
- -
and place it on your stack, and set its size to 50 by 50 pixels:
- -
set its name to "xx"
This will be your TEMPLATE to make your grid.
Next to it place a button.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Put some code into you button to make your grid:
Study this code to see how it goes through 2 cycles to generate 144 squares, name the sequentially, and position them on the stack.
Then click on the button to run the code:
- -
Remember to save your work.
Code: Select all
on mouseUp
put 1 into CYCLE1
repeat until CYCLE1 > 12
put 1 into CYCLE2
repeat until CYCLE2 > 12
clone graphic "xx"
set the name of the last graphic to ("SQUARE" & CYCLE1 & "," & CYCLE2)
set the location of the last graphic to (50 + (CYCLE1 *50)), (50 + (CYCLE2 * 50))
add 1 to CYCLE2
end repeat
add 1 to CYCLE1
end repeat
end mouseUp
Then click on the button to run the code:
- -
Remember to save your work.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now you need to make some blocks (you can see those in the photograph).
Select the round rectangle graphic in the tools palette:
- -
And set it on your stack, set its size to 44 by 44 pixels, and call it "zz".
-
Select the round rectangle graphic in the tools palette:
- -
And set it on your stack, set its size to 44 by 44 pixels, and call it "zz".
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
If you look at the photograph you will see yellow, red, green and blue blocks, so let's make some a bit like that.
We can duplicate our round rectangle using the drop-down menu:
- -
Do that 3 time so you have 4 round rectangles:
- -
Then colour them:
- -
Remember to save your work.
We can duplicate our round rectangle using the drop-down menu:
- -
Do that 3 time so you have 4 round rectangles:
- -
Then colour them:
- -
Remember to save your work.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now you can make as many blocks of any of those 4 colours as you need, and arrange them over the grid:
- -
And build up your maze.
-
- -
And build up your maze.
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now select ALL the 'blocks'.
Do this by pressing on the SHIFT bottun on your keyboard as you select each block with your mouse.
(Be very careful NOT to select any squares from the underlying grid.)
- -
Make all those blocks into a group using the drop-down menu:
- -
Name that group "walls".
- -
Remember to save your work.
Do this by pressing on the SHIFT bottun on your keyboard as you select each block with your mouse.
(Be very careful NOT to select any squares from the underlying grid.)
- -
Make all those blocks into a group using the drop-down menu:
- -
Name that group "walls".
- -
Remember to save your work.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now IMPORT this image into your stack:
- -
Use the drop-down menu:
- -
Rename the imported image to 'man':
- -
Remember to save your work.
- -
Use the drop-down menu:
- -
Rename the imported image to 'man':
- -
Remember to save your work.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now it is time to start computer programming.
Select a field from the tools palette:
- -
And set it on your stack, and name it "f1":
- -
Give it a vertical scrollbar:
-
Select a field from the tools palette:
- -
And set it on your stack, and name it "f1":
- -
Give it a vertical scrollbar:
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Move your 'man' to the START of your maze:
- -
Unselect '3D' for your field (this makes the field a lot easier to see):
- -
Make your field very nearly the same height as your stack:
- -
Remember to save your work.
- -
Unselect '3D' for your field (this makes the field a lot easier to see):
- -
Make your field very nearly the same height as your stack:
- -
Remember to save your work.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now your user can start entering their code:
- - -
But as you can see it will be hard to see onscreen, so:
- -
set the fontSize of field "f1" to size 18 and BOLD.
- - -
But as you can see it will be hard to see onscreen, so:
- -
set the fontSize of field "f1" to size 18 and BOLD.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
HOWEVER, we need to tell the computer how to interpret what is written in field "f1", so:
- -
Select a button from the tools palette
Set it on the stack and name it 'ACTION':
- -
Make its fontSize a bit bigger and BOLD so it is easier to see:
- -
In this button we are going to write the code to interpret what is written in field "f1".
- -
Select a button from the tools palette
Set it on the stack and name it 'ACTION':
- -
Make its fontSize a bit bigger and BOLD so it is easier to see:
- -
In this button we are going to write the code to interpret what is written in field "f1".
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
If you look closely at what the child has been writing on the table you will see that there are ONLY 3 possible COMMANDS:
FORWARD followed by a number
TURN RIGHT
TURN LEFT
In OpenXTalk positions on a stack are numbered from the Top-Left hand corner like this:
- -
So, as our 'man' progresses UP the screen the number showing his vertical position will get smaller.
-
FORWARD followed by a number
TURN RIGHT
TURN LEFT
In OpenXTalk positions on a stack are numbered from the Top-Left hand corner like this:
- -
So, as our 'man' progresses UP the screen the number showing his vertical position will get smaller.
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Here is the stack at this stage in the lesson.
- Attachments
-
- MAZE.oxtstack.zip
- (6.73 KiB) Downloaded 105 times
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Before we start reading our input code to move the image "man" around we really need a 'reset' button in case things go wrong.
If we examine the image "man" we will find its start position is 150, 650:
- -
So, let's add a Reset button:
- -
And write some code inside the button to send the image "man" back to the START of the maze:
-
-
Remember to save your work.
If we examine the image "man" we will find its start position is 150, 650:
- -
So, let's add a Reset button:
- -
And write some code inside the button to send the image "man" back to the START of the maze:
Code: Select all
on mouseUp
set the location of image "man" to 150, 650
end mouseUp
Remember to save your work.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Open the scriptEditor of your ACTION button:
- -
The first thing the computer needs to know is the location of the image "man", and which we just found out is 150, 650:
- -
Now we need to set up a repeat loop that reads each line of our field "f1" and acts on any instructions it finds there:
- -
You will see that each time the repeat loop repeats FieldLine's value increases by 1.
- -
The first thing the computer needs to know is the location of the image "man", and which we just found out is 150, 650:
- -
Now we need to set up a repeat loop that reads each line of our field "f1" and acts on any instructions it finds there:
- -
You will see that each time the repeat loop repeats FieldLine's value increases by 1.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now inside the repeat loop we have to find out if the line that is being examined contains either a
FORWARD
or a
TURN command.
And if it is a FORWARD command the number of forward movements required,
And if it is TURN command if it is a RIGHT or a LEFT TURN .
------------------------------
The first thing we do is set the itemDelimiter to SPACE:
- -
Then we have to find out what the first part of the relevant line consists of: FORWARD or TURN:
- -
FORWARD
or a
TURN command.
And if it is a FORWARD command the number of forward movements required,
And if it is TURN command if it is a RIGHT or a LEFT TURN .
------------------------------
The first thing we do is set the itemDelimiter to SPACE:
- -
Then we have to find out what the first part of the relevant line consists of: FORWARD or TURN:
- -
Code: Select all
on mouseUp
put 150 into LR -- I am using 'LR' to mean the Left-Right location of the 'man'
put 650 into UD -- I am using 'UD' to mean the Up-Down location of the man
put 1 into FieldLine
repeat until line FieldLine of field "f1" is empty
set the itemDelimiter to " " --this is so we can separate 'Forward' from a number, and 'Turn' from 'Right' or 'Left'
put item 1 of line FieldLine of field "f1" into KOMMAND1
if KOMMAND1 contains "FORWARD" then
else --what follows assumes as KOMMAND1 does NOT contain "FORWARD" it contains "TURN"
end if
add 1 to FieldLine
end repeat
end mouseUp
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now we can input the code for 'TURN':
Obviously we can use 'DIREXION' to tell us HOW to move the 'man' image.
Here you can see the code in context (you will also see that the code for FORWARD is not yet in place):
-
Code: Select all
else --what follows assumes as KOMMAND1 does NOT contain "FORWARD" it contains "TURN"
put item 2 of line FieldLine of field "f1" into KOMMAND2
if KOMMAND2 contains "RIGHT" then
switch DIREXION
case "U"
put "R" into DIREXION
break
case "R"
put "D" into DIREXION
break
case "D"
put "L" into DIREXION
break
case "L"
put "U" into DIREXION
break
end switch
else --what follows assumes as KOMMAND2 does NOT contain "RIGHT" it contains "LEFT"
switch DIREXION
case "U"
put "L" into DIREXION
break
case "L"
put "D" into DIREXION
break
case "D"
put "R" into DIREXION
break
case "R"
put "U" into DIREXION
end switch
end if
Here you can see the code in context (you will also see that the code for FORWARD is not yet in place):
-
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4243
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Babies love mazes.
Now we can input the code for MOVEMENT:
Here you can see it in conext:
- -
Please also note that the START position of the man has been altered to start outwith the maze.
Code: Select all
if KOMMAND1 contains "FORWARD" then
put item 2 of line FieldLine of field "f1" into JUMPS
put item 2 of line FieldLine of field "f1"
put 1 into HOPS
repeat until HOPS > JUMPS
------
--This is where we check in which direction our man is meant to be moving and act appropriately
switch DIREXION
case "U"
subtract 50 from UD
break
case "R"
add 50 to LR
break
case "D"
add 50 to UD
break
case "L"
subtract 50 from LR
break
end switch
move image "man" to LR, UD
------
add 1 to HOPS
end repeat
--------
- -
Please also note that the START position of the man has been altered to start outwith the maze.
https://richmondmathewson.owlstown.net/
Who is online
Users browsing this forum: No registered users and 0 guests