speed anpassung per +/-

This commit is contained in:
Michael S. 2024-03-24 14:42:04 +01:00
parent e7c77f0124
commit 8474c0e7d6

23
main.py
View file

@ -5,8 +5,8 @@ pygame.init()
## funktionen ## funktionen
def get_debug_text(): def get_debug_text():
def text(text,line_counter): def text(text,line_counter):
debug_text = default_font.render(str(text), True, (255,255,255)) debug_text = debug_font.render(str(text), True, (255,255,255))
screen.blit(debug_text,(0,line_counter*default_font.get_height())) screen.blit(debug_text,(0,line_counter*debug_font.get_height()))
line_counter = 1 line_counter = 1
globalvars = globals() globalvars = globals()
@ -26,13 +26,15 @@ screen = pygame.display.set_mode((300,300),pygame.RESIZABLE)
pygame.display.set_caption("Lissajous Figures") pygame.display.set_caption("Lissajous Figures")
screensize = pygame.display.get_window_size() screensize = pygame.display.get_window_size()
clock = pygame.time.Clock() clock = pygame.time.Clock()
default_font = pygame.font.SysFont("sans", 14) debug_font = pygame.font.SysFont("sans", 14)
default_font = pygame.font.SysFont(pygame.font.get_default_font(), 25)
mitte_pos = screensize[0]//2,screensize[1]//2 mitte_pos = screensize[0]//2,screensize[1]//2
frequ1 = 1 frequ1 = 1
frequ2 = 1 frequ2 = 1
phasenverschiebung = 90 phasenverschiebung = 90
phasenverschiebungspeed = 1
scale = (get_best_size()-10)//2 scale = (get_best_size()-10)//2
@ -50,12 +52,16 @@ if __name__ == "__main__":
show_debug = not show_debug show_debug = not show_debug
if pressed_keys[pygame.K_UP] and not preview_pressed_keys[pygame.K_UP]: if pressed_keys[pygame.K_UP] and not preview_pressed_keys[pygame.K_UP]:
frequ1 += 1 frequ1 += 1
if pressed_keys[pygame.K_DOWN] and not preview_pressed_keys[pygame.K_DOWN] and frequ1>=0: if pressed_keys[pygame.K_DOWN] and not preview_pressed_keys[pygame.K_DOWN] and frequ1 >=1:
frequ1 -= 1 frequ1 -= 1
if pressed_keys[pygame.K_RIGHT] and not preview_pressed_keys[pygame.K_RIGHT]: if pressed_keys[pygame.K_RIGHT] and not preview_pressed_keys[pygame.K_RIGHT]:
frequ2 += 1 frequ2 += 1
if pressed_keys[pygame.K_LEFT] and not preview_pressed_keys[pygame.K_LEFT] and frequ2>=0: if pressed_keys[pygame.K_LEFT] and not preview_pressed_keys[pygame.K_LEFT] and frequ2>=1:
frequ2 -= 1 frequ2 -= 1
if pressed_keys[pygame.K_PLUS] and not preview_pressed_keys[pygame.K_PLUS]:
phasenverschiebungspeed += 0.05
if pressed_keys[pygame.K_MINUS] and not preview_pressed_keys[pygame.K_MINUS] and phasenverschiebungspeed>=0:
phasenverschiebungspeed -= 0.05
preview_pressed_keys = pressed_keys preview_pressed_keys = pressed_keys
## event managment ## event managment
@ -69,19 +75,16 @@ if __name__ == "__main__":
if show_debug: if show_debug:
get_debug_text() get_debug_text()
phasenverschiebung += 0.1 phasenverschiebung += phasenverschiebungspeed
if phasenverschiebung >= 360: if phasenverschiebung >= 360:
phasenverschiebung = 0 phasenverschiebung = 0
for r in range(360): for r in range(360):
pos = (sin(radians(frequ1*(r+phasenverschiebung)))*scale)+mitte_pos[0],(cos(radians(frequ2*r))*scale)+mitte_pos[1] pos = (sin(radians(frequ1*(r+phasenverschiebung)))*scale)+mitte_pos[0],(cos(radians(frequ2*r))*scale)+mitte_pos[1]
pygame.draw.line(screen,(0,255,0),preview_pos,pos,3) pygame.draw.line(screen,(0,255,0),preview_pos,pos,3)
preview_pos = pos preview_pos = pos
#pygame.draw.circle(screen,(255,0,0),pos,2)
#frequ1 = pygame.mouse.get_pos()[0]//5
#frequ2 = pygame.mouse.get_pos()[1]//5
frequs_txt = default_font.render(f"x = {frequ1}, y = {frequ2}", True, (255,255,255)) frequs_txt = default_font.render(f"Speed = {phasenverschiebungspeed} X = {frequ1} Y = {frequ2}", True, (255,255,255))
screen.blit(frequs_txt,(0,0)) screen.blit(frequs_txt,(0,0))
## bildschirm aktuallisierung ## bildschirm aktuallisierung
pygame.display.flip() pygame.display.flip()