Advertisement
here2share

# t_morphing.py ZZZ

Feb 12th, 2021
1,374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.45 KB | None | 0 0
  1. # t_morphing.py ZZZ
  2.  
  3. vectors = {
  4.         'A': [(0,0),(0.5,1),(0.75,0.5),(0.25,0.5),(0.75,0.5),(1,0)],
  5.         '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)],
  6.         '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)],
  7.         'D': [(0,0),(0,1),(0.625 ,1),(0.75,0.875),(0.75,0.125),(0.625,0),(0,0)],
  8.         'E': [(0.75,0),(0,0),(0,0.5),(0.75,0.5),(0,0.5),(0,1),(0.75,1)],
  9.         'F': [(0,0),(0,0.5),(0.75,0.5),(0,0.5),(0,1),(0.75,1)],
  10.         '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)],
  11.         'H': [(0,0),(0,1),(0,0.5),(0.75,0.5),(0.75,1),(0.75,0)],
  12.         'I': [(0,0),(0.25,0),(0.125,0),(0.125,1),(0,1),(0.25,1)],
  13.         'J': [(0,0.125),(0.125,0),(0.375,0),(0.5,0.125),(0.5,1)],
  14.         'K': [(0,0),(0,1),(0,0.5),(0.75,1),(0,0.5),(0.75,0)],
  15.         'L': [(0,0),(0,1),(0,0),(0.75,0)],
  16.         'M': [(0,0),(0,1),(0.5,0),(1,1),(1,0)],
  17.         'N': [(0,0),(0,1),(0.75,0),(0.75,1)],
  18.         '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)],
  19.         'P': [(0,0),(0,1),(0.625,1),(0.75,0.875),(0.75,0.625),(0.625,0.5),(0,0.5)],
  20.         '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)],
  21.         '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)],
  22.         '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)],
  23.         'T': [(0,1),(0.5,1),(0.5,0),(0.5,1),(1,1)],
  24.         'U': [(0,1),(0,0.125),(0.125,0),(0.625,0),(0.75,0.125),(0.75,1)],
  25.         'V': [(0,1),(0.375,0),(0.75,1)],
  26.         'W': [(0,1),(0.25,0),(0.5,1),(0.75,0),(1,1)],
  27.         'X': [(0,0),(0.375,0.5),(0,1),(0.375,0.5),(0.75,1),(0.375,0.5),(0.75,0)],
  28.         'Y': [(0,1),(0.375,0.5),(0.375,0),(0.375,0.5),(0.75,1)],
  29.         'Z': [(0,1),(0.75,1),(0,0),(0.75,0)],
  30.         '0': [(0,1),(0,0),(1,0),(1,1),(0,1)],
  31.         '1': [(1,0),(1,1)],
  32.         '2': [(0,1),(1,1),(1,.5),(0,.5),(0,0),(1,0)],
  33.         '3': [(0,1),(1,1),(1,.5),(0,.5),(1,.5),(1,0),(0,0)],
  34.         '4': [(0,1),(0,.5),(1,.5),(1,1),(1,0)],
  35.         '5': [(0,1),(1,1),(0,1),(0,.5),(1,.5),(1,0),(0,0)],
  36.         '6': [(0,1),(1,1),(0,1),(0,0),(1,0),(1,.5),(0,.5)],
  37.         '7': [(0,1),(1,1),(1,0)],
  38.         '8': [(0,1),(0,0),(1,0),(1,1),(0,1),(0,.5),(1,.5)],
  39.         '9': [(0,1),(1,1),(1,.5),(0,.5),(0,1),(1,1),(1,0),(0,0)]
  40. }
  41.  
  42. import turtle
  43. from time import sleep
  44.  
  45. myPen = turtle.Turtle()
  46. myPen.hideturtle()
  47. myPen.tracer(0)
  48. myPen.speed(0)
  49. window = turtle.Screen()
  50. window.bgcolor("#000000")
  51. myPen.pensize(4)
  52.  
  53. def morphing(keyA,keyB,t,fontSize,color,x,y):
  54.     myPen.color(color)
  55.     keyA=keyA.upper()
  56.     keyB=keyB.upper()
  57.     myPen.penup()
  58.     myPen.goto(x,y)
  59.     myPen.pendown()
  60.    
  61.     #Check that the characters avail
  62.     if keyA in vectors and keyB in vectors:
  63.             keyACoordinates=vectors[keyA]
  64.             keyBCoordinates=vectors[keyB]
  65.            
  66.             dots=[]
  67.            
  68.             #Some letters have more nodes than others. We need to ensure they have the same number of nodes
  69.             if len(keyACoordinates)>len(keyBCoordinates):
  70.                 lastDot = keyBCoordinates[len(keyBCoordinates)-1]
  71.                 for i in range(0,len(keyACoordinates)-len(keyBCoordinates)):
  72.                     keyBCoordinates.append(lastDot)
  73.             elif len(keyACoordinates)<len(keyBCoordinates):
  74.                 lastDot = keyACoordinates[len(keyACoordinates)-1]
  75.                 for i in range(0,len(keyBCoordinates)-len(keyACoordinates)):
  76.                     keyACoordinates.append(lastDot)
  77.            
  78.             numberOfDots = len(keyACoordinates)
  79.  
  80.             #Morphing Calculations
  81.             #Calculate the new interim coordinates of each node
  82.             for i in range(0,numberOfDots):
  83.                 dotx=keyACoordinates[i][0] + (keyBCoordinates[i][0]-keyACoordinates[i][0])*t/10
  84.                 doty=keyACoordinates[i][1] + (keyBCoordinates[i][1]-keyACoordinates[i][1])*t/10
  85.                 dots.append([dotx,doty])
  86.                
  87.             #Draw the resulting morphed character
  88.             myPen.penup()
  89.             for dot in dots:
  90.                 myPen.goto(x + dot[0]*fontSize, y + dot[1]*fontSize)
  91.                 myPen.pendown()
  92.                
  93.  
  94. #Main Program Starts Here
  95. fontSize = 200
  96. fontColor = "#FF00FF"
  97. DELTA_SIZE = 4
  98. FONT = ("Ariel", 60, "italic")
  99.  
  100. t = ord('A')
  101. ALL_KEYS = [chr(z) for z in range(t,t+26)] + [str(z) for z in range(0,10)]
  102.  
  103. while 1:
  104.     all_keys = ALL_KEYS[:]
  105.     keyA = 'A'
  106.     while all_keys:
  107.         keyB = all_keys.pop(0)
  108.         for t in range(0,11):
  109.             myPen.clear()
  110.             morphing(keyA,keyB,t,fontSize,fontColor,-100,-100)
  111.             sleep(0.05)
  112.             myPen.getscreen().update()
  113.         myPen.goto(-200, 100)
  114.         myPen.write(keyB, move=True, font=FONT)
  115.         sleep(0.5)
  116.         keyA = keyB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement