Python Forum
Create a turtle drawing from .txt file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create a turtle drawing from .txt file
#1
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
Reply
#2
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?
Reply
#3
(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
Reply
#4
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.
Reply
#5
(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.
Reply
#6
(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
Reply
#7
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?
Reply
#8
(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
Reply
#9
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")
Reply
#10
Might just be the dumbest person ever, but I just can't wrap my head around this...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie here. Create an array from file data? Rayj00 2 1,249 Jan-13-2023, 01:35 PM
Last Post: perfringo
  how can i create a dictionary of dictionaries from a file Astone 2 2,265 Oct-26-2020, 02:40 PM
Last Post: DeaD_EyE
  Drawing wheels in a turtle woehh 1 1,900 Apr-23-2020, 02:58 PM
Last Post: deanhystad
  Turtle Polygon drawing program tp_oz 3 3,188 Jul-23-2019, 01:01 PM
Last Post: ichabod801
  Turtle drawing Right Triangle Zatoichi 3 5,733 Feb-26-2018, 12:24 AM
Last Post: Zatoichi
  Unable to create csv file Sumaira 2 3,253 Feb-06-2018, 03:43 AM
Last Post: Sumaira
  Help drawing circles with turtle songminguk 3 4,495 Dec-19-2017, 08:43 PM
Last Post: squenson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020