forked from virtualeiro/p5-imfvj1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAula11_4.py
56 lines (43 loc) · 1.13 KB
/
Aula11_4.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
#VERSAO P5
"""
from p5 import *
import numpy as np
v_pos=[400,300]
def setup():
size(800,600)
def draw():
global v_pos
background(0)
target=[mouse_x,mouse_y]
v_dir=np.subtract(target,v_pos)
v_dir_normalized = v_dir/np.linalg.norm(v_dir)
v_dir_normalized=np.multiply(v_dir_normalized,8)
v_pos=np.add(v_pos,v_dir_normalized)
circle( v_pos, 40)
run()
"""
#VERSAO PYGAME
#VERSAO PYGAME
import pygame, sys
import numpy as np
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((800,600))
fpsClock=pygame.time.Clock()
FPS = 15 #num segundos
v_pos=[400,300]
while True: #Main loop--
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
screen.fill((255,255,255))
mouse = pygame.mouse.get_pos()
target=[mouse[0],mouse[1]]
v_dir=np.subtract(target,v_pos)
v_dir_normalized = v_dir/np.linalg.norm(v_dir)
v_dir_normalized=v_dir_normalized*8
v_pos=np.add(v_pos,v_dir_normalized)
pygame.draw.circle( screen, (255,0,0), v_pos, 10)
pygame.display.update()
fpsClock.tick(FPS)