Python Forum
Is there a way to move text created by turtle.write()?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a way to move text created by turtle.write()?
#1
I'm working on a school project right now, so I'm limited with the modules I can use (turtle, random, time). The basic concept is a typing game, modeled after an old game called Typer Shark. I've created turtles for each individual letter and had the corresponding turtle write the letter on each shark, but I can't get the words to move. Obviously, moving the turtle doesn't work, but it does with the shark because the turtle shape is set as the shark. Is there a way to move the text without having to create different gifs for each letter? Could I possibly make the text a turtle shape? Thanks.

# Typer Shark
import turtle as trtl
import random as rand
import time

# setup:
shark_image = 'shark.gif' # store the file name of your shape
sharks = []
letters = []
words = ['cat', 'car', 'dog', 'top', 'red']
divided_words = []
grabbed = []
wn = trtl.Screen()
wn.tracer(False)
wn.setup(width=600, height=400)
wn.addshape(shark_image) # make the screen aware of the new file
num_sharks = len(words)
for i in range(0, num_sharks):
  shark = trtl.Turtle()
  sharks.append(shark)
string = ''
for word in words:
  string += word
for char in string:
  divided_words.append(char)
  writer = trtl.Turtle()
  letters.append(writer)

# functions:
def create_shark(active_shark):
  for active_shark in sharks:
    xcor = rand.randint(0, 150)
    ycor = rand.randint(-50, 150)
    active_shark.penup()
    active_shark.goto(xcor, ycor)
    active_shark.shape(shark_image)
    wn.update()

def write_words():
  i = 0
  ii = -1
  spacing = 0                     
  while 0 < len(divided_words):
    if i % 3 == 0:
      ii += 1
      spacing = 0
    letters[i].color('blueviolet')
    letters[i].hideturtle()
    letters[i].penup()
    letters[i].goto(sharks[ii].xcor() + spacing - 30, sharks[ii].ycor() - 20)
    letters[i].pendown()
    letters[i].write(divided_words[0], align='center', font=('Arial', 20, 'bold'))  
    grabbed.append(divided_words[0])
    divided_words.pop(0)
    spacing += 15
    i += 1

def swim(): # this was just to test
  letters[0].backward(10)
  letters[1].backward(10)
  letters[2].backward(10)
  sharks[0].backward(10)
  wn.update()
  
# function calls and events:
wn.bgpic('background.gif')
create_shark(shark)
write_words()
wn.onkeypress(swim, "a")
wn.listen()
wn.mainloop()
Reply


Messages In This Thread
Is there a way to move text created by turtle.write()? - by derekered - Dec-14-2020, 11:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 13 28,801 Yesterday, 12:26 PM
Last Post: hanmen9527
  matplotlib x-axis text move bottom upward jacklee26 3 2,283 May-31-2023, 04:28 AM
Last Post: jacklee26
  Read text file, modify it then write back Pavel_47 5 5,088 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  Turtle.setpos() vs text position on screen query ElectronWrangler 0 3,269 Nov-26-2022, 02:39 AM
Last Post: ElectronWrangler
  How to write in text file - indented block Joni_Engr 4 8,678 Jul-18-2022, 09:09 AM
Last Post: Hathemand
  CSV to Text File and write a line in newline atomxkai 4 4,211 Feb-15-2022, 08:06 PM
Last Post: atomxkai
  List Won't Write in Text File IILawrenceII 4 3,719 Jul-17-2020, 11:16 PM
Last Post: j.crater
  Write text expander in Python constantin01 5 5,371 Jan-16-2020, 08:28 AM
Last Post: buran
  read text file and write into html with correct link jacklee26 4 4,144 Aug-02-2019, 05:48 AM
Last Post: jacklee26
  write image into string format into text file venkat18 2 5,543 Jun-01-2019, 06:46 AM
Last Post: venkat18

Forum Jump:

User Panel Messages

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