draw points, rects, and filled rects
This commit is contained in:
parent
fc3c379a09
commit
0bd9c80cdb
@ -156,11 +156,35 @@ class Renderer(object):
|
||||
errcheck(_SDL.SDL_RenderDrawLine(self._renderer, x1, y1, x2, y2))
|
||||
|
||||
def draw_lines(self, points):
|
||||
T = Point*len(points)
|
||||
_sdl_points = T(*[Point(*pt) for pt in points])
|
||||
PtArray = Point*len(points)
|
||||
_sdl_points = PtArray(*[Point(*pt) for pt in points])
|
||||
errcheck(_SDL.SDL_RenderDrawLines(self._renderer, _sdl_points,
|
||||
len(points)))
|
||||
|
||||
def draw_point(self, x, y):
|
||||
errcheck(_SDL.SDL_RenderDrawPoint(self._renderer, x, y))
|
||||
|
||||
def draw_points(self, points):
|
||||
PtArray = Point*len(points)
|
||||
_sdl_points = PtArray(*[Point(*pt) for pt in points])
|
||||
errcheck(_SDL.SDL_RenderDrawPoints(self._renderer, _sdl_points,
|
||||
len(points)))
|
||||
|
||||
def draw_rect(self, rect):
|
||||
_SDL.SDL_RenderDrawRect(self._renderer, ctypes.pointer(rect))
|
||||
|
||||
def draw_rects(self, rects):
|
||||
RectArray = Rect*len(rects)
|
||||
rects = RectArray(*rects)
|
||||
_SDL.SDL_RenderDrawRects(self._renderer, rects, len(rects))
|
||||
|
||||
def fill_rect(self, rect):
|
||||
_SDL.SDL_RenderFillRect(self._renderer, ctypes.pointer(rect))
|
||||
|
||||
def fill_rects(self, rects):
|
||||
RectArray = Rect*len(rects)
|
||||
rects = RectArray(*rects)
|
||||
_SDL.SDL_RenderFillRects(self._renderer, rects, len(rects))
|
||||
|
||||
_SDL.SDL_GetWindowTitle.restype = ctypes.c_char_p
|
||||
|
||||
|
26
demo/random_rectangles.py
Normal file
26
demo/random_rectangles.py
Normal file
@ -0,0 +1,26 @@
|
||||
from csdl import init, Window, SDL_INIT_EVERYTHING, Rect
|
||||
import random
|
||||
import time
|
||||
|
||||
def main():
|
||||
init(SDL_INIT_EVERYTHING)
|
||||
window = Window('test', 100, 100, 512, 512, 0)
|
||||
|
||||
while True:
|
||||
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()
|
Loading…
Reference in New Issue
Block a user