| 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 | |
| }) |