File size: 4,130 Bytes
83e35a7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
import math
import numpy as np
class panel:
def __init__(self,image,row_span,col_span,metadata=None):
self.image = image
self.row_span = row_span
self.col_span = col_span
self.metadata = metadata or {}
# class bubble:
# def __init__(self,bubble_offset_x,bubble_offset_y,lip_x,lip_y,dialog):
# bubble_width=200
# bubble_height=94
# tail_centre_x=100
# tail_centre_y=47
# self.dialog = dialog
# self.bubble_offset_x = bubble_offset_x
# self.bubble_offset_y = bubble_offset_y
# temp = 0
# angle = 0
# try:
# temp = math.degrees(math.atan((bubble_offset_y-lip_y) / (bubble_offset_x-lip_x)))
# except ZeroDivisionError:
# temp = 45
# if(bubble_offset_y>lip_y):
# # tail top
# if(bubble_offset_x>lip_x):
# #tail left
# angle=180-temp
# elif(bubble_offset_x<lip_x):
# #tail right
# angle=180-temp
# elif(bubble_offset_y<=lip_y):
# #tail bottom
# if(bubble_offset_x>lip_x):
# #tail left
# angle=-temp
# elif(bubble_offset_x<lip_x):
# #tail right
# angle=360-temp
# print(angle)
# tail_offset_x = None
# tail_offset_y = None
# self.tail_deg=angle
# if(bubble_offset_y>lip_y):
# # tail top
# if(bubble_offset_x>lip_x):
# #tail left
# tail_offset_x=tail_centre_x-50
# tail_offset_y=tail_centre_y-23
# elif(bubble_offset_x<lip_x):
# #tail right
# tail_offset_x=tail_centre_x+50
# tail_offset_y=tail_centre_y-23
# elif(bubble_offset_y<=lip_y):
# #tail bottom
# if(bubble_offset_x>lip_x):
# #tail left
# tail_offset_x=tail_centre_x-50
# tail_offset_y=tail_centre_y+23
# elif(bubble_offset_x<lip_x):
# #tail right
# tail_offset_x=tail_centre_x+50
# tail_offset_y=tail_centre_y+23
# self.tail_offset_x = tail_offset_x
# self.tail_offset_y = tail_offset_y
class bubble:
def __init__(self,bubble_offset_x,bubble_offset_y,lip_x,lip_y,dialog,emotion):
bubble_width=200
bubble_height=94
tail_centre_x=100
tail_centre_y=47
self.dialog = dialog
self.emotion = emotion
self.bubble_offset_x = bubble_offset_x
self.bubble_offset_y = bubble_offset_y
angle = 0
print(f"lipx = {lip_x} and lipy = {lip_y}")
# If lip wasn't detected
if(lip_x==-1 and lip_y == -1):
angle = 0
self.tail_offset_x = None
self.tail_offset_y = None
else:
dx = lip_x - bubble_offset_x
dy = lip_y - bubble_offset_y
angle = np.arctan2(dy, dx)
print(angle)
tail_offset_x = None
tail_offset_y = None
self.tail_deg=np.degrees(angle)
self.tail_offset_x = 80 * np.cos(angle)
self.tail_offset_y = 80 * np.sin(angle)
class Page:
def __init__(self,panels,bubbles,metadata=None):
self.panels = []
self.bubbles = []
self.metadata = metadata or {}
for i in range(len(panels)):
self.panels.append(panels[i].__dict__)
if i < len(bubbles):
self.bubbles.append(bubbles[i].__dict__)
else:
# Fallback placeholder bubble to keep indices aligned with panels
self.bubbles.append({
'dialog': '((action-scene))',
'emotion': 'normal',
'bubble_offset_x': 0,
'bubble_offset_y': 0,
'tail_deg': 0,
'tail_offset_x': None,
'tail_offset_y': None
}) |