Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,167 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)