Python Projects

Teaching software development? Using LiveCode to build your curriculum? This is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Thu Nov 11, 2021 7:41 am

How did those kids become proficient in BBC BASIC?
'Proficient' might be going a bit far.

Because, in a summer coding month 3 years ago, just for a change, I spent 5 days teaching the
children BBC BASIC BEFORE looking at LiveCode.

They were all given tasks to do at home on BBC emulators on their home computers.

And, in the summer coding months in 2020 and 2021, because I was feeling particularly
bloody-minded, I hauled them off the delights of LiveCode after 2 weeks and spent
5 days teaching the children BBC BASIC.

Over 3 years (that is about 60 children) only 1 had the dubious privilege of having done anything
with SCRATCH.
BASIC is kinda funky.
Contemporary BASIC may be "kinda funky", but as we started BASIC on 2 BBC micros I have in my school

[Original hardware gets children excited.]

with the BASIC installed on BBC MODEL Bs in 1981, everything went swimmingly.

What was "fun" (well, from my point of view anyway) was performing text analysis using LEFT$, RIGHT$ and MID$
in BASIC of the sort we had just performed with LiveCode, and then getting the children to say what they thought
of the 2 ways of programming.
-
SShot 2021-11-11 at 9.40.04.png
-
SShot 2021-11-11 at 9.40.25.png
-

https://bbcmic.ro/#
-
MODEL_B.jpeg
MODEL_B.jpeg (5.55 KiB) Viewed 1322 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Thu Nov 11, 2021 8:58 am

BBC_User_Guide_LEFT$.jpg
-
BBC_User_Guide_MID$.jpg
-
BBC_User_Guide_RIGHT$.jpg

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Thu Nov 11, 2021 9:04 am

HelloWorld03_RM.jpg
-
And what I wrote there, I believe, is just as relevant now as it was then.

https://helloworld.raspberrypi.org/
-
HelloWorld17_RM.jpg

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Thu Nov 11, 2021 9:11 am

If we take a moment to examine the image "deer" we can see it
is 165 points high and 155 points wide:
-
SShot 2021-11-11 at 10.09.48.png
SShot 2021-11-11 at 10.09.48.png (22.35 KiB) Viewed 1316 times
-
Knowing that, and a bit of simple Maths we can determine the location of the animal's nose:
-
SShot 2021-11-11 at 10.27.54.png
-
We know that the current location of the animal (in that small, white card) is 200,200,

and we know that its dimensions are 155 by 165.

Therefore we know that the animal's nose is located at 144, 121 relative to the image.

We also know that the animal's nose is approximately (rounding up) located 67 points horizontally
from the centre of the image,

and 39 points vertically from the centre of the image.

Using this information we can set things so that when we move the mouse the image follows the mouseLoc
not relative to its centre, but relative to the deer's nose.
Last edited by richmond62 on Thu Nov 11, 2021 9:37 am, edited 2 times in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8901
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Python Projects

Post by FourthWorld » Thu Nov 11, 2021 9:30 am

Good docs.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Thu Nov 11, 2021 9:39 am

We can start by commenting out the GRAB command in the image of the deer in our 'Christmas' stack:
-
SShot 2021-11-11 at 10.38.17.png
SShot 2021-11-11 at 10.38.17.png (16.14 KiB) Viewed 1303 times
-
If we put this into the script of our background image we end up in trouble:

Code: Select all

on mouseMove
   put item 1 of the mouseLoc into L1
   put item 2 of the mouseLoc into L2
   put (L1 - 67) into LOC1
   put (L2 + 39) into LOC2
   move img "deer" to  LOC1, LOC2
end mouseMove
-
SShot 2021-11-11 at 10.46.56.png
-
-
If we use this:

Code: Select all

on mouseDown
   put item 1 of the mouseLoc into L1
   put item 2 of the mouseLoc into L2
   put (L1 - 67) into LOC1
   put (L2 + 39) into LOC2
   move img "deer" to  LOC1, LOC2
end mouseDown
every time we click our mouse the image moves as it should.
Attachments
Christmas 2.livecode.zip
Here's the stack.
(188.01 KiB) Downloaded 9 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Thu Nov 11, 2021 10:03 am

Directional_prob.jpg
-
The main problem with this SIMPLE code is that when you click
BEHIND the image the animal moves BACKWARDS.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Thu Nov 11, 2021 11:02 am

