Turtle Challenge

For discussion of xTalk topics related to education.
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

I have now expanded my stack to 2000 pixels wide to allow for all sorts of stuff.

(I apologise in advance to people who do not have socking great monitors).
-
Screenshot 2024-07-03 at 11.52.51.jpg
Screenshot 2024-07-03 at 11.52.51.jpg (282.01 KiB) Viewed 18765 times
-
And I have made a button 'RESET' to return the turtle to its home position:
-
Screenshot 2024-07-03 at 12.03.01.png
Screenshot 2024-07-03 at 12.03.01.png (38.61 KiB) Viewed 18764 times
-

Code: Select all

on mouseUp
   set the loc of img "TT" to the loc of img "x13"
end mouseUp
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

I have now made 10 regular rectangular graphics (which I have named g1, g2, . . . g10) to act as drop-targets for codeBlocks:
-
Screenshot 2024-07-03 at 12.14.53.png
Screenshot 2024-07-03 at 12.14.53.png (646.49 KiB) Viewed 18762 times
-
I have created a new field ('fLAP') and altered the code in the RESET button.

This is to keep track of WHERE codeblocks should be dropped:
-
Screenshot 2024-07-03 at 12.19.25.png
Screenshot 2024-07-03 at 12.19.25.png (221.29 KiB) Viewed 18762 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

The next thing is to put code into the codeblock image of the MOVE block so that when a user clicks on it it reduplicates . . .
-
Screenshot 2024-07-03 at 15.11.54.png
Screenshot 2024-07-03 at 15.11.54.png (38.17 KiB) Viewed 18758 times
-

Code: Select all

on mouseDown
   clone group "tMOVE"
   put fld "fLAP" into XXX
   set the name of the last group to ("t" & XXX)
   set the left of the last group to ((the left of group "tMOVE") + 50)
   set the top of the last group to ((the top of group "tMOVE") + 50)
end mouseDown
Now, while that will CLONE the group, the code in the cloned group needs to be changed.
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

Screenshot 2024-07-03 at 15.21.37.png
Screenshot 2024-07-03 at 15.21.37.png (142.17 KiB) Viewed 18757 times
-
The 2 selected fields hold 2 parts of the code for the cloned group.

To insert the complete script into the new group we have this modification to the script in the original group:

Code: Select all

on mouseDown
   clone group "tMOVE"
   put fld "fLAP" into XXX
   set the name of the last group to ("t" & XXX)
   set the left of the last group to ((the left of group "tMOVE") + 50)
   set the top of the last group to ((the top of group "tMOVE") + 50)
   add 1 to fld "fLAP"
   put fld "fMOVECODE_1" into MC1
   put fld "fMOVECODE_2" into MC2
   set the script of img "moveBACK65.png" of group ("t" & XXX) to (MC1 & XXX & MC2)
end mouseDown
We now have to modify the script in the cloned group to make sure it can be dropped into the graphic rectangle drop-target, or deleted.

As it is not possible to delete an object from within its own script, we need to rename a group we wish not to use and 'park' it off screen: it can be deleted at a later time.
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

The original MOVE group script (in the image component) has now been modified to take all these considerations into account:

Code: Select all

on mouseDown
   if exists(group "HAPPY") then
      delete group "HAPPY"
   end if
   clone group "tMOVE"
   put fld "fLAP" into XXX
   set the name of the last group to ("t" & XXX)
   set the left of the last group to ((the left of group "tMOVE") + 50)
   set the top of the last group to ((the top of group "tMOVE") + 50)
   add 1 to fld "fLAP"
   put fld "fMOVECODE_1" into MC1
   put fld "fMOVECODE_2" into MC2
   put fld "fMOVECODE_3" into MC3
   put fld "fMOVECODE_4" into MC4
   put fld "fMOVECODE_5" into MC5
   set the script of img "moveBACK65.png" of group ("t" & XXX) to (MC1 & XXX & MC2 & XXX & MC3 & XXX & MC4 & XXX & MC5)
end mouseDown
You will see that ALL the new script components of the cloned group are stored in a series of fields:
-
Screenshot 2024-07-03 at 15.59.00.png
Screenshot 2024-07-03 at 15.59.00.png (77.28 KiB) Viewed 18753 times
-
This is obviously an extremely inefficient way of doing things.

It should also be clear that every time one clones a group it should end up on a different drop-target.
-
Screenshot 2024-07-03 at 16.21.52.png
Screenshot 2024-07-03 at 16.21.52.png (175.52 KiB) Viewed 18748 times
-

