-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interface.py
75 lines (64 loc) · 3.01 KB
/
Interface.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
69
70
71
72
73
74
75
import wireframe
import pygame
import os
import numpy as np
class EnvironmentViewer:
#displays 3D objects on a 2D Pygame screen
def __init__(self, width, height):
self.width = width
self.height = height
self.screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Environment Display')
self.background = (100,100,100)
self.wireframes = {}
self.displayNodes = True
self.hub_im_size = (75,75)
self.drone_im_size = (70,70)
self.drone_size_list = [0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1]
self.package_im_size = (50,50)
self.package_size_list = [0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1]
self.flag_im_size = (35,50)
self.flag_size_list = [0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1]
def addWireframe(self, name, wireframe):
#add a named wireframe object
self.wireframes[name] = wireframe
def run(self):
#create a pygame screen until it is closed
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
self.display()
def display(self):
#draw the wireframes on the screen
self.screen.fill(self.background)
im_path = os.getcwd()
for wireframe in self.wireframes.values():
temp_path = os.getcwd()
for node in wireframe.nodes:
if node.type == 0: # HUB
im_path = temp_path+'\\images\\hub.png'
Image = pygame.image.load(im_path)
Image = pygame.transform.scale(Image, self.hub_im_size)
elif node.type == 3:
im_path = temp_path+'\\images\\flag.png'
mult = self.flag_size_list[node.real_z]
im_size = tuple(mult*np.array(self.flag_im_size))
Image = pygame.image.load(im_path)
Image = pygame.transform.scale(Image, im_size)
elif node.type == 2: # PACKAGE
im_path = temp_path+'\\images\\package.png'
mult = self.package_size_list[node.real_z]
im_size = tuple(mult*np.array(self.package_im_size))
Image = pygame.image.load(im_path)
Image = pygame.transform.scale(Image, im_size)
elif node.type == 1: # DRONE
im_path = temp_path+'\\images\\drone.png'
mult = self.drone_size_list[node.real_z]
im_size = tuple(mult*np.array(self.drone_im_size))
Image = pygame.image.load(im_path)
Image = pygame.transform.scale(Image, im_size)
self.screen.blit(Image, (node.x,node.y))
# update the display with the new coordinates
pygame.display.flip()