Question

In: Computer Science

Assignment Write a program using turtle graphics which writes your initials, or any other three unique...

Assignment

Write a program using turtle graphics which writes your initials, or any other three unique letters, to the display. Look to your program for lab 1 for reminders of how to use turtle graphics.

Functions that must be written:

def drawLetter (x, y, letterColor): Write three functions, one for three unique letters. Personally, I would write drawA, drawR, and drawS. Each function must draw that letter to the screen. The x and y values determine the upper left-hand location for the start of the letter. Ensure that each letter takes the same amount of space, both vertically and horizontally. The letterColor parameter will be a string used to determine the color of the letter – use it to set the fillcolor, and maybe pencolor. You can also set pencolor to “black” to create an outline of the letter. In the Turtle Graphics Resources link in blackboard I have a link to valid turttle graphic colors.

Each function can have one, and only one, goto command. If drawing a letter which requires two “shapes,” such as a “O” with a two circles you can use a second goto. The initial goto should position the turtle in the upper left-hand location of the letter to be drawn. It might be smart to ensure that you know what direction the turtle is pointing before starting to draw the letter. All of the actual drawing must be done with basic movements, such as forward, backward, left, or right. Remember to use penup and pendown to ensure you only draw the desired lines.

def drawShadowedLetter (x, y, letterColor, offset): Write three more functions, one for each letter (mine would be drawshadowedT, drawShadowedL, and drawShadowedS). These functions will use your drawLetter functions, once using letterColor, and once adding offset to the x and y values and using “black” as the color. This will create a “shadowed” letter. These three functions will not be doing any actual drawing, all of the graphics work will be done in the drawLetter functions.

In the main program, draw your initials to the screen twice. The first time write your initials to the screen using the drawLetter functions. Somewhere else on the display, write your initials to the screen using the drawShadowedLetter functions.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code with no comments, for easy copying

import turtle

LETTER_SIZE = 50


def drawS(x, y, letterColor):
    turtle.up()
    turtle.goto(x, y - LETTER_SIZE * 2)
    turtle.setheading(0)
    turtle.color(letterColor)
    turtle.pensize(10)
    turtle.down()
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    turtle.forward(LETTER_SIZE)
    turtle.right(90)
    turtle.forward(LETTER_SIZE)
    turtle.right(90)
    turtle.forward(LETTER_SIZE)


def drawU(x, y, letterColor):
    turtle.up()
    turtle.goto(x, y)
    turtle.setheading(-90)
    turtle.color(letterColor)
    turtle.pensize(10)
    turtle.down()
    turtle.forward(LETTER_SIZE * 2)
    turtle.left(90)
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    turtle.forward(LETTER_SIZE * 2)


def drawE(x, y, letterColor):
    turtle.up()
    turtle.goto(x + LETTER_SIZE, y)
    turtle.setheading(180)
    turtle.color(letterColor)
    turtle.pensize(10)
    turtle.down()
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    turtle.forward(LETTER_SIZE)
    turtle.backward(LETTER_SIZE)
    turtle.right(90)
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    turtle.forward(LETTER_SIZE)


def drawShadowedS(x, y, letterColor, offset):
    drawS(x + offset, y + offset, 'black')
    drawS(x, y, letterColor)


def drawShadowedU(x, y, letterColor, offset):
    drawU(x + offset, y + offset, 'black')
    drawU(x, y, letterColor)


def drawShadowedE(x, y, letterColor, offset):
    drawE(x + offset, y + offset, 'black')
    drawE(x, y, letterColor)


if __name__ == '__main__':
    x = -300
    y = -200
    turtle.speed(0)
    drawS(x, y, 'red')
    drawU(x + LETTER_SIZE + 20, y, 'green')
    drawE(x + 2 * (LETTER_SIZE + 20), y, 'blue')
    x = 200
    y = 200
    drawShadowedS(x, y, 'red', 5)
    drawShadowedU(x + LETTER_SIZE + 20, y, 'green', 5)
    drawShadowedE(x + 2 * (LETTER_SIZE + 20), y, 'blue', 5)
    turtle.done()

#same code with comments, for learning

import turtle

# width of each letter
LETTER_SIZE = 50


# method to draw an 'S'
def drawS(x, y, letterColor):
    # pen up
    turtle.up()
    # moving to bottom left position of S
    turtle.goto(x, y - LETTER_SIZE * 2)
    # facing right
    turtle.setheading(0)
    # using given color
    turtle.color(letterColor)
    # thicker pen
    turtle.pensize(10)
    # pen down
    turtle.down()
    # moving forward LETTER_SIZE spaces
    turtle.forward(LETTER_SIZE)
    # turning left
    turtle.left(90)
    # moving forward LETTER_SIZE spaces, turning left again
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    # moving forward LETTER_SIZE spaces, turning right
    turtle.forward(LETTER_SIZE)
    turtle.right(90)
    # moving forward LETTER_SIZE spaces, turning right again
    turtle.forward(LETTER_SIZE)
    turtle.right(90)
    # moving forward LETTER_SIZE spaces to complete S
    turtle.forward(LETTER_SIZE)


# method to draw a 'U'
def drawU(x, y, letterColor):
    turtle.up()
    turtle.goto(x, y)  # top left position of U
    turtle.setheading(-90)  # facing down
    turtle.color(letterColor)
    turtle.pensize(10)
    turtle.down()
    # moving down LETTER_SIZE*2 spaces, then moving right LETTER_SIZE spaces and then moving
    # up LETTER_SIZE*2 spaces to complete U
    turtle.forward(LETTER_SIZE * 2)
    turtle.left(90)
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    turtle.forward(LETTER_SIZE * 2)