Code: Select all

on mouseDown
   if exists(group "HAPPY") then
      delete group "HAPPY"
   end if
   clone group "tMOVE"
   put fld "fLAP" into XXX
   set the name of the last group to ("t" & XXX)
   set the left of the last group to ((the left of group "tMOVE") + 50)
   set the top of the last group to ((the top of group "tMOVE") + 50)
   add 1 to fld "fLAP"
   put fld "fMOVECODE_1" into MC1
   put fld "fMOVECODE_2" into MC2
   put fld "fMOVECODE_3" into MC3
   put fld "fMOVECODE_4" into MC4
   put fld "fMOVECODE_5" into MC5
   put fld "fMOVECODE_6" into MC6
   put fld "fMOVECODE_7" into MC7
   set the script of img "moveBACK65.png" of group ("t" & XXX) to (MC1 & XXX & MC2 & XXX & MC3 & XXX & MC4 & XXX & MC5 & XXX & MC6 & XXX & MC7)
end mouseDown
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

It is far more efficient to store all those code snippets in those 7 fields as custom properties of an object:
-
Screenshot 2024-07-03 at 16.39.48.png
Screenshot 2024-07-03 at 16.39.48.png (492.52 KiB) Viewed 18745 times
-
Screenshot 2024-07-03 at 16.42.55.png
Screenshot 2024-07-03 at 16.42.55.png (249.74 KiB) Viewed 18745 times
-

Code: Select all

on mouseDown
   if exists(group "HAPPY") then
      delete group "HAPPY"
   end if
   clone group "tMOVE"
   put fld "fLAP" into XXX
   set the name of the last group to ("move" & XXX)
   set the left of the last group to ((the left of group "tMOVE") + 50)
   set the top of the last group to ((the top of group "tMOVE") + 50)
   add 1 to fld "fLAP"
   put the X1 of button "MOVE_CODE" into MC1
   put the X2 of button "MOVE_CODE" into MC2
   put the X3 of button "MOVE_CODE" into MC3
   put the X4 of button "MOVE_CODE" into MC4
   put the X5 of button "MOVE_CODE" into MC5
   put the X6 of button "MOVE_CODE" into MC6
   put the X7 of button "MOVE_CODE" into MC7
   set the script of img "moveBACK65.png" of group ("move" & XXX) to (MC1 & XXX & MC2 & XXX & MC3 & XXX & MC4 & XXX & MC5 & XXX & MC6 & XXX & MC7)
end mouseDown
Attachments
Turtle Challenge.oxtstack.zip
(78.05 KiB) Downloaded 310 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

For people who really want to "lose control" there is a whole slew of codeblock templates freely available here:

https://scratched.gse.harvard.edu/resou ... locks.html
-
Scratch Control Blocks_if then else.png
Scratch Control Blocks_if then else.png (21.81 KiB) Viewed 18740 times
-
Scratch Event Blocks_When is greater than.png
Scratch Event Blocks_When is greater than.png (14.43 KiB) Viewed 18740 times
-
Scratch Motion Blocks_glide.png
Scratch Motion Blocks_glide.png (22.33 KiB) Viewed 18740 times
-
And THEN you can spend a considerable period of your life coding the lot. 8-)
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

Now, let's work on our codeblock to change the turtle's direction of travel:
-
turnSample.png
turnSample.png (49.4 KiB) Viewed 18733 times
-
We need a background image, a drop-down menu, and a field (exactly the same as for our movement codeblock):
-
Screenshot 2024-07-04 at 17.57.01.png
Screenshot 2024-07-04 at 17.57.01.png (41.91 KiB) Viewed 18731 times
-
I have also imported a 'turn arrow' image for the drop-down menu.
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

GROUP 'xTURN':
-
Screenshot 2024-07-04 at 18.00.41.png
Screenshot 2024-07-04 at 18.00.41.png (323.78 KiB) Viewed 18730 times
-
The script of the background image 'turnBACK65.png' needs to be extremely similar to its homologue in GROUP 'tMOVE':

Code: Select all

