-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.py
138 lines (116 loc) · 4.82 KB
/
demo.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#
# (C) Copyright 2023, 2024 Pavel Tisnovsky
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Pavel Tisnovsky
#
"""Entry point to initialization part + entry to the main event loop."""
import sys
import pygame
import pygame.locals
from demo.about_screen import AboutScreen
from demo.circle_moire_screen import CircleMoireScreen
from demo.colors import Colors
from demo.config import loadConfiguration
from demo.cplx_menu import CplxMenu
from demo.cplx_screen import CplxScreen
from demo.dynamic_systems_screen import DynamicSystemsScreen
from demo.ghost import Ghost
from demo.ifs_screen import IteratedFunctionsSystemsScreen
from demo.main_menu import MainMenu
from demo.mandelbrot_screen import MandelbrotScreen
from demo.other_moire_screen import OtherMoireScreen
from demo.plasma_screen import PlasmaScreen
from demo.resources import Resources
from demo.setup_screen import SetupScreen
from demo.splash_screen import SplashScreen
from demo.strange_attractors_screen import StrangeAttractorsScreen
from demo.textures_menu import TexturesMenu
from demo.textures_screen import TexturesScreen
configuration = loadConfiguration("demo.ini")
pygame.init()
resources = Resources(configuration)
clock = pygame.time.Clock()
# create demo window
window_width = int(configuration["screen"]["window_width"])
window_height = int(configuration["screen"]["window_height"])
display = pygame.display.set_mode([window_width, window_height])
# set window title
pygame.display.set_caption("Procedural graphics demos")
display.fill(Colors.BLACK.value)
red_ghost = Ghost(display, resources, "ghost_red")
splash_screen = SplashScreen(display, resources, "splash_screen", 8, red_ghost)
def in_texture_screen(display, resources, red_ghost) -> None:
textures_screen = TexturesScreen(display, resources, red_ghost)
textures_screen.draw()
while True:
choice = textures_screen.eventLoop()
if choice in {TexturesMenu.QUIT.value, MainMenu.QUIT.value}:
return
elif choice == TexturesMenu.CIRCLE_MOIRE.value:
circle_moire_screen = CircleMoireScreen(
display, resources, "Circle moire patterns"
)
circle_moire_screen.draw()
circle_moire_screen.eventLoop()
elif choice == TexturesMenu.OTHER_MOIRE.value:
other_moire_screen = OtherMoireScreen(
display, resources, "Other moire patterns"
)
other_moire_screen.draw()
other_moire_screen.eventLoop()
elif choice == TexturesMenu.PLASMA.value:
plasma_screen = PlasmaScreen(display, resources, "Plasma")
plasma_screen.draw()
plasma_screen.eventLoop()
def in_cplx_screen(display, resources, red_ghost) -> None:
cplx_screen = CplxScreen(display, resources, red_ghost)
cplx_screen.draw()
while True:
choice = cplx_screen.eventLoop()
if choice in {CplxMenu.QUIT.value, MainMenu.QUIT.value}:
return
elif choice == CplxMenu.MANDELBROT.value:
mandelbrot_screen = MandelbrotScreen(
display, resources, "Mandelbrot fractal"
)
mandelbrot_screen.draw()
mandelbrot_screen.eventLoop()
def main() -> None:
while True:
menuItem = splash_screen.eventLoop()
if menuItem == MainMenu.QUIT.value:
pygame.quit()
sys.exit()
elif menuItem == MainMenu.PROCEDURAL_TEXTURES.value:
in_texture_screen(display, resources, red_ghost)
elif menuItem == MainMenu.COMPLEX_FRACTALS.value:
in_cplx_screen(display, resources, red_ghost)
elif menuItem == MainMenu.STRANGE_ATTRACTORS.value:
# TODO: refactor a bit
cplx_screen = StrangeAttractorsScreen(display, resources, red_ghost)
cplx_screen.draw()
cplx_screen.eventLoop()
elif menuItem == MainMenu.IFS.value:
ifs_screen = IteratedFunctionsSystemsScreen(display, resources, red_ghost)
ifs_screen.draw()
ifs_screen.eventLoop()
elif menuItem == MainMenu.DYNAMIC_SYSTEMS.value:
dynamic_system_screen = DynamicSystemsScreen(display, resources, red_ghost)
dynamic_system_screen.draw()
dynamic_system_screen.eventLoop()
elif menuItem == MainMenu.ABOUT.value:
about_screen = AboutScreen(display, resources)
about_screen.draw()
about_screen.eventLoop()
elif menuItem == MainMenu.SETUP.value:
setup_screen = SetupScreen(display, resources, red_ghost)
setup_screen.draw()
setup_screen.eventLoop()
main()
# finito