srodowisko update&reprezentacja wiedzy

This commit is contained in:
Anna Śmigiel 2022-03-24 20:02:21 +01:00
parent 39ffced97d
commit 4d5981b238
25 changed files with 210 additions and 107 deletions

View File

@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (AI_wozek_widlowy)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

45
Environment.py Normal file
View File

@ -0,0 +1,45 @@
import numpy as np
from Shelf import Shelf
from Grid import Grid
WINDOW_X = 1400
WINDOW_Y = 750
RECT_SIZE = 50
class Environment:
def __init__(self, window):
self.window = window
self.grid = Grid(self.window)
self.list_of_coordinates = self.compute_coordinates_of_shelves()
self.shelves = self.create_shelves()
# fills surface with color, draws grid&shelves
def draw_itself(self):
self.window.fill((70, 77, 87))
self.draw_shelves()
self.grid.draw_grid()
# computes shelves coordinates according to window size, might change later
def compute_coordinates_of_shelves(self):
y = 0
y1 = WINDOW_Y - 6*RECT_SIZE
arr = []
for x in range(2*RECT_SIZE, WINDOW_X - 2*RECT_SIZE, 3*RECT_SIZE):
arr.append(x)
arr.append(y)
arr.append(x)
arr.append(y1)
list_of_coordinates = np.array(arr).reshape(int(len(arr)/2), 2)
return list_of_coordinates
# creating list of shelves
def create_shelves(self):
shelves = []
for row in self.list_of_coordinates:
shelf = Shelf(self.window, row[0], row[1])
shelves.append(shelf)
return shelves
def draw_shelves(self):
for shelf in self.shelves:
shelf.draw()

22
Grid.py Normal file
View File

@ -0,0 +1,22 @@
import pygame
WINDOW_X = 1400
WINDOW_Y = 750
RECT_SIZE = 50
class Grid:
def __init__(self, window):
self.window = window
# function to draw a grid, it draws a line every 50px(RECT_SIZE) for both x and y axis
def draw_grid(self):
num_of_columns = int(WINDOW_X / RECT_SIZE)
num_of_rows = int(WINDOW_Y / RECT_SIZE)
x = 0
y = 0
for i in range(num_of_columns):
x += RECT_SIZE
pygame.draw.line(self.window, (255, 255, 255), (x, 0), (x, WINDOW_Y))
for i in range(num_of_rows):
y += RECT_SIZE
pygame.draw.line(self.window, (255, 255, 255), (0, y), (WINDOW_X, y))

30
Package.py Normal file
View File

@ -0,0 +1,30 @@
import numpy as np
import glob2
import pygame
import random
RECT_SIZE = 50
class Package:
def __init__(self, window):
self.window = window
self.length = np.random.randint(1, 3) * RECT_SIZE -1
self.width = RECT_SIZE-1
self.color = list(np.random.choice(range(256), size=3))
self.x = 1251
self.y = 351
# self.mark = random.choice(['fragile', 'dont turn around', 'keep dry', 'glass'])
self.mark_image = self.get_marking_photo()
self.block = pygame.Rect(self.x, self.y, self.width, self.length)
def get_marking_photo(self):
file_path_type = ["resources/package_markings/*.jpg"]
images = glob2.glob(random.choice(file_path_type))
random_image = random.choice(images)
print(random_image)
return random_image
def draw(self):
pygame.draw.rect(self.window, self.color, self.block)
pygame.display.flip()

36
Program.py Normal file
View File

@ -0,0 +1,36 @@
import pygame
from pygame.locals import *
from Truck import Truck
WINDOW_X = 1400
WINDOW_Y = 750
RECT_SIZE = 50
class Program:
def __init__(self):
pygame.init()
self.window = pygame.display.set_mode((WINDOW_X, WINDOW_Y)) # decides window's size
self.track = Truck(self.window)
self.track.draw()
def run(self):
running = True
while running:
for event in pygame.event.get(): # integrating with keyboard
if event.type == KEYDOWN:
if event.key == K_LEFT:
self.track.move_left()
if event.key == K_RIGHT:
self.track.move_right()
if event.key == K_UP:
self.track.move_up()
if event.key == K_DOWN:
self.track.move_down()
elif event.type == QUIT:
running = False

16
Shelf.py Normal file
View File

