-3

I am trying to find the size of the turtle screen in replit so that I can know where the turtle has went out of bounds.

Here is my code:

import turtle as t
from random import randint as r
import sys

window = t.Screen()
pet = t.Turtle()

def rand_color():
  red = r(0, 255)
  green = r(0, 255)
  blue = r(0, 255)
  pet.color(red, green, blue)

def random_turtle(num_moves):
  global count
  while count < num_moves:
    rand_color()
    pet.forward(r(10, 100))
    check()
    pet.right(r(0, 360))
    check()
    count += 1 

def check():
  global count
  x = t.xcor()
  y = t.ycor()
  if x > 350 or x < -350:
    t.right(180)
    if count > 100:
      sys.stop()
    else:
      random_turtle(100 - count)
  elif y > 330 or y < -320:
    t.right(180)
    if count > 100:
      sys.stop()
    else:
      random_turtle(100 - count)
  else:
    random_turtle(100 - count)

If there is an easier method than finding the size of the turtle screen and dividing the x by 2, please let me know in the comments!

  • Hi! What exactly is your question? Please include your code and point out your issue and where you are stuck. – adamgy Jul 11 '20 at 02:31
  • Does this answer your question? [How can I change the size of my python turtle window?](https://stackoverflow.com/questions/56528067/how-can-i-change-the-size-of-my-python-turtle-window) – zx485 Jul 10 '21 at 04:45

1 Answers1

0

You can ask turtle itself, even in Repl.it:

from turtle import Screen

screen = Screen()
print(screen.window_width(), screen.window_height())

Repl console output:

Starting X
.....400 450
> 
cdlane
  • 40,441
  • 5
  • 32
  • 81