Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 07:53 24 Sep 2020 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Proposed enhancements to CMM2 Turtle Graphics

Author Message
Sasquatch

Senior Member

Joined: 08/05/2020
Location: United States
Posts: 156
Posted: 01:08am 03 Aug 2020
Copy link to clipboard 
Print this post

I have been experimenting with Turtle Graphics on the CMM2.  It reminds me of learning UCSD Pascal on the Terak 8510 as a teenager.  They had them at the University.  Later on they replaced them with Apple][e computers and I bought one as "surplus"

I am noticing that MMBasic seems to have some odd limitations as compared to other implementations.  I keep needing to find work-arounds for these limitations. Based on this experience and looking at some examples online, I would like to suggest the following enhancements.  I believe these modest enhancements can be made without "breaking" any existing functionality.

"TURTLE TURN RIGHT" and "TURTLE TURN LEFT" should accept floating point angles as their parameters.  "TURTLE HEADING" already accepts a floating point angle as it's parameter.  It appears that position and heading are tracked as float (type TFLOAT) internally in MMBasic.  There is no reason to restrict the heading to an integer.  One degree of resolution is really not sufficient.  In fact, everything should be able to track position and heading as floating point and only need to be integers when plotted to the screen.


The following seem to have limits of 0-360 for the angle parameter:
 TURTLE HEADING
 TURTLE TURN LEFT
 TURTLE TURN RIGHT

While it may seem conceptually odd to "Turn Right" by 734.2 degrees, In principle there is no reason that this shouldn't work.  We are using a computer after all!  This makes more sense if the angle is calculated rather than input as a constant.  I propose removing the limits to the parameter for these functions.  There is really no reason that these commands shouldn't accept negative angles as well (see below)


Similarly:
 TURTLE FORWARD
 TURTLE BACKWARD
Are limited to 0-MM.HRES as the number of pixels to move.  This means you can't even move diagonally across the full screen in one move.  Again it might seem odd to move forward by -327 pixels but why shouldn't it work?


I would potentially like the following sub-commands added.  Before anyone freaks out about the limit on new keywords, "TURTLE" is the only tokenized keyword used.  The sub-commands are implemented as options to the "TURTLE" command.

TURTLE GO n  (Move is already used)  This would move forward if n is positive and backward if n is negative.  Note that this would be somewhat redundant if the "Turtle Forward" command would accept a negative number.  It might be conceptually easier for beginners not to use TURTLE FORWARD 0 - Distance for example.

TURTLE TURN deg  This would make a relative change to the heading right (clockwise) if deg is positive and left (counter-clockwise) if deg is negative.  Again this is potentially redundant if TURTLE TURN RIGHT would accept a negative angle.

Regards,
-Carl
 
Sasquatch

Senior Member

Joined: 08/05/2020
Location: United States
Posts: 156
Posted: 02:40am 03 Aug 2020
Copy link to clipboard 
Print this post

Oh, and TURTLE PEN WIDTH would be nice too, but that's likely a little more involved than the changes outlined above.
-Carl
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 3869
Posted: 03:31pm 03 Aug 2020
Copy link to clipboard 
Print this post

Try the latest beta V5.05.05b4

Floats for turns and any angle for turns and heading
negative numbers for forward and backward and range increased to +/- SQRT(MM.HRES^2 + MM.VRES^2)
Edited 2020-08-04 01:32 by matherp
 
Sasquatch

Senior Member

Joined: 08/05/2020
Location: United States
Posts: 156
Posted: 03:40pm 03 Aug 2020
Copy link to clipboard 
Print this post

  matherp said  Try the latest beta V5.05.05b4

Floats for turns and any angle for turns and heading
negative numbers for forward and backward and range increased to +/- SQRT(MM.HRES^2 + MM.VRES^2)


Thanks Peter, I'll flash the latest Beta version and check it out!
-Carl
 
Sasquatch

Senior Member

Joined: 08/05/2020
Location: United States
Posts: 156
Posted: 08:42pm 03 Aug 2020
Copy link to clipboard 
Print this post

  matherp said  Try the latest beta V5.05.05b4

Floats for turns and any angle for turns and heading
negative numbers for forward and backward and range increased to +/- SQRT(MM.HRES^2 + MM.VRES^2)


I updated to Beta V5.05.05b4.

The good news is that all my little demos still work fine, so nothing got broken as far as I have tested.

The TURTLE TURN RIGHT and TURTLE TURN LEFT are now working great with floating point angles and negative angles.

The TURTLE FORWARD and TURTLE BACKWARD are still giving an error message that the valid range is 1-1000 (Mode 1,8) when passing a negative number.

No rush on this, I can wait for the next Beta to test it.
Edited 2020-08-04 06:47 by Sasquatch
-Carl
 
Sasquatch

Senior Member

Joined: 08/05/2020
Location: United States
Posts: 156
Posted: 09:59pm 03 Aug 2020
Copy link to clipboard 
Print this post

Also, I can't seem to get the TURTLE FILL commands to work properly?  At first I thought It was just triangles that didn't work, but it doesn't seem to work as expected on n sided polygons either.  I could be missing something?  It almost seems like the coordinates for the fill algorithm are mirrored around screen center?

I am using V5.05.05b4

Try this sample:

' Test for Filling Turtle Polygons

Mode 1,8


' Try a Square
Turtle Reset

Turtle Begin Fill
For X = 1 to 4
 Turtle Forward 100
 Turtle Turn Right 90
Next X
Turtle End Fill

Pause(10000)

' How 'Bout an Octogon
Turtle Reset

Turtle Begin Fill
For X = 1 to 8
 Turtle Forward 100
 Turtle Turn Right 45
Next X
Turtle End Fill

Pause(10000)

' Or a 36-o-gon
Turtle Reset

Turtle Begin Fill
For X = 1 to 36
 Turtle Forward 20
 Turtle Turn Right 10
Next X
Turtle End Fill

Pause(10000)

'Try a square without the For/Next Loop
Turtle Reset

Turtle Begin Fill
 Turtle Forward 100
 Turtle Turn Right 90
 Turtle Forward 100
 Turtle Turn Right 90
 Turtle Forward 100
 Turtle Turn Right 90
 Turtle Forward 100
 Turtle Turn Right 90
Turtle End Fill



-Carl
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 368
Posted: 12:03am 04 Aug 2020
Copy link to clipboard 
Print this post

With turtle fill, it looks like each x-coordinate is mistakenly set to the corresponding y-coordinate.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 3869
Posted: 09:14am 04 Aug 2020
Copy link to clipboard 
Print this post

Fill fixed in V5.05.05b5 just posted
 
Sasquatch

Senior Member

Joined: 08/05/2020
Location: United States
Posts: 156
Posted: 04:26pm 04 Aug 2020
Copy link to clipboard 
Print this post

  matherp said  Fill fixed in V5.05.05b5 just posted


Thanks again Peter, everything looks good!  All the demo/test programs working great.
-Carl
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2020