mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-11-05 08:36:14 +02:00
50 lines
1.1 KiB
Plaintext
50 lines
1.1 KiB
Plaintext
|
#pypp 0
|
||
|
#include <iris.hh>
|
||
|
#include <devices.hh>
|
||
|
|
||
|
static unsigned *framebuffer
|
||
|
static int const r = 10
|
||
|
|
||
|
void ball (int x, int y, bool print):
|
||
|
static unsigned bg
|
||
|
static unsigned count
|
||
|
for int ty = y - r; ty < y + r; ++ty:
|
||
|
if ty < 0 || ty >= 240:
|
||
|
continue
|
||
|
for int tx = x - r; tx < x + r; ++tx:
|
||
|
if tx < 0 || tx >= 320:
|
||
|
continue
|
||
|
if (x - tx) * (x - tx) + (y - ty) * (y - ty) > r * r:
|
||
|
continue
|
||
|
framebuffer[ty * 320 + tx] = (print ? 0xffffff : bg)
|
||
|
if ++count >= 30:
|
||
|
bg += 0x010307
|
||
|
count = 0
|
||
|
|
||
|
Kernel::Num start ():
|
||
|
Kernel::my_parent.init_done ()
|
||
|
framebuffer = (unsigned *)0x15000
|
||
|
Kernel::Caps caps = Kernel::my_parent.get_device <Display> ()
|
||
|
Display display = caps.get (0)
|
||
|
int x = r, y = r, dx = 3, dy = 0
|
||
|
Kernel::Cap eof = Kernel::my_receiver.create_capability (0)
|
||
|
while true:
|
||
|
display.set_eof_cb (eof)
|
||
|
Kernel::wait ()
|
||
|
ball (x, y, false)
|
||
|
x += dx
|
||
|
y += dy
|
||
|
if y + r >= 240:
|
||
|
dy = -dy
|
||
|
y = 240 - r
|
||
|
if x - r < 0:
|
||
|
x = r
|
||
|
dx = -dx
|
||
|
if x + r >= 320:
|
||
|
x = 320 - r
|
||
|
dx = -dx
|
||
|
if y == 240 - r && dy == 0:
|
||
|
dy = -21
|
||
|
++dy
|
||
|
ball (x, y, true)
|