Python coding

profilebiju
assignment2-bizoree-rahmotullah.zip

turtle_Rahmotullah/alphabet.py

alphabet = { 'A': ((0,0),(0.5,1),(0.75,0.5),(0.25,0.5),(0.75,0.5),(1,0)), 'B': ((0,0),(0,1),(0.625 ,1),(0.75,0.875),(0.75,0.625),(0.625,0.5),(0,0.5),(0.625,0.5),(0.75,0.375),(0.75,0.125),(0.625,0),(0,0)), 'C': ((0.75,0.125),(0.625,0),(0.125,0),(0,0.125),(0,0.875),(0.125,1),(0.625,1),(0.75,0.875)), 'D': ((0,0),(0,1),(0.625 ,1),(0.75,0.875),(0.75,0.125),(0.625,0),(0,0)), 'E': ((0.75,0),(0,0),(0,0.5),(0.75,0.5),(0,0.5),(0,1),(0.75,1)), 'F': ((0,0),(0,0.5),(0.75,0.5),(0,0.5),(0,1),(0.75,1)), 'G': ((0.75,0.5),(0.625,0.5),(0.75,0.5),(0.75,0.125),(0.625,0),(0.125,0),(0,0.125),(0,0.875),(0.125,1),(0.625,1),(0.75,0.875)), 'H': ((0,0),(0,1),(0,0.5),(0.75,0.5),(0.75,1),(0.75,0)), 'I': ((0,0),(0.25,0),(0.125,0),(0.125,1),(0,1),(0.25,1)), 'J': ((0,0.125),(0.125,0),(0.375,0),(0.5,0.125),(0.5,1)), 'K': ((0,0),(0,1),(0,0.5),(0.75,1),(0,0.5),(0.75,0)), 'L': ((0,0),(0,1),(0,0),(0.75,0)), 'M': ((0,0),(0,1),(0.5,0),(1,1),(1,0)), 'N': ((0,0),(0,1),(0.75,0),(0.75,1)), 'O': ((0.75,0.125),(0.625,0),(0.125,0),(0,0.125),(0,0.875),(0.125,1),(0.625,1),(0.75,0.875),(0.75,0.125)), 'P': ((0,0),(0,1),(0.625,1),(0.75,0.875),(0.75,0.625),(0.625,0.5),(0,0.5)), 'Q': ((0.75,0.125),(0.625,0),(0.125,0),(0,0.125),(0,0.875),(0.125,1),(0.625,1),(0.75,0.875),(0.75,0.125),(0.875,0)), 'R': ((0,0),(0,1),(0.625,1),(0.75,0.875),(0.75,0.625),(0.625,0.5),(0,0.5),(0.625,0.5),(0.875,0)), 'S': ((0,0.125),(0.125,0),(0.625,0),(0.75,0.125),(0.75,0.375),(0.675,0.5),(0.125,0.5),(0,0.625),(0,0.875),(0.125,1),(0.625,1),(0.75,0.875)), 'T': ((0,1),(0.5,1),(0.5,0),(0.5,1),(1,1)), 'U': ((0,1),(0,0.125),(0.125,0),(0.625,0),(0.75,0.125),(0.75,1)), 'V': ((0,1),(0.375,0),(0.75,1)), 'W': ((0,1),(0.25,0),(0.5,1),(0.75,0),(1,1)), 'X': ((0,0),(0.375,0.5),(0,1),(0.375,0.5),(0.75,1),(0.375,0.5),(0.75,0)), 'Y': ((0,1),(0.375,0.5),(0.375,0),(0.375,0.5),(0.75,1)), 'Z': ((0,1),(0.75,1),(0,0),(0.75,0)), }

turtle_Rahmotullah/main.py

#Python program to use Turtle to write name entered by the user on the screen import turtle import random from alphabet import alphabet from math import cos, sin, atan2, radians, degrees myPen = turtle.Turtle() myPen.hideturtle() myPen.speed(0) window = turtle.Screen() window.bgcolor("#FFFF89") myPen.pensize(2) def printName(name_str,fontSize,color,x,y,rotationAngle): myPen.color(color) name_str=name_str.upper() myPen.penup() myPen.goto(x,y) for character in name_str: if character in alphabet: letter=alphabet[character] myPen.setheading(rotationAngle) myPen.penup() x=0 y=0 for dot in letter: angle = atan2((dot[1]-y),(dot[0]-x)) angle= degrees(angle) distance = ((dot[0]-x)**2 + (dot[1]-y)**2)**0.5 myPen.setheading(rotationAngle) myPen.left(angle) myPen.forward(distance*fontSize) x = dot[0] y = dot[1] myPen.pendown() myPen.penup() angle = atan2((0-y),(0-x)) angle = degrees(angle) distance = ((0-x)**2 + (0-y)**2)**0.5 myPen.setheading(rotationAngle) myPen.left(angle) myPen.forward(distance*fontSize) myPen.setheading(rotationAngle) myPen.penup() myPen.forward(fontSize) myPen.forward(characterSpacing) #Main Program Starts Here fontSize = 40 fontColor="#BB00CC" characterSpacing = 4 name_str = input("Enter your name here") printName(name_str,fontSize,fontColor,-300,-100,0)

Application_Rahmotullah/archery.py

import turtle import random def target(size): turtle.goto(0,0) rings = 10 turtle.penup() turtle.pencolor("green") ringColors = ("white", "white", "black", "black", "blue", "blue", "red", "red", "yellow", "yellow") while rings > 0: r = int(rings / 10 * size) # calculate radius for each ring turtle.forward(r) turtle.pendown() # start drawing turtle.left(90) turtle.fillcolor(ringColors[10 - rings]) turtle.begin_fill() turtle.circle(r, 360) # draw and fill circle turtle.end_fill() turtle.penup() # no draw when moving turtle.left(90) turtle.forward(r) turtle.left(180) # back to (0,0), same direction rings -= 1 def shoot(range): turtle.penup() xpos = random.randint(-range, range) # get random x position ypos = random.randint(-range, range) # get random y position turtle.goto(xpos, ypos) turtle.dot(10,"green") # draw the dot where archer is set distance = turtle.distance(0,0) # calculate distance from the shot to (0,0) return distance def score(distance, radius): if (distance > radius): # out of target return 0 return int(11 - 10 * distance / radius) # in target def displayScore(score, ntry, xpos, ypos): turtle.goto(xpos, ypos) turtle.write(str(ntry) + " try: " + str(score), True, "center", font=("Arial", 14, "normal")) # MAIN Program def main(): # hide turtle turtle.hideturtle() # set turtle speed turtle.speed(20) # draw target radius = 150 target(radius) # draw title turtle.goto(0, radius + 50) turtle.write("TARGET GAME", True, "center", font=("Arial", 14, "bold")) # three shot sum = 0 for i in (1, 2, 3): d = shoot(radius) s = score(d, radius) sum += s displayScore(s, i, 0 , -radius - 50 - i*20) turtle.goto(0,0 -radius - 50 - 4*20) turtle.write("Sum score = " + str(sum), True, "center", font=("Arial", 14, "bold")) # pause to view, exit when user click on the screen turtle.exitonclick() # call function main to run program main()