Change x axis so 0dg points north?

I’m really new to Julia but like what I see so far. My goal is to write a program to help blind folks draw. For kids, it’ll help w/spatial orientation. For everyone, it’ll help them to communicate using graphics. Likely the best way to do that is to use Turtle graphics or similar, & I see that’s implemented in Luxor. The problem is that I really need 0 degrees to be pointing north, not as it is now using the default Luxor system. I did read some posts regarding this, i.e. scale(1,-1)? but it seemed like when text was added, there were problems w/that solution.

I’m no mathematician (my former training was that of a physician), so if you could perhaps phrase it so a 2-year-old (or maybe 5yo) could understand, that’d be great.

Don’t use scale because that flips text. Just transform your coordinates before you send them to Luxor, y_new = -y + height I think.

Hi, and welcome to the Julia community! Happy to hear you’re enjoying the language.


Could you give an example (e.g. a hand-drawing) of the output you desire?

If you just rotate every Turtle by -90°, then the 0° direction would be up (north). So perhaps it would suffice to create a new constructor MyTurtle and function MyOrientation calling Turtle and Orientation with a shifted angle.

using Luxor

MyTurtle(x=0., y=0., pendown=true, orientation=0., pencolor=(1.0, 0.25, 0.25)) = 
    Turtle(x, y, pendown, orientation - pi/2, pencolor)     # uses radians
MyOrientation(t::Turtle, r = 0.) = Orientation(t, r - 90.)  # uses degrees

Drawing(300, 300)
background("white")
origin()

t_north = MyTurtle()
Pencolor(t_north, "red")
Forward(t_north, 100)
Message(t_north, "Default orientation (0°) = north")

t_east = MyTurtle(0., 0., true, pi/2)
Pencolor(t_east, "green")
Forward(t_east, 100)
Message(t_east, "90° = east") 

t_west = MyTurtle()
MyOrientation(t_west, -90.)
Pencolor(t_west, "blue")
Forward(t_west, 100)
Message(t_west, "-90° = west")

t_turn = MyTurtle()
MyOrientation(t_turn, -180.)
Pencolor(t_turn, "orange")
Forward(t_turn, 50)
Turn(t_turn, 60)
Forward(t_turn, 50)
Message(t_turn, "Started going south, then turned +60°")

finish()

2 Likes

First, jules & eldee, thank you for your replies. I’m very appreciative–far more than I can express. Eldee, I think what you’ve written here is what I’m looking for. Like I said, I’m really new, &, as such, I need to study this a bit in order to fully understand precisely what’s being done. But it looks on the money, whether or not I have any.

I realize that combining drawing & blind people in the same sentence seems rather counterintuitive, but even those blind from birth are taught clock/compass orientation early in life, and it’s why I need to simulate that in the graphics environment.

I think Julia’s a cool language, & 1 advantage it has is that indentation is not crucial, as in some other languages. Indentation can make it hard for those using screen readers to identify errors that result from improper indenting.

Please give me a little time to study this. I’ll be back either to ask further questions, mark a solution, or both. I appreciate everyone’s patience. Everyone have a blessed rest of your day.

1 Like

Turtle graphics always throws me for a loop because there isn’t a standard. Turtle graphics mostly use relative changes (turning right instead of specifying a direction, moving a distance instead of specifying a location), so there’s less of a need for a strict standard. Still, the differences in implementation can get pretty jarring. Logo’s original turtle and other implementations have a turn-left (counterclockwise) and turn-right (clockwise), so users would usually input positive angles. Luxor however only has clockwise (*by default) Turn, so users would use negative angles for counterclockwise turns.

There is also a lack of standard in geometry and display. If I recall correctly, Logo’s original turtle graphics indeed starts facing (“heading”) north and sets the angle value at 0 there, but many implementations like Luxor start facing east at 0 to match conventional display of polar coordinates in mathematics. Using polar coordinates also results in visual variations because the displayed directions of the x and y Cartesian coordinates can differ. If the x axis increases from left to right and the y axis increases from bottom to top per mathematical convention, then a positive angle turn in polar coordinates is counterclockwise. *In Luxor, the y axis instead increases from top to bottom per 2D graphics convention, so a positive angle Turn is clockwise. This is the actual reason for the suggestion to scale(1, -1) initially so the y-axis would reverse to conventional display, and the absence of left-turn and right-turn functions is precisely because Turn’s direction is relative to the coordinates while our intuition of direction is firmly relative to the display. There’s no wrong approach when things are relative, in fact we could’ve called the turtle’s initial orientation “north”, the north end of the compass would just be along the x axis toward the right side of the screen instead of conventionally along the y axis toward the top side.

eldee’s customized Turtle constructor and shifted Orientation-setter is one approach to moving things toward your standard. But it would be worth further specifying your standard for displayed directions of x and y axes, what direction you’d like your 0 angle to be in terms of x,y unit coordinates, and basic kid-friendly turtle movement commands. With some more math like eldee’s, maybe something can be whipped up.

1 Like

Hello, Benny, & thanks for joining the thread! Yall have been so very kind. Basically, my intent is to make a port of the Logo/R turtle functions to Julia, as they’re quite similar. That means:

  • Simplify typing of functions, i.e. rt for right, lt for left, fd for forward, etc. Everyone loves to avoid typing, nowhere is that mor true than for kids & programmers.
  • Be able to make the turtle visible/invisible as desired (hide/show turtle).
  • Change the shape/size of the turtle to help those w/low vision. This likely means being able to incorporate a shape of their choosing.
  • 0 degrees represents north.
  • I’ll likely include clockface functions as well, i.e., 12, 1, 2, etc.

Python actually has a way to configure which coordinate system should be used via a mode constant, i.e., standard (original Luxor), Logo (0dg=north), & world, which are actually user-defined. It can be done programmatically or a config file.

Since, as I said, I’m really new, and I do have a pretty busy life, this won’t happen overnight lol.

To give just a little background for those who might care, although I’m new to Julia, I’ve been programming computers in 1 way or another for over 30 years. So although Julia’s syntax is a bit new for me, many of (at least the basic concepts) are not. Now–you start throwing matrices at me & I’m totally lost.

For those who haven’t yet suspected, I’m completely blind now. It doesn’t stop me from doing most stuff. They don’t let me drive, of course, but I swear to yall sometimes I do better than a lot of folks out there on the roads. As I like to say, there are 2 causes of visual impairment–1 like I have, & the 2nd is because someone has their head where the sun doesn’t shine. Of course, unfortunately, I can attest to the fact the 2 aren’t necessarily mutually exclusive :(.

I’ve taken a lot of yall’s time, for which I apologize. Thanks for everyone’s suggestions. I’m 100% certain I’ll have more questions as I go beyond planning & understanding Julia’s syntax, & I’ll be back to bother you again when the time comes.