diff --git a/Projects of personal interest/Games/Snake.py b/Projects of personal interest/Games/Snake.py new file mode 100644 index 0000000000000000000000000000000000000000..c990ad8ea8468715488012b8ae2769a0b5d37369 --- /dev/null +++ b/Projects of personal interest/Games/Snake.py @@ -0,0 +1,178 @@ +import pygame +import random +import sys +import numpy as np +from math import exp + +class Snake(object): + def __init__(self): + self.legth = 1 + self.positions = [((width / 2), (height / 2))] + self.direction = random.choice([up, down, left, right]) + self.color = (17, 24, 47) + + + def get_head_position(self): + return self.positions[0] + + + def getPositions(self): + return self.positions + + + def move(self): + cur = self.get_head_position() + x, y = self.direction + new = (((cur[0] + (x * grid_size)) % width), (cur[1] + (y * grid_size)) % height) + if len(self.positions) > 2 and new in self.positions[2:]: + self.reset() + elif new[0] == width - grid_size: + self.reset() + elif new[1] == height - grid_size: + self.reset() + elif new[0] == 0: + self.reset() + elif new[1] == 0: + self.reset() + else: + self.positions.insert(0, new) + if len(self.positions) > self.legth: + self.positions.pop() + + + + def reset(self): + self.legth = 1 + self.positions = [((width / 2), (height / 2))] + self.direction = random.choice([up, down, left, right]) + + + def draw(self, surface): + for p in self.positions: + r = pygame.Rect((p[0], p[1]), (grid_size, grid_size)) + pygame.draw.rect(surface, self.color, r) + pygame.draw.rect(surface, (93, 216, 228), r, 1) + + + def handle_keys(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_UP: + if self.direction == down: + pass + else: + self.direction = up + elif event.key == pygame.K_DOWN: + if self.direction == up: + pass + else: + self.direction = down + elif event.key == pygame.K_LEFT: + if self.direction == right: + pass + else: + self.direction = left + elif event.key == pygame.K_RIGHT: + if self.direction == left: + pass + else: + self.direction = right + + +class Food(object): + def __init__(self): + self.position = (0, 0) + self.color = (233, 163, 49) + self.randomize_position() + + + def getPosition(self): + return self.position + + + def randomize_position(self): + self.position = (random.randint(1, grid_width - 2) * grid_size, random.randint(1, grid_height - 2) * grid_size) + + + def draw(self, surface): + r = pygame.Rect((self.position[0], self.position[1]), (grid_size, grid_size)) + pygame.draw.rect(surface, self.color, r) + pygame.draw.rect(surface, (93, 216, 228), r, 1) + + +def drawGrid(surface): + for y in range(0, int(height)): + for x in range(0, int(width)): + if (x + y) % 2 == 0: + r = pygame.Rect((x * grid_size, y * grid_size), (grid_size, grid_size)) + pygame.draw.rect(surface, (93, 216, 228), r) + else: + rr = pygame.Rect((x * grid_size, y * grid_size), (grid_size, grid_size)) + pygame.draw.rect(surface, (84, 194, 205), rr) + for x in range(0, int(width)): + boarder = pygame.Rect((width - grid_size, x * grid_size), ( grid_size, grid_size)) + pygame.draw.rect(surface, (200, 200, 200), boarder) + pygame.draw.rect(surface, (125, 125, 125), boarder, 1) + boarder = pygame.Rect((0, x * grid_size), ( grid_size, grid_size)) + pygame.draw.rect(surface, (200, 200, 200), boarder) + pygame.draw.rect(surface, (125, 125, 125), boarder, 1) + for y in range(0, int(height)): + boarder = pygame.Rect((y * grid_size, width - grid_size), ( grid_size, grid_size)) + pygame.draw.rect(surface, (200, 200, 200), boarder) + pygame.draw.rect(surface, (125, 125, 125), boarder, 1) + boarder = pygame.Rect((y * grid_size, 0), ( grid_size, grid_size)) + pygame.draw.rect(surface, (200, 200, 200), boarder) + pygame.draw.rect(surface, (125, 125, 125), boarder, 1) + +# Grid size parameters +width = 480 +height = 480 +grid_size = 20 +grid_width = height / grid_size +grid_height = width / grid_size + +# Possible movements +up = (0, -1) +down = (0, 1) +left = (-1, 0) +right = (1, 0) + + +def main(): + pygame.init() + + clock = pygame.time.Clock() + screen = pygame.display.set_mode((width, height), 0, 32) + + surface = pygame.Surface(screen.get_size()) + surface = surface.convert() + drawGrid(surface) + + snake = Snake() + food = Food() + + while(True): + + clock.tick(10) + snake.handle_keys() + drawGrid(surface) + snake.move() + + if snake.get_head_position() == food.position: + snake.legth += 1 + food.randomize_position() + while food.getPosition() in snake.getPositions(): + food.randomize_position() + + snake.draw(surface) + food.draw(surface) + screen.blit(surface, (0, 0)) + # text = myfont.render("Score {0}".format(score), 1, (0)) + # screen.blit(text, (5, 10)) + pygame.display.update() + + +main() \ No newline at end of file diff --git a/Projects of personal interest/Games/bombfield.py b/Projects of personal interest/Games/bombfield.py new file mode 100644 index 0000000000000000000000000000000000000000..84c3ff8b4dd1a22b3ab5378d33a849ee12c38be4 --- /dev/null +++ b/Projects of personal interest/Games/bombfield.py @@ -0,0 +1,199 @@ +import pygame +import random +import sys +import numpy as np +from time import sleep +import pandas as pd + +class Human(object): + def __init__(self): + self.position = (grid_size, 0) + self.color = (255, 255, 255) + self.direction = up + + + def move(self): + cur = self.getPosition() + x, y = self.direction + new = (((cur[0] + (x * grid_size)) % width), (cur[1] + (y * grid_size)) % height) + if new[0] == width - grid_size: + pass + elif new[1] == height - grid_size: + if new[0] == width - 2 * grid_size: + self.position = new + else: + pass + elif new[0] == 0: + pass + elif new[1] == 0: + pass + else: + self.position = new + + + def getPosition(self): + return self.position + + + def getDirection(self): + return self.direction + + def setDirection(self, direction): + self.direction = direction + + + def handle_keys(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_KP8: + self.direction = up + self.move() + elif event.key == pygame.K_KP2: + self.direction = down + self.move() + elif event.key == pygame.K_KP4: + self.direction = left + self.move() + elif event.key == pygame.K_KP6: + self.direction = right + self.move() + elif event.key == pygame.K_KP9: + self.direction = up_right + self.move() + elif event.key == pygame.K_KP7: + self.direction = up_left + self.move() + elif event.key == pygame.K_KP1: + self.direction = down_left + self.move() + elif event.key == pygame.K_KP3: + self.direction = down_right + self.move() + + + def draw(self, surface): + r = pygame.Rect((self.position[0], self.position[1]), (grid_size, grid_size)) + pygame.draw.rect(surface, self.color, r) + pygame.draw.rect(surface, (93, 216, 228), r, 1) + + + def reset(self): + self.position = (grid_size, 0) + + +class Bomb(object): + def __init__(self): + self.position = (0, 0) + self.color = (0, 0, 0) + self.randomize_position() + + + def randomize_position(self): + self.position = (random.randint(1, width_grid - 2) * grid_size, random.randint(1, height_grid - 2) * grid_size) + + + def getPosition(self): + return self.position + + + def draw(self, surface): + r = pygame.Rect((self.position[0], self.position[1]), (grid_size, grid_size)) + pygame.draw.rect(surface, self.color, r) + pygame.draw.rect(surface, (93, 216, 228), r, 1) + + + def explode(self, surface): + r = pygame.Rect((self.position[0], self.position[1]), (grid_size, grid_size)) + pygame.draw.rect(surface, (255, 0, 0), r) + pygame.draw.rect(surface, (93, 216, 228), r, 1) + + +def drawGrid(surface): + for y in range(0, int(height)): + for x in range(0, int(width)): + if (x + y) % 2 == 0: + r = pygame.Rect((x * grid_size, y * grid_size), (grid_size, grid_size)) + pygame.draw.rect(surface, (93, 216, 228), r) + else: + rr = pygame.Rect((x * grid_size, y * grid_size), (grid_size, grid_size)) + pygame.draw.rect(surface, (84, 194, 205), rr) + for x in range(0, int(width)): + boarder = pygame.Rect((x * grid_size, width - grid_size), ( grid_size, grid_size)) + pygame.draw.rect(surface, (200, 200, 200), boarder) + pygame.draw.rect(surface, (125, 125, 125), boarder, 1) + boarder = pygame.Rect(((x + 2) * grid_size, 0), (grid_size, grid_size)) + pygame.draw.rect(surface, (200, 200, 200), boarder) + pygame.draw.rect(surface, (125, 125, 125), boarder, 1) + for y in range(0, int(height)): + boarder = pygame.Rect((width - grid_size, y * grid_size), ( grid_size, grid_size)) + pygame.draw.rect(surface, (200, 200, 200), boarder) + pygame.draw.rect(surface, (125, 125, 125), boarder, 1) + boarder = pygame.Rect((0, y * grid_size), (grid_size, grid_size)) + pygame.draw.rect(surface, (200, 200, 200), boarder) + pygame.draw.rect(surface, (125, 125, 125), boarder, 1) + goal = pygame.Rect((width - 2 * grid_size, height - grid_size), (grid_size, grid_size)) + pygame.draw.rect(surface, (255,255,0), goal) + + +# Grid size parameters +height = 480 +width = 480 +grid_size = 20 +height_grid = int(height / grid_size) +width_grid = int(width / grid_size) + +# Possible movements +up = (0, -1) +down = (0, 1) +right = (1, 0) +left = (-1, 0) +up_right = (up[0] + right[0], up[1] + right[1]) +up_left = (up[0] + left[0], up[1] + left[1]) +down_right = (down[0] + right[0], down[1] + right[1]) +down_left = (down[0] + left[0], down[1] + left[1]) + + +def main(): + pygame.init() + clock = pygame.time.Clock() + screen = pygame.display.set_mode((width, height), 0, 32) + + surface = pygame.Surface(screen.get_size()) + surface = surface.convert() + drawGrid(surface) + + human = Human() + bombs = [] + + for b in range(int(min([height_grid, width_grid]) - 1)): + bombs.append(Bomb()) + + while(True): + clock.tick(30) + drawGrid(surface) + + human.handle_keys() + + for bomb in bombs: + if human.getPosition() == bomb.getPosition(): + bomb.explode(surface) + screen.blit(surface, (0, 0)) + pygame.display.update() + done = True + sleep(1) + human.reset() + + human.draw(surface) + screen.blit(surface, (0, 0)) + pygame.display.update() + + if human.getPosition() == ( width - 2 * grid_size, height - grid_size): + print("You win!") + sleep(1) + human.reset() + + +main() \ No newline at end of file diff --git a/Projects of personal interest/NYE/4k-ultra-hd-background-toronto-canada-long-exposure-photogra.gif b/Projects of personal interest/NYE/4k-ultra-hd-background-toronto-canada-long-exposure-photogra.gif new file mode 100644 index 0000000000000000000000000000000000000000..be2183836f1ff7723148c77381eab21bba2016ba Binary files /dev/null and b/Projects of personal interest/NYE/4k-ultra-hd-background-toronto-canada-long-exposure-photogra.gif differ diff --git a/Projects of personal interest/NYE/Blue-Fireworks-New-Year-2021-Wallpaper-72615.gif b/Projects of personal interest/NYE/Blue-Fireworks-New-Year-2021-Wallpaper-72615.gif new file mode 100644 index 0000000000000000000000000000000000000000..dcb9ca07f6053a112466cc1b6fb95eff7078f6ae Binary files /dev/null and b/Projects of personal interest/NYE/Blue-Fireworks-New-Year-2021-Wallpaper-72615.gif differ diff --git a/Projects of personal interest/NYE/new_year_eve_countdown.py b/Projects of personal interest/NYE/new_year_eve_countdown.py new file mode 100644 index 0000000000000000000000000000000000000000..a0bc6e66cd8cd6887d4ad741b829dd314cd5cf09 --- /dev/null +++ b/Projects of personal interest/NYE/new_year_eve_countdown.py @@ -0,0 +1,41 @@ +import datetime +import time +import turtle + +screen = turtle.Screen() +display = turtle.Turtle() + +image = "4k-ultra-hd-background-toronto-canada-long-exposure-photogra.jpg" + +while True: + screen.title("NYE Countdown") + # screen.bgcolor("pink") + screen.bgpic("D:/pythonProject/Neural network/Snake/4k-ultra-hd-background-toronto-canada-long-exposure-photogra.gif") + screen.setup(width=4000, height=2000, startx = 0, starty= 0) + screen.tracer(0) + + hour = 23 + minute = 59 + seconds = 59 + time_now = datetime.datetime.now() + + countdown = f"{hour - time_now.hour:02d}:{minute - time_now.minute:02d}:{seconds - time_now.second:02d}" + style = ('Arial', 120, "bold") + display.color("white") + display.write(countdown, font=style, align="center") + + time.sleep(1) + screen.clear() + + if ((hour - time_now.hour) == 0) & ((minute - time_now.minute) == 0) & ((seconds - time_now.second) == 0): + break + +screen.bgpic("D:/pythonProject/Neural network/Snake/Blue-Fireworks-New-Year-2021-Wallpaper-72615.gif") +screen.setup(width=4000, height=2000, startx = 0, starty= 0) +screen.tracer(0) +screen.update() +countdown = "Happy New Year!!" +style = ('Arial', 120, "bold") +display.color("white") +display.write(countdown, font=style, align="center") +turtle.done() \ No newline at end of file diff --git a/images/snake.png b/images/Games/snake.png similarity index 100% rename from images/snake.png rename to images/Games/snake.png