fin de séance (?)

This commit is contained in:
Laureηt 2022-12-09 15:36:13 +01:00
parent 51a42e0b4b
commit 67235084b7
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
8 changed files with 34 additions and 24 deletions

1
.vscode/launch.json vendored
View file

@ -6,6 +6,7 @@
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/main.py",
// "program": "${workspaceFolder}/bite.py",
"console": "integratedTerminal",
"justMyCode": true,
"env": {

View file

@ -27,12 +27,12 @@ class Body:
texture_scaled = pg.transform.scale(
self.texture,
(300, 200),
self.env.size,
)
texture_pos = body_pos - pg.Vector2(
150,
25,
self.env.size[0] / 2,
self.env.size[1] / 10,
)
# draw texture

View file

@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
import pygame as pg
from utils import landmark2vec
from utils import blitRotate, landmark2vec
if TYPE_CHECKING:
from environment import Environment
@ -23,18 +23,11 @@ class Crown:
if self.env.results.multi_face_landmarks:
for face_landmarks in self.env.results.multi_face_landmarks:
# head_top = landmark2vec(face_landmarks.landmark[LANDMARKS[1]], screen)
# head_bottom = landmark2vec(face_landmarks.landmark[LANDMARKS[3]], screen)
# angle = (head_bottom - head_top).angle_to(pg.Vector2(0, 1))
# height = (head_bottom - head_top).length()
# ratio = self.texture.get_width() / self.texture.get_height()
crown_pos = landmark2vec(face_landmarks.landmark[LANDMARKS[0]], screen)
texture_scaled = pg.transform.scale(
self.texture,
(100, 100),
(self.env.size[0] / 3, self.env.size[1] / 3),
)
texture_pos = crown_pos - pg.Vector2(
@ -43,4 +36,4 @@ class Crown:
)
# draw texture
screen.blit(texture_scaled, texture_pos)
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)

View file

@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
import pygame as pg
from utils import landmark2vec
from utils import blitRotate, landmark2vec
if TYPE_CHECKING:
from environment import Environment
@ -30,7 +30,7 @@ class Ear:
texture_scaled = pg.transform.scale(
self.texture,
(100, 250),
(self.env.size[0] / 3, self.env.size[1]),
)
if self.side: # right moustache
@ -50,4 +50,4 @@ class Ear:
)
# draw texture
screen.blit(texture_scaled, texture_pos)
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)

View file

@ -27,14 +27,18 @@ class Head:
head_bottom = landmark2vec(face_landmarks.landmark[LANDMARKS[3]], screen)
angle = (head_bottom - head_top).angle_to(pg.Vector2(0, 1))
self.env.angle = angle
height = (head_bottom - head_top).length()
ratio = self.texture.get_width() / self.texture.get_height()
self.env.size = (height * ratio, height)
head_pos = (head_bottom + head_top) / 2
texture_scaled = pg.transform.scale(
self.texture,
(height * ratio, height),
self.env.size,
)
texture_pos = head_pos - pg.Vector2(
@ -43,4 +47,4 @@ class Head:
)
# draw texture
blitRotate(screen, texture_scaled, texture_pos, angle)
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)

View file

@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
import pygame as pg
from utils import landmark2vec
from utils import blitRotate, landmark2vec
if TYPE_CHECKING:
from environment import Environment
@ -30,7 +30,7 @@ class Moustache:
texture_scaled = pg.transform.scale(
self.texture,
(200, 100),
(self.env.size[0] / 1.5, self.env.size[1] / 1.5),
)
if self.side: # right moustache
@ -50,4 +50,4 @@ class Moustache:
)
# draw texture
screen.blit(texture_scaled, texture_pos)
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)

View file

@ -10,12 +10,15 @@ if TYPE_CHECKING:
from environment import Environment
LANDMARKS = [78, 13, 308, 14]
MIN_HEIGHT = 4
class Mouth:
def __init__(self, env: Environment) -> None:
self.env = env
self.texture = pg.image.load("assets/mouth.png").convert_alpha()
self.closed_texture = pg.image.load("assets/mouth.png").convert_alpha()
self.closed_texture.fill((0, 0, 0, 255), special_flags=pg.BLEND_RGBA_MULT)
def draw(self, screen) -> None:
@ -29,14 +32,19 @@ class Mouth:
mouth_left = landmark2vec(face_landmarks.landmark[LANDMARKS[0]], screen)
mouth_right = landmark2vec(face_landmarks.landmark[LANDMARKS[2]], screen)
angle = (mouth_bottom - mouth_top).angle_to(pg.Vector2(0, 1))
height = (mouth_bottom - mouth_top).length()
width = (mouth_right - mouth_left).length()
head_pos = (mouth_bottom + mouth_top) / 2
if height < MIN_HEIGHT:
height = MIN_HEIGHT
texture = self.closed_texture
else:
texture = self.texture
texture_scaled = pg.transform.scale(
self.texture,
texture,
(width, height),
)
@ -46,4 +54,4 @@ class Mouth:
)
# draw texture
blitRotate(screen, texture_scaled, texture_pos, angle)
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)

View file

@ -46,6 +46,9 @@ class Environment:
) # type: ignore
pg.display.set_caption("Projet APP")
self.angle = 0.0
self.size = (0.0, 0.0)
# create body parts
self.body_parts = {
"body": Body(self),
@ -139,6 +142,7 @@ class Environment:
for part in self.body_parts.values():
part.draw(self.screen)
# self.screen.blit(pg.transform.flip(self.screen, False, False), (0, 0))
self.screen.blit(pg.transform.flip(self.screen, True, False), (0, 0))
pg.display.flip()