mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
cx16 spotlight example
This commit is contained in:
parent
4bb9ae61f2
commit
f56c12ee4e
@ -121,6 +121,7 @@ class TestCompilerOnExamplesCx16: FunSpec({
|
||||
"rasterbars",
|
||||
"sincos",
|
||||
"snow",
|
||||
"spotlight",
|
||||
"tehtriz",
|
||||
"testgfx2",
|
||||
),
|
||||
|
@ -1,6 +1,8 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- optimize a "dangling else"
|
||||
|
||||
...
|
||||
|
||||
|
||||
|
51
examples/cx16/spotlight.p8
Normal file
51
examples/cx16/spotlight.p8
Normal file
@ -0,0 +1,51 @@
|
||||
%import math
|
||||
%import palette
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
const uword WIDTH=320
|
||||
const ubyte HEIGHT=240
|
||||
|
||||
uword xx
|
||||
ubyte yy
|
||||
void cx16.screen_mode(128, false)
|
||||
cx16.mouse_config2(1)
|
||||
|
||||
; prefill
|
||||
for yy in 0 to HEIGHT-1 {
|
||||
cx16.FB_cursor_position(0, yy)
|
||||
for xx in 0 to WIDTH-1 {
|
||||
cx16.FB_set_pixel(math.direction(128, HEIGHT/2, clampx(xx), yy) + 128)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ubyte previous_direction
|
||||
ubyte new_direction
|
||||
|
||||
; dim the screen
|
||||
for new_direction in 128 to 128+23
|
||||
palette.set_color(new_direction, $024)
|
||||
|
||||
; spotlight
|
||||
repeat {
|
||||
void cx16.mouse_pos()
|
||||
new_direction = math.direction(128, HEIGHT/2, clampx(cx16.r0), cx16.r1L)
|
||||
if new_direction != previous_direction {
|
||||
sys.waitvsync()
|
||||
palette.set_color(new_direction+128, math.rndw())
|
||||
palette.set_color(previous_direction+128, $024)
|
||||
previous_direction = new_direction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub clampx(uword screenx) -> ubyte {
|
||||
;; return clamp(screenx, 32, 255+32)-32 as ubyte
|
||||
if screenx<32
|
||||
return 0
|
||||
else if screenx>255+32
|
||||
return 255
|
||||
return lsb(screenx-32)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user