Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # t_morphing.py ZZZ
- vectors = {
- '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)],
- '0': [(0,1),(0,0),(1,0),(1,1),(0,1)],
- '1': [(1,0),(1,1)],
- '2': [(0,1),(1,1),(1,.5),(0,.5),(0,0),(1,0)],
- '3': [(0,1),(1,1),(1,.5),(0,.5),(1,.5),(1,0),(0,0)],
- '4': [(0,1),(0,.5),(1,.5),(1,1),(1,0)],
- '5': [(0,1),(1,1),(0,1),(0,.5),(1,.5),(1,0),(0,0)],
- '6': [(0,1),(1,1),(0,1),(0,0),(1,0),(1,.5),(0,.5)],
- '7': [(0,1),(1,1),(1,0)],
- '8': [(0,1),(0,0),(1,0),(1,1),(0,1),(0,.5),(1,.5)],
- '9': [(0,1),(1,1),(1,.5),(0,.5),(0,1),(1,1),(1,0),(0,0)]
- }
- import turtle
- from time import sleep
- myPen = turtle.Turtle()
- myPen.hideturtle()
- myPen.tracer(0)
- myPen.speed(0)
- window = turtle.Screen()
- window.bgcolor("#000000")
- myPen.pensize(4)
- def morphing(keyA,keyB,t,fontSize,color,x,y):
- myPen.color(color)
- keyA=keyA.upper()
- keyB=keyB.upper()
- myPen.penup()
- myPen.goto(x,y)
- myPen.pendown()
- #Check that the characters avail
- if keyA in vectors and keyB in vectors:
- keyACoordinates=vectors[keyA]
- keyBCoordinates=vectors[keyB]
- dots=[]
- #Some letters have more nodes than others. We need to ensure they have the same number of nodes
- if len(keyACoordinates)>len(keyBCoordinates):
- lastDot = keyBCoordinates[len(keyBCoordinates)-1]
- for i in range(0,len(keyACoordinates)-len(keyBCoordinates)):
- keyBCoordinates.append(lastDot)
- elif len(keyACoordinates)<len(keyBCoordinates):
- lastDot = keyACoordinates[len(keyACoordinates)-1]
- for i in range(0,len(keyBCoordinates)-len(keyACoordinates)):
- keyACoordinates.append(lastDot)
- numberOfDots = len(keyACoordinates)
- #Morphing Calculations
- #Calculate the new interim coordinates of each node
- for i in range(0,numberOfDots):
- dotx=keyACoordinates[i][0] + (keyBCoordinates[i][0]-keyACoordinates[i][0])*t/10
- doty=keyACoordinates[i][1] + (keyBCoordinates[i][1]-keyACoordinates[i][1])*t/10
- dots.append([dotx,doty])
- #Draw the resulting morphed character
- myPen.penup()
- for dot in dots:
- myPen.goto(x + dot[0]*fontSize, y + dot[1]*fontSize)
- myPen.pendown()
- #Main Program Starts Here
- fontSize = 200
- fontColor = "#FF00FF"
- DELTA_SIZE = 4
- FONT = ("Ariel", 60, "italic")
- t = ord('A')
- ALL_KEYS = [chr(z) for z in range(t,t+26)] + [str(z) for z in range(0,10)]
- while 1:
- all_keys = ALL_KEYS[:]
- keyA = 'A'
- while all_keys:
- keyB = all_keys.pop(0)
- for t in range(0,11):
- myPen.clear()
- morphing(keyA,keyB,t,fontSize,fontColor,-100,-100)
- sleep(0.05)
- myPen.getscreen().update()
- myPen.goto(-200, 100)
- myPen.write(keyB, move=True, font=FONT)
- sleep(0.5)
- keyA = keyB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement