added prototype sound, proper delta time and changed some settings
This commit is contained in:
parent
eaad3380ef
commit
1ab61186a9
66
main.py
66
main.py
@ -3,6 +3,7 @@ import pygame.gfxdraw
|
||||
from PIL import Image
|
||||
import random
|
||||
from math import cos, sin
|
||||
#import time
|
||||
|
||||
##### CONFIG #####
|
||||
window_size = (1280, 720)
|
||||
@ -10,7 +11,7 @@ window_size = (1280, 720)
|
||||
fps = 60
|
||||
|
||||
# pixel size in percentage of window height (0.0 - 1.0)
|
||||
pixel_size = 0.018
|
||||
pixel_size = 0.015
|
||||
|
||||
# min and max distance from screen edge to pixel in window height percentage (0.0 - 1.0)
|
||||
min_distribution_edge_dist = 0.1
|
||||
@ -29,11 +30,17 @@ stiffness = 40
|
||||
# 0.0 - 1.0
|
||||
damping = 0.08
|
||||
|
||||
|
||||
audio = True
|
||||
|
||||
##################
|
||||
|
||||
if audio:
|
||||
import playsound
|
||||
|
||||
damping_multiplier = 1 - damping
|
||||
|
||||
target_delta_time = 1 / fps
|
||||
delta_time = 1 / fps
|
||||
|
||||
half_window_size = (window_size[0] / 2, window_size[1] / 2)
|
||||
|
||||
@ -110,19 +117,22 @@ pygame.init()
|
||||
window = pygame.display.set_mode(window_size)
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
# font
|
||||
font = pygame.font.SysFont("Arial", 20)
|
||||
|
||||
|
||||
|
||||
############# another config stuff ##############
|
||||
|
||||
rot_zoom_delay = 6
|
||||
rot_speed_increase = 0.2
|
||||
zoom_speed_increase = 0.8
|
||||
zoom_speed_increase = 2
|
||||
|
||||
|
||||
zoom_speed = 0.04
|
||||
|
||||
fade_delay = 2.5
|
||||
fade_speed = 255*3
|
||||
fade_delay = 1.6
|
||||
fade_speed = 255*4
|
||||
|
||||
|
||||
zoom = 1
|
||||
@ -137,6 +147,9 @@ angle = 0
|
||||
can_rot = False
|
||||
|
||||
|
||||
#time_start = time.perf_counter() + 1
|
||||
|
||||
|
||||
# main loop
|
||||
while True:
|
||||
# events
|
||||
@ -149,13 +162,14 @@ while True:
|
||||
window.fill((0, 0, 0))
|
||||
|
||||
if fade_val > 0:
|
||||
if rot_zoom_delay > 0:
|
||||
rot_zoom_delay -= target_delta_time
|
||||
else: # zooming more and rotating
|
||||
rot_speed += rot_speed_increase * target_delta_time
|
||||
zoom_speed += zoom_speed_increase * target_delta_time
|
||||
|
||||
angle += rot_speed * target_delta_time
|
||||
if rot_zoom_delay > 0:
|
||||
rot_zoom_delay -= delta_time
|
||||
else: # zooming more and rotating
|
||||
rot_speed += rot_speed_increase * delta_time
|
||||
zoom_speed += zoom_speed_increase * delta_time
|
||||
|
||||
angle += rot_speed * delta_time
|
||||
|
||||
# rotate and zoom
|
||||
rot_cos = cos(angle)
|
||||
@ -166,13 +180,13 @@ while True:
|
||||
|
||||
# fade
|
||||
if fade_delay > 0:
|
||||
fade_delay -= target_delta_time
|
||||
fade_delay -= delta_time
|
||||
else:
|
||||
fade_val -= fade_speed * target_delta_time
|
||||
fade_val -= fade_speed * delta_time
|
||||
if fade_val < 0:
|
||||
continue
|
||||
|
||||
zoom *= 1 + zoom_speed * target_delta_time
|
||||
zoom *= 1 + zoom_speed * delta_time
|
||||
|
||||
# calculate pixel points positions
|
||||
scaled_pixel_size_px = pixel_size_px * zoom
|
||||
@ -209,10 +223,14 @@ while True:
|
||||
for pixel_idx, pixel in enumerate(pixels_pos_and_vel):
|
||||
# check if delay is over
|
||||
if pixel[2] > 0:
|
||||
pixel[2] -= target_delta_time
|
||||
pixel[2] -= delta_time
|
||||
continue
|
||||
|
||||
## simulation (take target_delta_time into account)
|
||||
if audio:
|
||||
playsound.playsound("prototype_sound.wav", False)
|
||||
audio = False
|
||||
|
||||
## simulation (take delta_time into account)
|
||||
|
||||
# get pixel pos and vel
|
||||
pos = pixel[0]
|
||||
@ -222,16 +240,16 @@ while True:
|
||||
delta_pos = [pixels_target_pos[pixel_idx][0] - pos[0], pixels_target_pos[pixel_idx][1] - pos[1]]
|
||||
|
||||
# update velocity
|
||||
vel[0] += delta_pos[0] * stiffness * target_delta_time
|
||||
vel[1] += delta_pos[1] * stiffness * target_delta_time
|
||||
vel[0] += delta_pos[0] * stiffness * delta_time
|
||||
vel[1] += delta_pos[1] * stiffness * delta_time
|
||||
|
||||
# damping
|
||||
vel[0] *= damping_multiplier
|
||||
vel[1] *= damping_multiplier
|
||||
|
||||
# update pos
|
||||
pos[0] += vel[0] * target_delta_time
|
||||
pos[1] += vel[1] * target_delta_time
|
||||
pos[0] += vel[0] * delta_time
|
||||
pos[1] += vel[1] * delta_time
|
||||
|
||||
# update pixel pos and vel
|
||||
pixels_pos_and_vel[pixel_idx][0:2] = [pos, vel]
|
||||
@ -283,8 +301,14 @@ while True:
|
||||
# DEBUG draw dot
|
||||
#pygame.draw.circle(window, (255, 0, 0), (round(pixel_draw_pos[0]), round(pixel_draw_pos[1])), 1)
|
||||
|
||||
#time_now = time.perf_counter()
|
||||
#time_delta = time_now - time_start
|
||||
#
|
||||
## draw time
|
||||
#text = font.render(f"Time: {time_delta:.2f}", True, (255, 255, 255))
|
||||
#window.blit(text, (10, 10))
|
||||
|
||||
|
||||
# update
|
||||
pygame.display.update()
|
||||
clock.tick(60)
|
||||
delta_time = clock.tick(60) / 1000
|
BIN
prototype_sound.wav
Normal file
BIN
prototype_sound.wav
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user