I have just popped a field called "DIRX" in the
bottom-right hand corner of the stack to use to
know which direction the image "deer" is facing.
-
SShot 2021-11-11 at 12.00.03.png
SShot 2021-11-11 at 12.00.03.png (10.9 KiB) Viewed 1277 times
-
We can now work extensively with the script in the background image to ensure the
animal faces the correct way, and that its nose always ends up where the mouseClick
happens:

Code: Select all

on mouseDown
   put item 1 of the loc of image "deer" into D1
   put item 1 of the mouseLoc into L1
   put item 2 of the mouseLoc into L2
   --LOCATE THE NOSE's LATERAL LOCATION
   put (D1 - 67) into DLOC1L
   put (D1 + 67) into DLOC1R
   ----------------------------------
   --CODE FOR THE DIRECTION THE IMAGE FACES
   if L1 < D1 then
      if field "DIRX" contains "LEFT" then
         flip image "deer" horizontal
         put "RIGHT" into field "DIRX"
      end if
   end if
   if L1 > D1 then
      if field "DIRX" contains "RIGHT" then
         flip image "deer" horizontal
         put "LEFT" into field "DIRX"
      end if
   end if
   -------------------------------------
   put (L1 - 67) into LLOC1
   put (L2 + 39) into LLOC2
   put (L1 + 67) into RLOC1
   put (L2 + 39) into RLOC2
   if field "DIRX" contains "LEFT" then
      move img "deer" to  LLOC1, LLOC2
   else
      move img "deer" to  RLOC1, RLOC2
   end if
end mouseDown
Attachments
Christmas 3.livecode.zip
Here's the stack.
(188.64 KiB) Downloaded 15 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Thu Nov 11, 2021 12:24 pm

SShot 2021-11-11 at 13.23.20.png
-
OK
-
SShot 2021-11-11 at 13.38.26.png
-
4 images called "P1" . . . "P4"

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Wed Nov 17, 2021 11:32 am

So, let's duplicate our presents so that we have 16 and call them p1 . . . p16
-
SShot 2021-11-17 at 12.27.44.png
-
One of my criticisms of thse projects is that they have no step-by-step pictures so
children can get an idea of what their project should look like.
-
SShot 2021-11-17 at 12.30.24.png
SShot 2021-11-17 at 12.30.24.png (66.29 KiB) Viewed 697 times
-
What should that look like?

One of the things I like a lot about LiveCode is its WYSIWYG IDE.
-
As far as I can tell, presents are meant to fall from the top of the screen from random locations . . .

Our background image "winter'jpg" is 1581 pixels wide, so let's pretend it is 1600 pixels wide so we can pick random numbers from a pot of 16
to determine where the presents will fall from.

We really need a 'PLAY" button at this stage to start the game:
-
SShot 2021-11-17 at 12.47.44.png
SShot 2021-11-17 at 12.47.44.png (19.02 KiB) Viewed 693 times
-
Obviously we don't want them falling "half off" the windows se we will play soem small Mathematical 'jiggery-pokery' to ensure that does not
happen something like this (in the PLAY button):

Code: Select all

on mouseUp
   put 1 into PREZ
   repeat until PREZ > 16
      put random(16) into LOKK
      put ((LOKK * 100) - 50) into FALLPOZZ
      add 1 to PREZ
   end repeat
end mouseUp
Where PREZ counts up to 16 for which present to use each time, and FALLPOZZ
tells us where along the top of our game each present will fall.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Wed Nov 17, 2021 11:57 am

Adding a single line hides the presents above the top line of the game positioned ready to fall:

set the loc of image ("p" & PREZ) to FALLPOZZ, -50

Code: Select all

on mouseUp
   put 1 into PREZ
   repeat until PREZ > 16
      put random(16) into LOKK
      put ((LOKK * 100) - 50) into FALLPOZZ
      set the loc of image ("p" & PREZ) to FALLPOZZ, -50
      add 1 to PREZ
   end repeat
end mouseUp
Our next bit of work is to make the presents fall:

Code: Select all

