Python Forum
Create a turtle drawing from .txt file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Create a turtle drawing from .txt file (/thread-32167.html)

Pages: 1 2 3


Create a turtle drawing from .txt file - Noob101 - Jan-25-2021

Hi, haven't touched any coding language for ages and it's killing me atm.
Got an assignment that wants me to create a program that reads a .txt file of numbers and colors, and draws it out as a star shape with different colors. I've got no problem with actually creating a normal turtle code, but everything stops for me when I'm supposed to create a code that "draws" this file out. I can create something that prints out the strings, but that's it, no drawing. It's color, turtle to the right and then turtle forward

black
15
200
lightgray
150
200
black
300
200
lightgray
150
200
black
300
200
lightgray
150
200
black
300
200
lightgray
150
200

Anyone that can help me out? Or guide me to a youtube video/site that shows something similar to this? I've googled for ages without results


RE: Create a turtle drawing from .txt file - deanhystad - Jan-25-2021

Ignore the color for now and focus on just doing the moves. If you read 15 and 200, how would you make the turtle draw a line from the current location to 15, 200?


RE: Create a turtle drawing from .txt file - Noob101 - Jan-25-2021

(Jan-25-2021, 02:54 PM)deanhystad Wrote: Ignore the color for now and focus on just doing the moves. If you read 15 and 200, how would you make the turtle draw a line from the current location to 15, 200?

normally I would write up turtle.right(15) and turtle.forward(200). But that's not what the assignment is asking of me, so I'm stuck


RE: Create a turtle drawing from .txt file - deanhystad - Jan-25-2021

Is the problem that you don't know how to convert a move from x1, y1 to x2, y2 into a turn and a distance? This is a conversion from cartesian coordinates to polar coordinates. You should be able to find lots of information about how this is done. Maybe even a few examples that work in Turtle.


RE: Create a turtle drawing from .txt file - Noob101 - Jan-25-2021

(Jan-25-2021, 03:24 PM)deanhystad Wrote: Is the problem that you don't know how to convert a move from x1, y1 to x2, y2 into a turn and a distance?

I can get it to read/print out the colours, angles and forward separately from each other, but I can't figure out how to actually get the program to draw it out, without having to do just a normal turtle code, which I'm not allowed to.


RE: Create a turtle drawing from .txt file - Noob101 - Jan-25-2021

(Jan-25-2021, 03:31 PM)Noob101 Wrote:
(Jan-25-2021, 03:24 PM)deanhystad Wrote: Is the problem that you don't know how to convert a move from x1, y1 to x2, y2 into a turn and a distance?

I can get it to read/print out the colours, angles and forward separately from each other, but I can't figure out how to actually get the program to draw it out, without having to do just a normal turtle code, which I'm not allowed to.

from the .txt file that is


RE: Create a turtle drawing from .txt file - deanhystad - Jan-25-2021

What do you mean by "normal turtle code" and "not allowed to do"? How are you expected to do drawing? Will this program be using turtle graphics or something else to do the drawing. If something else, what is the something else?


RE: Create a turtle drawing from .txt file - Noob101 - Jan-25-2021

(Jan-25-2021, 03:39 PM)deanhystad Wrote: What do you mean by "normal turtle code" and "not allowed to do"? How are you expected to do drawing? Will this program be using turtle graphics or something else to do the drawing. If something else, what is the something else?

"Create a program that reads a file of numbers and uses these numbers to draw shapes with Turtle Graphics. The first number should be interpreted as an angle that the turtle should rotate to the right. Other numbers should be interpreted as the turtle going forward and drawing. Third numbers should be interpreted as an angle that the turtle should rotate to the right. The fourth number should be interpreted as the turtle going forward and drawing. And so on until the file is finished. Text that cannot be converted to numbers should be interpreted as a color, and the turtle's pen should be set to this color. Color names should be color names in plain English, without open spaces, newline characters or other punctuation."

I posted the .txt file in question above


RE: Create a turtle drawing from .txt file - Noob101 - Jan-25-2021

The "hints" that we're getting is that we're supposed to learn about files and exceptions, strings and linenumbers. I can get my program to read/print the file out as text, but I'm not sure how to get my program to actually draw it out, without having the 24 lines of turtle.color(),turtle.right() and turtle.forward() etc. (also got a comment with "needs to be a clean script without the hard-coding of the turtle")


RE: Create a turtle drawing from .txt file - Noob101 - Jan-25-2021

Might just be the dumbest person ever, but I just can't wrap my head around this...