# method to draw an 'E'
def drawE(x, y, letterColor):
    turtle.up()
    turtle.goto(x + LETTER_SIZE, y)  # top right position
    turtle.setheading(180)  # facing left
    turtle.color(letterColor)
    turtle.pensize(10)
    turtle.down()
    # moving forward LETTER_SIZE spaces, turning left
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    # moving forward LETTER_SIZE spaces, turning left again
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    # moving forward LETTER_SIZE spaces, and then backwards LETTER_SIZE spaces
    turtle.forward(LETTER_SIZE)
    turtle.backward(LETTER_SIZE)
    # turning right
    turtle.right(90)
    # moving forward LETTER_SIZE spaces, turning left
    turtle.forward(LETTER_SIZE)
    turtle.left(90)
    # moving forward LETTER_SIZE spaces to complete 'E'
    turtle.forward(LETTER_SIZE)


# method to draw a shadowed version of 'S'
def drawShadowedS(x, y, letterColor, offset):
    # drawing shadow first
    drawS(x + offset, y + offset, 'black')
    # drawing S at x,y
    drawS(x, y, letterColor)


# method to draw a shadowed version of 'U'
def drawShadowedU(x, y, letterColor, offset):
    drawU(x + offset, y + offset, 'black')
    drawU(x, y, letterColor)


# method to draw a shadowed version of 'E'
def drawShadowedE(x, y, letterColor, offset):
    drawE(x + offset, y + offset, 'black')
    drawE(x, y, letterColor)


if __name__ == '__main__':
    # at (-300,-200) drawing S, U and E, spaced evenly
    x = -300
    y = -200
    turtle.speed(0)  # max speed
    drawS(x, y, 'red')
    drawU(x + LETTER_SIZE + 20, y, 'green')
    drawE(x + 2 * (LETTER_SIZE + 20), y, 'blue')
    # at (200,200), drawing shadowed versions of S,U and E
    x = 200
    y = 200
    drawShadowedS(x, y, 'red', 5)
    drawShadowedU(x + LETTER_SIZE + 20, y, 'green', 5)
    drawShadowedE(x + 2 * (LETTER_SIZE + 20), y, 'blue', 5)
    turtle.done()

#output


Related Solutions

Write a function that draw your initials. (Using python 3 turtle) (T, S)
Write a function that draw your initials. (Using python 3 turtle) (T, S)
Without using the graphics module, write a program to simulate an archery score tracker. Your program...
Without using the graphics module, write a program to simulate an archery score tracker. Your program should use a Tkinter canvas to draw a target. Your program should allow the user to click the target to mark where their arrow landed on the target (or off). When the user clicks the target, the program should draw a dot at that location and compute the score. Scores for each ring are as follows: yellow 5, red 4, blue 3, black 2,...
Write a function that plots the following trajectory equations using python turtle graphics. x = v*sin(A)*t...
Write a function that plots the following trajectory equations using python turtle graphics. x = v*sin(A)*t y = v*cos(A)*t -.5*(9.8)*t**2 Loop through t starting at 0 and increment by .1 until y<=0. (hint, while loop) Experiment with values of velocity V (1 to 20) and angle A (0 to 90) that gives you a good plot that does not go off the screen. Position the start of the plot at the left bottom of the screen
Write an interactive C++·program to have a user input their three initials and the length of...
Write an interactive C++·program to have a user input their three initials and the length of three sides of a triangle. Allow the user to enter the sides in any order. Determine if the entered sides form a valid triangle.The triangle may not have negative sides.The sum of any two sides must be greater than the third side to form a triangle. Determine if the entered sides are part of a scalene, isosceles, or equilateral triangle. Using the Pythagorean Theorem,...
. Write a program which encodes any string using the XOR instruction.  Test it using your <first...
. Write a program which encodes any string using the XOR instruction.  Test it using your <first name last name> in the data segment to produce cipher text and then decode using the program to get plain text.  Use the last two digits of your student id as the key.  Print plane text from the data segment, print the cipher text, and then print the plain text upon execution.  Submit the asm/list file and screenshots that shows the output of your code. What are...
Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
You will write a single class named WordsXX- replace the XX's with your initials. The program...
You will write a single class named WordsXX- replace the XX's with your initials. The program will have 2 overloaded methods named wordMaker. They will have to be declared as static. Both methods will not have a return type but they will print some text. The first method wordMaker signature will not accept any parameters and when invoked will simply print out the line "lower case words". The second overloaded wordMaker method will accept an integer and print "Words in...
You will write a single class named WordsXX- replace the XX's with your initials. The program...
You will write a single class named WordsXX- replace the XX's with your initials. The program will have 2 overloaded methods named wordMaker. They will have to be declared as static. Both methods will not have a return type but they will print some text. The first method wordMaker signature will not accept any parameters and when invoked will simply print out the line "lower case words". The second overloaded wordMaker method will accept an integer and print "Words in...
Write a program (name it firstMiddleLast _yourInitials.java (yourInitials represents your initials) that will: 1. Ask the...
Write a program (name it firstMiddleLast _yourInitials.java (yourInitials represents your initials) that will: 1. Ask the user (include appropriate dialog) to enter their: first name middle name last name save each of the above as a String variable as follows: firstName middleName lastName 2. Print to the screen the number of characters in each of the names (first, middle and last) 3. Print to the screen total number of characters in all three names. Include appropriate dialog in your output....
Write the simplest program possible in your language of choice containing your 'main' and any other...
Write the simplest program possible in your language of choice containing your 'main' and any other functions you may need that will: A. Read a sequence of words up to a maximum of 64 words from std input. Before reading the input, prompt the user to enter the words. B. Check to see if there any duplicate words in the input read. C. If there are no duplicates, print out to std output the message 'No Duplicates'. D. If there...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT