mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 08:29:25 +00:00
adding circle and disc to gfx2
This commit is contained in:
parent
ffffcdd50a
commit
cdcda27d07
@ -98,6 +98,86 @@ gfx2 {
|
||||
position(0, 0)
|
||||
}
|
||||
|
||||
sub horizontal_line(uword x, uword y, ubyte length, ubyte color) {
|
||||
when active_mode {
|
||||
1 -> {
|
||||
; 8bpp mode
|
||||
gfx2.plot(x, y, color)
|
||||
repeat length-1
|
||||
gfx2.next_pixel(color)
|
||||
}
|
||||
0, 128 -> {
|
||||
; 1 bpp mode
|
||||
; TODO optimize this to plot 8 pixels at once while possible
|
||||
repeat length {
|
||||
gfx2.plot(x, y, color)
|
||||
x++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub circle(uword xcenter, uword ycenter, ubyte radius, ubyte color) {
|
||||
; Midpoint algorithm.
|
||||
ubyte @zp xx = radius
|
||||
ubyte @zp yy = 0
|
||||
word @zp decisionOver2 = (1 as word)-xx
|
||||
; R14 = internal plot X
|
||||
; R15 = internal plot Y
|
||||
|
||||
while xx>=yy {
|
||||
cx16.r14 = xcenter + xx
|
||||
cx16.r15 = ycenter + yy
|
||||
plot(cx16.r14, cx16.r15, color)
|
||||
cx16.r14 = xcenter - xx
|
||||
plot(cx16.r14, cx16.r15, color)
|
||||
cx16.r14 = xcenter + xx
|
||||
cx16.r15 = ycenter - yy
|
||||
plot(cx16.r14, cx16.r15, color)
|
||||
cx16.r14 = xcenter - xx
|
||||
plot(cx16.r14, cx16.r15, color)
|
||||
cx16.r14 = xcenter + yy
|
||||
cx16.r15 = ycenter + xx
|
||||
plot(cx16.r14, cx16.r15, color)
|
||||
cx16.r14 = xcenter - yy
|
||||
plot(cx16.r14, cx16.r15, color)
|
||||
cx16.r14 = xcenter + yy
|
||||
cx16.r15 = ycenter - xx
|
||||
plot(cx16.r14, cx16.r15, color)
|
||||
cx16.r14 = xcenter - yy
|
||||
plot(cx16.r14, cx16.r15, color)
|
||||
|
||||
yy++
|
||||
if decisionOver2<=0
|
||||
decisionOver2 += (yy as word)*2+1
|
||||
else {
|
||||
xx--
|
||||
decisionOver2 += (yy as word -xx)*2+1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub disc(uword xcenter, uword ycenter, ubyte radius, ubyte color) {
|
||||
; Midpoint algorithm, filled
|
||||
ubyte @zp xx = radius
|
||||
ubyte @zp yy = 0
|
||||
word @zp decisionOver2 = (1 as word)-xx
|
||||
|
||||
while xx>=yy {
|
||||
horizontal_line(xcenter-xx, ycenter+yy, xx*2+1, color)
|
||||
horizontal_line(xcenter-xx, ycenter-yy, xx*2+1, color)
|
||||
horizontal_line(xcenter-yy, ycenter+xx, yy*2+1, color)
|
||||
horizontal_line(xcenter-yy, ycenter-xx, yy*2+1, color)
|
||||
yy++
|
||||
if decisionOver2<=0
|
||||
decisionOver2 += (yy as word)*2+1
|
||||
else {
|
||||
xx--
|
||||
decisionOver2 += (yy as word -xx)*2+1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub plot(uword x, uword y, ubyte color) {
|
||||
ubyte[8] bits = [128, 64, 32, 16, 8, 4, 2, 1]
|
||||
uword addr
|
||||
@ -121,6 +201,7 @@ gfx2 {
|
||||
}
|
||||
; activate vera auto-increment mode so next_pixel() can be used after this
|
||||
cx16.VERA_ADDR_H = (cx16.VERA_ADDR_H & %00000111) | %00010000
|
||||
color = cx16.VERA_DATA0
|
||||
}
|
||||
|
||||
sub position(uword x, uword y) {
|
||||
|
@ -8,7 +8,7 @@ main {
|
||||
sub start () {
|
||||
gfx2.text_charset(3)
|
||||
|
||||
ubyte[] modes = [0, 1, 128]
|
||||
ubyte[] modes = [1, 0, 128]
|
||||
ubyte mode
|
||||
for mode in modes {
|
||||
gfx2.screen_mode(mode)
|
||||
@ -17,36 +17,25 @@ main {
|
||||
for tp in 0 to 15 {
|
||||
gfx2.text(19+tp,20+tp*11, 5, @"ScreenCODE text! 1234![]<>#$%&*()")
|
||||
}
|
||||
cx16.wait(120)
|
||||
cx16.wait(200)
|
||||
}
|
||||
|
||||
gfx2.screen_mode(255)
|
||||
txt.print("done!\n")
|
||||
}
|
||||
|
||||
sub draw() {
|
||||
uword offset
|
||||
ubyte angle
|
||||
uword x
|
||||
uword y
|
||||
when gfx2.active_mode {
|
||||
0, 1 -> {
|
||||
for offset in 0 to 90 step 3 {
|
||||
for angle in 0 to 255 {
|
||||
x = $0008+sin8u(angle)/2
|
||||
y = $0008+cos8u(angle)/2
|
||||
gfx2.plot(x+offset*2,y+offset, lsb(x+y))
|
||||
}
|
||||
}
|
||||
}
|
||||
128 -> {
|
||||
for offset in 0 to 190 step 6 {
|
||||
for angle in 0 to 255 {
|
||||
x = $0008+sin8u(angle)
|
||||
y = $0008+cos8u(angle)
|
||||
gfx2.plot(x+offset*2,y+offset, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
ubyte radius
|
||||
|
||||
for radius in 110 downto 8 step -4 {
|
||||
gfx2.circle(gfx2.width/2, (gfx2.height/2 as ubyte), radius, radius)
|
||||
}
|
||||
|
||||
gfx2.disc(gfx2.width/2, gfx2.height/2, 108, 255)
|
||||
}
|
||||
}
|
||||
|
||||
gfx3 {
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user