Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main


Python


C++
JAVA
PHP
SQL
Assignments

Turtle


drawMethods_V2.py

# CAC, 3/2023
def drawForwardSlash(turtle,x,y,cellSize):
    """
    Draw a slash from (x,y) in the lower left
    to the upper right in a square of size cellSize
    :param turtle: The object to draw on
    :param x: x-coordinate of lower left corner of slash
    :param y: y-coordinate of lower left corner of slash
    :param cellSize: The size of the box
    """
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.goto(x + cellSize, y + cellSize)

def drawBackwardSlash(turtle, x, y, cellSize):
    """
    Draw a slash from (x+cellSize,y) in the lower right
    to the upper left in a square of size cellSize
    :param turtle: The object to draw on
    :param x: x-coordinate of lower left corner of slash
    :param y: y-coordinate of lower left corner of slash
    :param cellSize: The size of the box
    """
    turtle.penup()
    turtle.goto(x + cellSize, y)
    turtle.pendown()
    turtle.goto(x, y + cellSize)

def drawCircle(turtle,x,y,radius,lineWidth=1,extent=360,start=0):
    """
    Draw a circle centered at (x,y) with overall radius of radius,
    line width of lineWidth, going around extent degrees starting
    at start degrees
    :param turtle: The object to draw on
    :param x: x-coordinate of the center of the circle
    :param y: y-coordinate of the center of the circle
    :param radius: radius of the circle
    :param lineWidth: width of the line around the circle
    :param extent: how many degrees of the circle to draw
    :param start: the starting angle of the circle.
    :return:
    """
    turtle.penup()
    turtle.goto(x,y-radius+lineWidth//2)
    turtle.setheading(0)
    turtle.circle(radius-lineWidth//2,extent=start)
    turtle.pendown()
    lw = turtle.pensize()
    turtle.pensize(lineWidth)
    turtle.circle(radius-lineWidth//2,extent=extent)
    turtle.pensize(lw)