on mouseDown
   if exists(group "SAD") then
      delete group "SAD"
   end if
   clone group "xTURN"
   put fld "fLAP" into XXX
   set the name of the last group to ("turn" & XXX)
   set the left of the last group to ((the left of group "xTURN") + 50)
   set the top of the last group to ((the top of group "xTURN") + 50)
   add 1 to fld "fLAP"
   put the X1 of button "TURN_CODE" into TC1
   put the X2 of button "TURN_CODE" into TC2
   put the X3 of button "TURN_CODE" into TC3
   put the X4 of button "TURN_CODE" into TC4
   put the X5 of button "TURN_CODE" into TC5
   put the X6 of button "TURN_CODE" into TC6
   put the X7 of button "TURN_CODE" into TC7
   set the script of img "turnBACK65.png" of group ("turn" & XXX) to (TC1 & XXX & TC2 & XXX & TC3 & XXX & TC4 & XXX & TC5 & XXX & TC6 & XXX & TC7)
end mouseDown
AND we must load the new code for the cloned TURN group into the custom properties of a button called 'TURN_CODE'.
-
Screenshot 2024-07-04 at 18.16.30.png
Screenshot 2024-07-04 at 18.16.30.png (491.78 KiB) Viewed 18729 times
Attachments
Turtle Challenge.oxtstack.zip
(82.93 KiB) Downloaded 302 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

Now we have work on a RUN button:
-
bottomBUTTONS.png
bottomBUTTONS.png (59.08 KiB) Viewed 18726 times
-
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

But before that let's HIDE a lot of our work by narrowing our stack:

[It is better to retain those items we are not using, rather than deleting them, as we may need them again.]
-
prune.png
prune.png (596.6 KiB) Viewed 18725 times
-
AND add any buttons we may need later:
-
Screenshot 2024-07-04 at 19.25.21.png
Screenshot 2024-07-04 at 19.25.21.png (366.91 KiB) Viewed 18724 times
-
Obviously we need to transfer the code in our temporary RESET button to our new one.
-
RESET.png
RESET.png (1.98 KiB) Viewed 18721 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

We can use the SLIDER to set how fast our Turtle moves:
-
Screenshot 2024-07-05 at 16.16.29.png
Screenshot 2024-07-05 at 16.16.29.png (68.67 KiB) Viewed 18704 times
-

Code: Select all

on scrollbarDrag nV 
   set the moveSpeed to nV
end scrollbarDrag
Let's add some code to our buttons so thatthere is a viauak signal when a user mouses over them:

Code: Select all

on mouseEnter
   lock screen
   set the coloroverlay["color"] of me to blue
   set the coloroverlay["opacity"] of me to "75"
   unlock screen
end mouseEnter

on mouseLeave
   set the outerGlow of me to empty
   set the colorOverlay of me to empty
end mouseLeave

on mouseDown
   set the ink of me to notsrcor
end mouseDown
-
Screenshot 2024-07-05 at 16.29.38.png
Screenshot 2024-07-05 at 16.29.38.png (49.09 KiB) Viewed 18702 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

Let's add some code to our buttons so thatthere is a viauak signal when a user mouses over them:
'Someone' was extremely tired. :?

Let's add some code to our buttons so that there is a visual signal when a user mouses over them.
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

Having had a rethink of things I have changed the 'move' and 'rotate' flds in their respective groups to drop-down menus:
-
Screenshot 2024-07-22 at 15.31.09.png
Screenshot 2024-07-22 at 15.31.09.png (77.9 KiB) Viewed 17971 times
-
Screenshot 2024-07-22 at 15.37.32.png
Screenshot 2024-07-22 at 15.37.32.png (59.3 KiB) Viewed 17971 times
-
Screenshot 2024-07-22 at 15.38.02.png
Screenshot 2024-07-22 at 15.38.02.png (64.66 KiB) Viewed 17971 times
https://richmondmathewson.owlstown.net/
User avatar
richmond62
Posts: 4831
Joined: Sun Sep 12, 2021 11:03 am
Location: Bulgaria
Contact:

Re: Turtle Challenge

Post by richmond62 »

This restricts the choices available to an end-useer:

The distances available are 1, 2,3, and 4.

As the distance between the centre of one square and an adjacent one is 120 pixels, the turtle will move in multiples of 120.
-
Screenshot 2024-07-22 at 15.53.31.png
Screenshot 2024-07-22 at 15.53.31.png (124.54 KiB) Viewed 17969 times
-
The angles available are 90, 180, 270 degrees.

As angles such as 154 would involve quite complicated calculations to ensure the turtle travelled exactly to the centre of the nearest square these types of possibilities are best avoided.
https://richmondmathewson.owlstown.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests