fin de séance (?)
This commit is contained in:
parent
51a42e0b4b
commit
67235084b7
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -6,6 +6,7 @@
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/src/main.py",
|
"program": "${workspaceFolder}/src/main.py",
|
||||||
|
// "program": "${workspaceFolder}/bite.py",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"justMyCode": true,
|
"justMyCode": true,
|
||||||
"env": {
|
"env": {
|
||||||
|
|
|
@ -27,12 +27,12 @@ class Body:
|
||||||
|
|
||||||
texture_scaled = pg.transform.scale(
|
texture_scaled = pg.transform.scale(
|
||||||
self.texture,
|
self.texture,
|
||||||
(300, 200),
|
self.env.size,
|
||||||
)
|
)
|
||||||
|
|
||||||
texture_pos = body_pos - pg.Vector2(
|
texture_pos = body_pos - pg.Vector2(
|
||||||
150,
|
self.env.size[0] / 2,
|
||||||
25,
|
self.env.size[1] / 10,
|
||||||
)
|
)
|
||||||
|
|
||||||
# draw texture
|
# draw texture
|
||||||
|
|
|
@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import pygame as pg
|
import pygame as pg
|
||||||
|
|
||||||
from utils import landmark2vec
|
from utils import blitRotate, landmark2vec
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from environment import Environment
|
from environment import Environment
|
||||||
|
@ -23,18 +23,11 @@ class Crown:
|
||||||
if self.env.results.multi_face_landmarks:
|
if self.env.results.multi_face_landmarks:
|
||||||
for face_landmarks in 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)
|
crown_pos = landmark2vec(face_landmarks.landmark[LANDMARKS[0]], screen)
|
||||||
|
|
||||||
texture_scaled = pg.transform.scale(
|
texture_scaled = pg.transform.scale(
|
||||||
self.texture,
|
self.texture,
|
||||||
(100, 100),
|
(self.env.size[0] / 3, self.env.size[1] / 3),
|
||||||
)
|
)
|
||||||
|
|
||||||
texture_pos = crown_pos - pg.Vector2(
|
texture_pos = crown_pos - pg.Vector2(
|
||||||
|
@ -43,4 +36,4 @@ class Crown:
|
||||||
)
|
)
|
||||||
|
|
||||||
# draw texture
|
# draw texture
|
||||||
screen.blit(texture_scaled, texture_pos)
|
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)
|
||||||
|
|
|
@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import pygame as pg
|
import pygame as pg
|
||||||
|
|
||||||
from utils import landmark2vec
|
from utils import blitRotate, landmark2vec
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from environment import Environment
|
from environment import Environment
|
||||||
|
@ -30,7 +30,7 @@ class Ear:
|
||||||
|
|
||||||
texture_scaled = pg.transform.scale(
|
texture_scaled = pg.transform.scale(
|
||||||
self.texture,
|
self.texture,
|
||||||
(100, 250),
|
(self.env.size[0] / 3, self.env.size[1]),
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.side: # right moustache
|
if self.side: # right moustache
|
||||||
|
@ -50,4 +50,4 @@ class Ear:
|
||||||
)
|
)
|
||||||
|
|
||||||
# draw texture
|
# draw texture
|
||||||
screen.blit(texture_scaled, texture_pos)
|
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)
|
||||||
|
|
|
@ -27,14 +27,18 @@ class Head:
|
||||||
head_bottom = landmark2vec(face_landmarks.landmark[LANDMARKS[3]], screen)
|
head_bottom = landmark2vec(face_landmarks.landmark[LANDMARKS[3]], screen)
|
||||||
|
|
||||||
angle = (head_bottom - head_top).angle_to(pg.Vector2(0, 1))
|
angle = (head_bottom - head_top).angle_to(pg.Vector2(0, 1))
|
||||||
|
self.env.angle = angle
|
||||||
|
|
||||||
height = (head_bottom - head_top).length()
|
height = (head_bottom - head_top).length()
|
||||||
ratio = self.texture.get_width() / self.texture.get_height()
|
ratio = self.texture.get_width() / self.texture.get_height()
|
||||||
|
|
||||||
|
self.env.size = (height * ratio, height)
|
||||||
|
|
||||||
head_pos = (head_bottom + head_top) / 2
|
head_pos = (head_bottom + head_top) / 2
|
||||||
|
|
||||||
texture_scaled = pg.transform.scale(
|
texture_scaled = pg.transform.scale(
|
||||||
self.texture,
|
self.texture,
|
||||||
(height * ratio, height),
|
self.env.size,
|
||||||
)
|
)
|
||||||
|
|
||||||
texture_pos = head_pos - pg.Vector2(
|
texture_pos = head_pos - pg.Vector2(
|
||||||
|
@ -43,4 +47,4 @@ class Head:
|
||||||
)
|
)
|
||||||
|
|
||||||
# draw texture
|
# draw texture
|
||||||
blitRotate(screen, texture_scaled, texture_pos, angle)
|
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)
|
||||||
|
|
|
@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import pygame as pg
|
import pygame as pg
|
||||||
|
|
||||||
from utils import landmark2vec
|
from utils import blitRotate, landmark2vec
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from environment import Environment
|
from environment import Environment
|
||||||
|
@ -30,7 +30,7 @@ class Moustache:
|
||||||
|
|
||||||
texture_scaled = pg.transform.scale(
|
texture_scaled = pg.transform.scale(
|
||||||
self.texture,
|
self.texture,
|
||||||
(200, 100),
|
(self.env.size[0] / 1.5, self.env.size[1] / 1.5),
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.side: # right moustache
|
if self.side: # right moustache
|
||||||
|
@ -50,4 +50,4 @@ class Moustache:
|
||||||
)
|
)
|
||||||
|
|
||||||
# draw texture
|
# draw texture
|
||||||
screen.blit(texture_scaled, texture_pos)
|
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)
|
||||||
|
|
|
@ -10,12 +10,15 @@ if TYPE_CHECKING:
|
||||||
from environment import Environment
|
from environment import Environment
|
||||||
|
|
||||||
LANDMARKS = [78, 13, 308, 14]
|
LANDMARKS = [78, 13, 308, 14]
|
||||||
|
MIN_HEIGHT = 4
|
||||||
|
|
||||||
|
|
||||||
class Mouth:
|
class Mouth:
|
||||||
def __init__(self, env: Environment) -> None:
|
def __init__(self, env: Environment) -> None:
|
||||||
self.env = env
|
self.env = env
|
||||||
self.texture = pg.image.load("assets/mouth.png").convert_alpha()
|
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:
|
def draw(self, screen) -> None:
|
||||||
|
|
||||||
|
@ -29,14 +32,19 @@ class Mouth:
|
||||||
mouth_left = landmark2vec(face_landmarks.landmark[LANDMARKS[0]], screen)
|
mouth_left = landmark2vec(face_landmarks.landmark[LANDMARKS[0]], screen)
|
||||||
mouth_right = landmark2vec(face_landmarks.landmark[LANDMARKS[2]], 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()
|
height = (mouth_bottom - mouth_top).length()
|
||||||
width = (mouth_right - mouth_left).length()
|
width = (mouth_right - mouth_left).length()
|
||||||
|
|
||||||
head_pos = (mouth_bottom + mouth_top) / 2
|
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(
|
texture_scaled = pg.transform.scale(
|
||||||
self.texture,
|
texture,
|
||||||
(width, height),
|
(width, height),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,4 +54,4 @@ class Mouth:
|
||||||
)
|
)
|
||||||
|
|
||||||
# draw texture
|
# draw texture
|
||||||
blitRotate(screen, texture_scaled, texture_pos, angle)
|
blitRotate(screen, texture_scaled, texture_pos, self.env.angle)
|
||||||
|
|
|
@ -46,6 +46,9 @@ class Environment:
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
pg.display.set_caption("Projet APP")
|
pg.display.set_caption("Projet APP")
|
||||||
|
|
||||||
|
self.angle = 0.0
|
||||||
|
self.size = (0.0, 0.0)
|
||||||
|
|
||||||
# create body parts
|
# create body parts
|
||||||
self.body_parts = {
|
self.body_parts = {
|
||||||
"body": Body(self),
|
"body": Body(self),
|
||||||
|
@ -139,6 +142,7 @@ class Environment:
|
||||||
for part in self.body_parts.values():
|
for part in self.body_parts.values():
|
||||||
part.draw(self.screen)
|
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))
|
self.screen.blit(pg.transform.flip(self.screen, True, False), (0, 0))
|
||||||
|
|
||||||
pg.display.flip()
|
pg.display.flip()
|
||||||
|
|
Loading…
Reference in a new issue