-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAula10_2.py
75 lines (60 loc) · 1.89 KB
/
Aula10_2.py
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
# -*- coding: latin-1 -*-
import pygame, sys
import numpy as np
from pygame.locals import *
pygame.init()
fpsClock=pygame.time.Clock()
FPS = 3 #num segundos
pygame.display.set_caption("10_2-Translation")
DISPLAYSURF = pygame.display.set_mode((800,600))
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
ARESTA=50
centroX=DISPLAYSURF.get_width()/2
centroY=DISPLAYSURF.get_height()/2
#1
p0 = [centroX, centroY - ARESTA/2]
p1 = [centroX-ARESTA, centroY + ARESTA ]
p2 = [centroX+ARESTA, centroY + ARESTA ]
#--Função desenha_triangulo---------------------------------
def desenha_triangulo(ponto0, ponto1, ponto2, cor):
pygame.draw.line(DISPLAYSURF, cor, ponto0, ponto1, 1)
pygame.draw.line(DISPLAYSURF, cor, ponto1, ponto2, 1)
pygame.draw.line(DISPLAYSURF, cor, ponto2, ponto0, 1)
return
#------------------------------------------------------------
#--Função translação-----------------------------------------
def translacao(ponto, dx, dy):
#x'=x+dx
#y'=y+dy
###Forma linear
#ponto_retorno=(0,0)
#ponto_retorno=(ponto[0]+dx, ponto[1]+dy)
#return ponto_retorno
###Forma matricial
mTrans=[dx,dy]
res=np.add(mTrans,ponto)
return (res[0], res[1])
#------------------------------------------------------------
desenha_triangulo(p0, p1, p2, WHITE)
#1
#Desloca -50,-50
pt0=translacao(p0,-50,-50)
pt1=translacao(p1,-50,-50)
pt2=translacao(p2,-50,-50)
desenha_triangulo(pt0,pt1,pt2, RED)
#2
#Tranladação para origem
ponto_central = ((p0[0]+p1[0]+p2[0])/3, (p0[1]+p1[1]+p2[1])/3)
pt0=translacao(p0,-1*ponto_central[0],-1*ponto_central[1])
pt1=translacao(p1,-1*ponto_central[0],-1*ponto_central[1])
pt2=translacao(p2,-1*ponto_central[0],-1*ponto_central[1])
desenha_triangulo(pt0,pt1,pt2, GREEN)
pygame.display.update()
while True: #Main loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()