@ -0,0 +1,16 @@
import pygame
RECT_SIZE = 50
class Shelf:
def __init__(self, window, x, y):
self.window = window
self.color = (143, 68, 33)
self.width = RECT_SIZE
self.length = 6*RECT_SIZE
self.x = x
self.y = y
self.block = pygame.Rect(self.x, self.y, self.width, self.length)
def draw(self):
pygame.draw.rect(self.window, self.color, self.block)

52
Truck.py Normal file
View File

@ -0,0 +1,52 @@
import pygame
from Environment import Environment
from Package import Package
RECT_SIZE = 50
class Truck:
def __init__(self, window, ):
self.window = window
self.image = pygame.image.load("resources/truck.jpeg").convert()
self.x = 701 # (x,y) - position of the truck
self.y = 401
self.has_package = False
self.environment = Environment(window)
self.package = Package(self.window)
# drawing the truck
def draw(self):
self.environment.draw_itself()
self.package.draw()
self.window.blit(self.image, (self.x, self.y))
pygame.display.flip()
# moving the truck
def move_right(self):
self.x += RECT_SIZE
self.draw()
def move_left(self):
self.x -= RECT_SIZE
self.draw()
def move_up(self):
self.y -= RECT_SIZE
self.draw()
def move_down(self):
self.y += RECT_SIZE
self.draw()
# def collision_with_shelves(self,x,y):
# for row in self.environment.compute_coordinates_of_shelves():
# if self.is_collision(x, y,row[0],row[1]):
# return True
# return False
#
# def is_collision(self, x1, y1, x2, y2):
# if x1 >= x2 and x1 <= x2 + RECT_SIZE:
# if y1 >= y2 and y1 <= y2 + 6*RECT_SIZE:
# return True
#

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

106
run.py
View File

@ -1,108 +1,4 @@
import pygame
from pygame.locals import *
WINDOW_X = 1350
WINDOW_Y = 850
RECT_SIZE = 50
class Truck:
def __init__(self, window, ):
self.window = window
self.image = pygame.image.load("resources/truck.jpeg").convert()
self.x = 701 # (x,y) - position of the truck
self.y = 401
self.grid = Grid(self.window)
self.shelves = Shelves(window)
# drawing the truck
def draw(self):
self.grid.redraw()
self.shelves.draw_shelves()
self.window.blit(self.image, (self.x, self.y))
pygame.display.flip()
# moving the truck
def move_right(self):
self.x += RECT_SIZE
self.draw()
def move_left(self):
self.x -= RECT_SIZE
self.draw()
def move_up(self):
self.y -= RECT_SIZE
self.draw()
def move_down(self):
self.y += RECT_SIZE
self.draw()
class Grid:
def __init__(self, window):
self.window = window
# function to draw a grid, it draws a line every 50px(RECT_SIZE) for both x and y axis
def draw_grid(self):
num_of_columns = int(WINDOW_X / RECT_SIZE)
num_of_rows = int(WINDOW_Y / RECT_SIZE)
x = 0
y = 0
for i in range(num_of_columns):
x += RECT_SIZE
pygame.draw.line(self.window, (255, 255, 255), (x, 0), (x, WINDOW_Y))
for i in range(num_of_rows):
y += RECT_SIZE
pygame.draw.line(self.window, (255, 255, 255), (0, y), (WINDOW_X, y))
# filling a background with color and grid
def redraw(self):
self.window.fill((70, 77, 87))
self.draw_grid()
class Shelves:
def __init__(self, window):
self.window = window
def draw_shelves(self):
width = RECT_SIZE - 1
length = 6*RECT_SIZE
for i in range(2*RECT_SIZE+1, WINDOW_X - 2*RECT_SIZE, 3*RECT_SIZE):
pygame.draw.rect(self.window, (143, 68, 33), pygame.Rect(i, 0, width, length))
pygame.draw.rect(self.window, (143, 68, 33), pygame.Rect(i, (WINDOW_Y - 6*RECT_SIZE)+1, width, length))
class Program:
def __init__(self):
pygame.init()
self.window = pygame.display.set_mode((WINDOW_X, WINDOW_Y)) # decides window's size
self.track = Truck(self.window)
self.track.draw()
def run(self):
running = True
while running:
for event in pygame.event.get(): # integrating with keyboard
if event.type == KEYDOWN:
if event.key == K_LEFT:
self.track.move_left()
if event.key == K_RIGHT:
self.track.move_right()
if event.key == K_UP:
self.track.move_up()
if event.key == K_DOWN:
self.track.move_down()
elif event.type == QUIT:
running = False
from Program import Program
if __name__ == "__main__":
program = Program()