Post Reply 
newRPL - build 1255 released! [updated to 1299]
02-05-2020, 01:07 PM (This post was last modified: 02-05-2020 01:20 PM by 3298.)
Post: #639
RE: newRPL - build 1255 released! [updated to 1299]
(02-04-2020 07:24 PM)compsystems Wrote:  In previous post it is mentioned that the library or graphic module of NewRPL is in development, I think it is a good idea to give some compatibility with names and argument of the MatPlotLib et Turtle library
You seem to have forgotten (again!) that these commands are extremely unlikely to be builtin due to their utter lack of usefulness to the general programmer and engineer (which the 50g has always been made for), instead requiring you to implement them. That also means YOU get to choose what their names are.
In short: Claudio's work on such compatibility is done already, and it has been since user programs could be written and named (i.e. for several years).

---

Since you seem to be incapable of actually implementing something rather than merely tossing ridiculous suggestions for your wanted builtin commands around, let me show you some code that demonstrates how trivial implementing your turtle commands in RPL really is.
For this I'm using for the most part very basic RPL functionality (stack juggling, global variables, IF ... THEN ... END, a little bit of trig and arithmetic operators, units to work with angle modes), the command LINE from old UserRPL (i.e. a single really elementary graphics command), and a little bit of complex numbers which LINE uses for coordinates. This means that as soon as LINE is implemented in newRPL, this should all just work.

Let's start with "goto". The purpose of "goto" is to update the stored position of the cursor (a.k.a. the turtle) to the given coordinates, and draw a line between the previous and new position if drawing is enabled (a.k.a. the pen is down), right? If so, try this:
Code:
« i * + IF turtlepen THEN turtlepos OVER LINE END 'turtlepos' STO »
Then, "forward" should be the same as a "goto" to a position calculated as the current position plus a given offset in a previously stored direction, correct? Let's use some trig to translate the offset into Cartesian coordinates, followed by a call to the "goto" program:
Code:
« turtledir COS OVER * turtlepos RE + turtledir SIN ROT * turtlepos IM + goto »
"left" should be as simple as updating the direction. Let's make sure angle mode changes between invocations don't affect it by always converting the input to degrees first (if you want the input to always be interpreted as degrees regardless of mode, use →UNIT in place of CONVERT):
Code:
« 1._° CONVERT turtledir + 'turtledir' STO »
"pendown" just sets the boolean flag read by the "goto" program:
Code:
« 1. 'turtlepen' STO »
I'm skipping pencolor because it's pointless on a monochrome screen. You can make it an alias for DROP (to get its single parameter off the stack) if you really need it.

Now, for your home assignment: Implement "right" and "penup" yourself. You can use "left" and "pendown" as templates. Also, implement an initialization program that sets the global variables used in this set of programs (turtlepos, turtledir, turtlepen) to some sane defaults and turns off obstructions like axes and their labels.

With these commands, the RPL version (because newRPL is obviously all about RPL) of that example you lazily grabbed off the internet becomes:
Code:
«
  IF OVER 0. ==
  THEN NIP forward
  ELSE
    OVER 1. - OVER 3. / koch
    60. left
    OVER 1. - OVER 3. / koch
    120. right
    OVER 1. - OVER 3. / koch
    60. left
    SWAP 1. - SWAP 3. / koch
  END
» 'koch' STO
penup
-180. -50. goto
pendown
4 360 koch
Is that enough hand-holding for you, or do I need to provide a solution for the home assignment too?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: newRPL - build 1001 released! - pier4r - 12-16-2017, 08:03 AM
newRPL - on Hp 39gs - Martin Hepperle - 06-05-2019, 06:51 AM
RE: newRPL - build 1001 released! - pier4r - 12-23-2017, 10:16 AM
RE: newRPL - build 1001 released! - pier4r - 01-01-2018, 09:42 AM
t - Claudio L. - 01-01-2018, 03:06 PM
RE: newRPL - build 1001 released! - pier4r - 01-01-2018, 03:41 PM
RE: newRPL - build 1001 released! - pier4r - 01-02-2018, 04:54 PM
RE: newRPL - build 1001 released! - pier4r - 01-02-2018, 06:58 PM
newRPL - brickviking - 10-05-2018, 06:01 AM
How to participate? - erazor - 12-13-2019, 07:12 AM
RE: newRPL - build 1255 released! [updated to 1299] - 3298 - 02-05-2020 01:07 PM



User(s) browsing this thread: 2 Guest(s)