on mouseUp
   put 1 into PREZ
   repeat until PREZ > 16
      put random(16) into LOKK
      put ((LOKK * 100) - 50) into FALLPOZZ
      set the loc of image ("p" & PREZ) to FALLPOZZ, -50
      ---------------
      -- this is where we write the code to make each present fall down the screen
      ---------------
      add 1 to PREZ
   end repeat
end mouseUp
To make our job easier we can work out a name-holder for each present so we don't have to keep
repeating ("p" & PREZ):

Code: Select all

on mouseUp
   put 1 into PREZ
   repeat until PREZ > 16
      put random(16) into LOKK
      put ((LOKK * 100) - 50) into FALLPOZZ
      ------
      put ("p" & PREZ) into GIFT
      ------
      set the loc of image GIFT to FALLPOZZ, -50
      ---------------
      -- this is where we write the code to make each present fall down the screen
      ---------------
      add 1 to PREZ
   end repeat
end mouseUp

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Wed Nov 17, 2021 12:50 pm

Let's get started by making one of the presents fall down the screen:
-
SShot 2021-11-17 at 13.49.49.png
-
The button "Single Fall" will make the image "p12" fall down the screen, and
the button "RESET" will return the image "p12" to its initial hiiden position
above the screen.

Children should be invited to use this code in a repeat loop inwith the "PLAY" button to
initiate falling for each of the present images in turn.

Button: "Single Fall":

Code: Select all

on mouseUp
   put 1 into TOPP
   repeat until TOPP > 800
      set the top of image "p12" to TOPP
      add 1 to TOPP
   end repeat
end mouseUp
https://www.dropbox.com/s/e0jw0yzlgaynq ... e.zip?dl=0

[This stack, with the addition of the images of Christmas presents is now larger than the Forums will permit as uploads.]

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Wed Nov 17, 2021 1:13 pm

Pause for teacherly thoughts . . .
-
SShot 2021-11-17 at 12.30.24.png
SShot 2021-11-17 at 12.30.24.png (66.29 KiB) Viewed 672 times
-
I wonder if some institution should not offer a course in "unpicking" stuff like this.
-
My "informants" [read teenagers at the Maths High School in Plovdiv, Bulgaria] tell me that their
teachers shove pre-made stuff at them in C++ and C# and expect them to unpick them, when . . .
. . . as often as not [and they freely admit this!] they CANNOT do that themselves.

Certainly these documents are written by someone who has not studied reader-response theory. 8)

WHAT happens after "touching Rudolph"?

Clear as mud.

Never mind "Bloody-minded Richmond" will invent something. :?

You have got to love these 'half-cock' jobs that are bunged out on the internet under the aegis of some "authority" and
are second-rate at best, and, obviously, are put together by people who have never been in a classroom with a load
of kids who, God bless them, ask majorly leading questions.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Wed Nov 17, 2021 2:58 pm

I have just had an EFL class where one of the children was in tears because her 'SCRATCH' teacher at school gave them 3 programs
to copy, and when this girl asked WHAT and WHY the teacher just said, "Be quiet and copy the program."

That is not what I understand by teaching programming.
Last edited by richmond62 on Fri Nov 19, 2021 7:56 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6477
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Python Projects

Post by richmond62 » Wed Nov 17, 2021 4:13 pm

Now we can adapt the single fall code and inject it itno the PLAY button to
start all the presents falling:

Code: Select all

on mouseUp
   put 1 into PREZ
   repeat until PREZ > 16
      put random(16) into LOKK
      put ((LOKK * 100) - 50) into FALLPOZZ
      ------
      put ("p" & PREZ) into GIFT
      ------
      set the loc of image GIFT to FALLPOZZ, -50
      ---------------
      put 1 into TOPP
      repeat until TOPP > 800
         set the top of image GIFT to TOPP
         add 1 to TOPP
      end repeat
      ---------------
      add 1 to PREZ
   end repeat
end mouseUp
and we can put a REPEAT loop into the RESET button:

Code: Select all

on mouseUp
   put 1 into GIZZ
   repeat until GIZZ > 16
      put ("p" & GIZZ) into GIFT
      set the top of image GIFT to -100
      add 1 to GIZZ
   end repeat
end mouseUp
I suppose those presents that the reindeer manages to touch should end up in some sort of sack.
-
sacked.jpg
https://www.dropbox.com/s/am4en1c7dj32j ... e.zip?dl=0

Post Reply

Return to “Teaching with LiveCode”