avatarJim McAulay🍁 I'm nobody. Are you a nobody too?

Summary

The provided web content discusses the differences between the Idle screen, the Python screen, and the turtle screen in the context of Python programming, with a focus on the use of the Cartesian plane in turtle graphics.

Abstract

The article introduces the concept of the Cartesian plane in relation to Python's Turtle module, explaining how it differs from the text-based Python screen and the script-writing Idle environment. It details the functionality of Idle as an IDE, the graphical capabilities of the turtle screen, and the significance of Cartesian coordinates in computer graphics and applied disciplines. The article also provides examples of code to illustrate how to plot points and write text on the turtle screen, emphasizing the distinction between the print function in Python and the write method in Turtle graphics.

Opinions

  • The author suggests that understanding the Cartesian plane is crucial for working with the turtle screen in Python.
  • The article implies that the turtle screen's GUI is more suited for graphics than the text-oriented Python screen.
  • The author highlights the importance of Cartesian coordinates in various fields such as astronomy, physics, engineering, and computer graphics.
  • The code examples provided demonstrate the practical use of random number generation and the goto, dot, and write methods in Turtle graphics to plot and label points on the Cartesian plane.
  • The author humorously quotes Jim McAulay to illustrate the point that children can be spoiled, which may be unrelated to the technical content but adds a personal touch to the article.
  • The inclusion of a "Buy me a coffee" image suggests that the author appreciates support for their work, indicating a personal investment in the content's reception and utility.

Python Turtle And The Cartesian Plane

The difference between a Python screen and a turtle screen

source screenshot home computer

In this article we introduce Idle and the cartesian plane. We talk about the difference between the Idle screen, the Python screen and the turtle screen and we highlight the difference between print and write.

The first screen that you see when working in Python is the script writing screen. In our case it is Idle named after Eric Idle who was a script writer for Monty Python. It is also an acronym for Integrated Development and Learning Environment.

An integrated development environment or IDE is the script writing tool associated with a language. Idle is a simple IDE that is bundle with the application. When you download turtle you usually download Idle as well.

When you write a program you normally see the Python screen with content of what you have written printed on the screen.

What you see in Idle is

print ("Hello World!")

What you see on the Python screen is

Hello World!

This will appear on the upper left hand corner of the screen. A carriage return is also generated and the next thing you print will be on the line immediately below.

When you run a program containing turtle commands. A different screen opens up.

This is a GUI or graphical user interface.

The python screen is designed to work primarily with text.

The turtle screen is designed to work primarily with graphics.

To understand the turtle screen you need to know a little bit about the cartesian plane.

The cartesian plane was developed by the mathematician and philosopher Rene Descartes to display numbers graphically with ordered co-ordinates.

Cartesian co-ordinates are an essential tool for most applied disciplines that deal with geometry, including astronomy, physics, and engineering. They are used in computer graphics, computer-aided geometric design and other geometry-related data processing

The cartesian plane has vertical and horizontal axises called the x axis and the y axis Which divide the screen into four quadrants with the middle point being 0,0.

Any two positive numbers will lie in the upper right hand quadrant.

Any two negative numbers will lie in the lower left hand quadrant.

Any two numbers that are negative and positive will line in the upper right hand quadrant.

Finally any two numbers that are positive and negative will line in the lower right hand quadrant.

To illustrate I have drawn the x and y axises and randomly generated four pairs of numbers for each of the quadrants and plotted them turtle screen.

Here is the code

import turtle as T
import random
T.forward (900)
T.back (1800)
T.home()
T.left (90)
T.forward (400)
T.back (800)
T.home()
T.penup()
x = random.randrange(10,201)
y = random.randrange (10,201)
T.goto (x,y)
T.dot()
T.write (x,font =("Arial",12,"normal") )
T.forward (40)
T.write (y,font =("Arial",12,"normal") )
x = random.randrange(-201,-10)
y = random.randrange (10,201)
T.goto (x,y)
T.dot()
T.write (x,font =("Arial",12,"normal") )
T.forward (40)
T.write (y,font =("Arial",12,"normal") )
x = random.randrange(10,201)
y = random.randrange (-201,-10)
T.goto (x,y)
T.dot()
T.write (x,font =("Arial",12,"normal") )
T.forward (40)
T.write (y,font =("Arial",12,"normal") )
x = random.randrange(-201,-10)
y = random.randrange (-201,-10)
T.goto (x,y)
T.dot()
T.write (x,font =("Arial",12,"normal") )
T.forward (40)
T.write (y,font =("Arial",12,"normal") )
T.hideturtle()

If you want to put some text on the turtle screen the command is write.

import turtle as T
T.write ("hello world!")

This will place the phrase hello world! at the current location of the cursor. When you start the cursor is in the center of the screen. The x y coordinates are 0,0. If you tried the following

import turtle as T
T.write ("hello world!")
T.write ("spam")

spam would overwrite hell and make it indescifrable and 0 world! would remain.

With turtle when you use write you have to specify the location. Otherwise it will just write at the current location of the turtle.

Jim McAulay🍁 says “I think my children are spoiled. They are beginning to smell bad”

70–67

Buy me a coffee
Technology
Python
Python Turtle
Jim Mcaulay
Illumination
Recommended from ReadMedium