Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Jose Luis Lopez
Jose Luis Lopez
19,179 Points

coordinates plane python

hello team treehouse community.

I'm currently working on a python program for my class CSC 110. The professor want us to draw a x, y axes with black and a background grid on blue. so my question is,

what can I do so the blue lines wont over draw on top of the x, y black axes. just the one in the center. I was thinking on a if statement but I'm not sure.

Jose Luis Lopez
Jose Luis Lopez
19,179 Points
#myPython code
import turtle
import math

wn = turtle.Screen()  # setup screen and its attributes
tess = turtle.Turtle()  # sets tess
wn.title("Coordinate axis")
tess.speed(1)


def draw_axis(s):
    # draws x, y axis
    tess.setpos(0, 0)
    tess.color("black")
    tess.pensize(5)
    for i in range(4):
        tess.fd(s)
        tess.pu()
        tess.goto(0, 0)
        tess.pd()
        tess.lt(90)
    tess.ht()


def horizontal_lines(s):
    # draw horizontal lines
    x = -300
    for y in range(-300, 300 + 1, 25):
        tess.pu()
        turtle.pu()
        turtle.goto(x, y)
        turtle.pd()
        turtle.color("lightblue")
        turtle.pensize(3)
        turtle.fd(s)


def vertical_lines(s):
    # draw vertical lines
    y = 300
    turtle.right(90)
    for x in range(-300, 300 + 1, 25):
        turtle.pu()
        turtle.goto(x, y)
        turtle.pd()
        turtle.color("lightblue")
        turtle.pensize(3)
        turtle.fd(s)




draw_axis(300)
horizontal_lines(600)
vertical_lines(600)

[MOD: corrected ```python formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

The drawing order may answer your question. Draw the horizontal and vertical lines first, then draw the black axis. So change the order of the last three lines:

horizontal_lines(600)
vertical_lines(600)
draw_axis(300)