demo improvements
This commit is contained in:
parent
181dea87f1
commit
29c5681066
32
demo/demo_utils.py
Normal file
32
demo/demo_utils.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from csdl import init, InitFlags
|
||||||
|
from csdl.video import Window
|
||||||
|
from csdl.events import EventType, poll_event, WindowEventType
|
||||||
|
import time
|
||||||
|
|
||||||
|
def simple_timed_loop(draw_func):
|
||||||
|
init(InitFlags.EVERYTHING)
|
||||||
|
window = Window('timed sdloppy demo', 100, 100, 512, 512)
|
||||||
|
running = True
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
frames = 0
|
||||||
|
|
||||||
|
while running:
|
||||||
|
frames += 1
|
||||||
|
if frames == 1000:
|
||||||
|
print('FPS: {0:.2f}'.format(frames/(time.time()-start_time)))
|
||||||
|
frames = 0
|
||||||
|
start_time = time.time()
|
||||||
|
|
||||||
|
# event loop
|
||||||
|
while True:
|
||||||
|
event = poll_event()
|
||||||
|
if not event:
|
||||||
|
break
|
||||||
|
elif event.type == EventType.QUIT:
|
||||||
|
running = False
|
||||||
|
elif event.type == EventType.WINDOWEVENT:
|
||||||
|
if event.window.event == WindowEventType.CLOSE:
|
||||||
|
running = False
|
||||||
|
|
||||||
|
draw_func(window)
|
24
demo/random_rectangles.py
Normal file → Executable file
24
demo/random_rectangles.py
Normal file → Executable file
@ -1,21 +1,8 @@
|
|||||||
from csdl import init, INIT
|
|
||||||
from csdl.video import Window, Rect
|
|
||||||
from csdl.events import EventType, poll_event
|
|
||||||
import random
|
import random
|
||||||
import time
|
from csdl.video import Rect
|
||||||
|
from demo_utils import simple_timed_loop
|
||||||
def main():
|
|
||||||
init(INIT.EVERYTHING)
|
|
||||||
window = Window('test', 100, 100, 512, 512, 0)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
while True:
|
|
||||||
event = poll_event()
|
|
||||||
if not event:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print repr(EventType.from_int(event.type))
|
|
||||||
|
|
||||||
|
def draw(window):
|
||||||
window.renderer.set_draw_color(0,0,0,255)
|
window.renderer.set_draw_color(0,0,0,255)
|
||||||
window.renderer.clear()
|
window.renderer.clear()
|
||||||
window.renderer.set_draw_color(255,0,0,255)
|
window.renderer.set_draw_color(255,0,0,255)
|
||||||
@ -31,5 +18,6 @@ def main():
|
|||||||
random.randint(0,300), random.randint(0, 300))
|
random.randint(0,300), random.randint(0, 300))
|
||||||
window.renderer.fill_rects([r,s,t])
|
window.renderer.fill_rects([r,s,t])
|
||||||
window.renderer.present()
|
window.renderer.present()
|
||||||
time.sleep(.001)
|
|
||||||
main()
|
if __name__ == '__main__':
|
||||||
|
simple_timed_loop(draw)
|
||||||
|
17
demo/random_triangles.py
Normal file → Executable file
17
demo/random_triangles.py
Normal file → Executable file
@ -1,14 +1,8 @@
|
|||||||
from csdl import init, INIT
|
#!/usr/bin/env python
|
||||||
from csdl.video import Window
|
from demo_utils import simple_timed_loop
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import time
|
|
||||||
|
|
||||||
def main():
|
def draw(window):
|
||||||
init(INIT.EVERYTHING)
|
|
||||||
window = Window('test', 100, 100, 512, 512, 0)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
window.renderer.set_draw_color(0,0,0,255)
|
window.renderer.set_draw_color(0,0,0,255)
|
||||||
window.renderer.clear()
|
window.renderer.clear()
|
||||||
window.renderer.set_draw_color(255,0,0,255)
|
window.renderer.set_draw_color(255,0,0,255)
|
||||||
@ -21,5 +15,6 @@ def main():
|
|||||||
p3 = (random.randint(0,512), random.randint(0, 512))
|
p3 = (random.randint(0,512), random.randint(0, 512))
|
||||||
window.renderer.draw_lines([p1, p2, p3, p1])
|
window.renderer.draw_lines([p1, p2, p3, p1])
|
||||||
window.renderer.present()
|
window.renderer.present()
|
||||||
time.sleep(.001)
|
|
||||||
main()
|
if __name__ == '__main__':
|
||||||
|
simple_timed_loop(draw)
|
||||||
|
Loading…
Reference in New Issue
Block a user