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)
|
52
demo/random_rectangles.py
Normal file → Executable file
52
demo/random_rectangles.py
Normal file → Executable file
@ -1,35 +1,23 @@
|
|||||||
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():
|
def draw(window):
|
||||||
init(INIT.EVERYTHING)
|
window.renderer.set_draw_color(0,0,0,255)
|
||||||
window = Window('test', 100, 100, 512, 512, 0)
|
window.renderer.clear()
|
||||||
|
window.renderer.set_draw_color(255,0,0,255)
|
||||||
|
for i in xrange(20):
|
||||||
|
window.renderer.set_draw_color(random.randint(0,255),
|
||||||
|
random.randint(0,255),
|
||||||
|
random.randint(0,255))
|
||||||
|
r = Rect(random.randint(0,512), random.randint(0, 512),
|
||||||
|
random.randint(0,300), random.randint(0, 300))
|
||||||
|
s = Rect(random.randint(0,512), random.randint(0, 512),
|
||||||
|
random.randint(0,300), random.randint(0, 300))
|
||||||
|
t = Rect(random.randint(0,512), random.randint(0, 512),
|
||||||
|
random.randint(0,300), random.randint(0, 300))
|
||||||
|
window.renderer.fill_rects([r,s,t])
|
||||||
|
window.renderer.present()
|
||||||
|
|
||||||
while True:
|
if __name__ == '__main__':
|
||||||
while True:
|
simple_timed_loop(draw)
|
||||||
event = poll_event()
|
|
||||||
if not event:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print repr(EventType.from_int(event.type))
|
|
||||||
|
|
||||||
window.renderer.set_draw_color(0,0,0,255)
|
|
||||||
window.renderer.clear()
|
|
||||||
window.renderer.set_draw_color(255,0,0,255)
|
|
||||||
for i in xrange(20):
|
|
||||||
window.renderer.set_draw_color(random.randint(0,255),
|
|
||||||
random.randint(0,255),
|
|
||||||
random.randint(0,255))
|
|
||||||
r = Rect(random.randint(0,512), random.randint(0, 512),
|
|
||||||
random.randint(0,300), random.randint(0, 300))
|
|
||||||
s = Rect(random.randint(0,512), random.randint(0, 512),
|
|
||||||
random.randint(0,300), random.randint(0, 300))
|
|
||||||
t = Rect(random.randint(0,512), random.randint(0, 512),
|
|
||||||
random.randint(0,300), random.randint(0, 300))
|
|
||||||
window.renderer.fill_rects([r,s,t])
|
|
||||||
window.renderer.present()
|
|
||||||
time.sleep(.001)
|
|
||||||
main()
|
|
||||||
|
39
demo/random_triangles.py
Normal file → Executable file
39
demo/random_triangles.py
Normal file → Executable file
@ -1,25 +1,20 @@
|
|||||||
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.renderer.set_draw_color(0,0,0,255)
|
||||||
window = Window('test', 100, 100, 512, 512, 0)
|
window.renderer.clear()
|
||||||
|
window.renderer.set_draw_color(255,0,0,255)
|
||||||
|
for i in xrange(20):
|
||||||
|
window.renderer.set_draw_color(random.randint(0,255),
|
||||||
|
random.randint(0,255),
|
||||||
|
random.randint(0,255))
|
||||||
|
p1 = (random.randint(0,512), random.randint(0, 512))
|
||||||
|
p2 = (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.present()
|
||||||
|
|
||||||
while True:
|
if __name__ == '__main__':
|
||||||
window.renderer.set_draw_color(0,0,0,255)
|
simple_timed_loop(draw)
|
||||||
window.renderer.clear()
|
|
||||||
window.renderer.set_draw_color(255,0,0,255)
|
|
||||||
for i in xrange(20):
|
|
||||||
window.renderer.set_draw_color(random.randint(0,255),
|
|
||||||
random.randint(0,255),
|
|
||||||
random.randint(0,255))
|
|
||||||
p1 = (random.randint(0,512), random.randint(0, 512))
|
|
||||||
p2 = (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.present()
|
|
||||||
time.sleep(.001)
|
|
||||||
main()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user