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 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...
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 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.
In JAVA Write a brief program that writes your name to a file in text format...
In JAVA Write a brief program that writes your name to a file in text format and then reads it back. Use the PrintWriter and Scanner classes.
2. Write a program which reads in the text file generated in part one and writes...
2. Write a program which reads in the text file generated in part one and writes out the same data as a comma-separated values (CSV) file for further processing. The file should have a header line which identifies which column contains which values and should look something like this: Time, Potentiometer, Temperature, Light, Switch0, Switch1, Switch2, Switch3 That header line should be followed by detail lines containing the measurements and should look something like this (matching the above Arduino output):...
Using energia software Write a program for your MSP430 board to will perform the following three...
Using energia software Write a program for your MSP430 board to will perform the following three tasks: 1. Input: Take a character string as user input through the serial interface. 2. Processing: Convert the entire string to lower case, and 3. Output: Return the processed string to serial output, which will be displayed on your computer monitor. Example: If the input character string is, “Here I am”, the output should be, “here i am”. For serial input and output purpose,...
Engstrom Manufacturing (which applied overhead to product using a predetermined overhead rate and writes any over...
Engstrom Manufacturing (which applied overhead to product using a predetermined overhead rate and writes any over or underapplied overhead off to cost of goods sold) reports the following for the year ended 12-31-2016. Inventories: Beg. Raw Material $         12,000 End Raw Material $         18,000 Beg. WIP $         42,000 End WIP $         35,000 Beg. Finished Goods $         66,000 End Finished Goods $         77,500 Other: Direct Labor - cost $         67,200 Direct Labor - hours               5,600 Manufacturing Overhead (actual) $         43,650...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT