2020-09-20 21:49:36 +00:00
|
|
|
%import textio
|
|
|
|
%import syslib
|
2020-03-14 16:11:10 +00:00
|
|
|
%zeropage basicsafe
|
|
|
|
|
2023-06-03 17:14:45 +00:00
|
|
|
; Note: this program can be compiled for multiple target systems.
|
2020-03-14 16:11:10 +00:00
|
|
|
|
|
|
|
main {
|
|
|
|
|
|
|
|
sub start() {
|
2021-02-04 16:47:52 +00:00
|
|
|
txt.print("rectangles\nand circle\ndrawing.\n")
|
2020-03-14 16:11:10 +00:00
|
|
|
|
2020-03-22 22:50:15 +00:00
|
|
|
ubyte r
|
|
|
|
for r in 3 to 12 step 3 {
|
|
|
|
circle(20, 12, r)
|
|
|
|
}
|
2020-03-21 23:43:46 +00:00
|
|
|
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.print("enter for disc:")
|
2023-04-28 21:13:03 +00:00
|
|
|
void cbm.CHRIN()
|
|
|
|
txt.nl()
|
2020-08-30 17:31:20 +00:00
|
|
|
txt.clear_screen()
|
2020-03-21 23:43:46 +00:00
|
|
|
disc(20, 12, 12)
|
|
|
|
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.print("enter for rectangles:")
|
2023-04-28 21:13:03 +00:00
|
|
|
void cbm.CHRIN()
|
|
|
|
txt.nl()
|
2020-08-30 17:31:20 +00:00
|
|
|
txt.clear_screen()
|
2020-03-21 23:43:46 +00:00
|
|
|
|
|
|
|
rect(4, 8, 37, 23, false)
|
|
|
|
rect(20, 12, 30, 20, true)
|
|
|
|
rect(10, 10, 10, 10, false)
|
|
|
|
rect(6, 0, 16, 20, true)
|
|
|
|
|
|
|
|
|
2024-02-04 22:18:11 +00:00
|
|
|
sub rect(ubyte x1, ubyte y1, ubyte x2, ubyte y2, bool fill) {
|
2020-03-21 23:43:46 +00:00
|
|
|
ubyte x
|
|
|
|
ubyte y
|
|
|
|
if fill {
|
|
|
|
for y in y1 to y2 {
|
|
|
|
for x in x1 to x2 {
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.setcc(x, y, 42, x+y)
|
2020-03-21 23:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for x in x1 to x2 {
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.setcc(x, y1, 42, 8)
|
|
|
|
txt.setcc(x, y2, 42, 8)
|
2020-03-21 23:43:46 +00:00
|
|
|
}
|
|
|
|
if y2>y1 {
|
|
|
|
for y in y1+1 to y2-1 {
|
2020-08-27 16:10:22 +00:00
|
|
|
txt.setcc(x1, y, 42, 7)
|
|
|
|
txt.setcc(x2, y, 42, 7)
|
2020-03-21 23:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub circle(ubyte xcenter, ubyte ycenter, ubyte radius) {
|
|
|
|
; Midpoint algorithm
|
2020-03-26 22:33:55 +00:00
|
|
|
ubyte x = radius
|
|
|
|
ubyte y = 0
|
2020-06-02 19:27:38 +00:00
|
|
|
byte decisionOver2 = 1-x as byte
|
2020-03-14 16:11:10 +00:00
|
|
|
|
|
|
|
while x>=y {
|
2023-11-05 15:39:36 +00:00
|
|
|
txt.setcc(xcenter + x, ycenter + y, 81, 1)
|
|
|
|
txt.setcc(xcenter - x, ycenter + y, 81, 2)
|
|
|
|
txt.setcc(xcenter + x, ycenter - y, 81, 3)
|
|
|
|
txt.setcc(xcenter - x, ycenter - y, 81, 4)
|
|
|
|
txt.setcc(xcenter + y, ycenter + x, 81, 5)
|
|
|
|
txt.setcc(xcenter - y, ycenter + x, 81, 6)
|
|
|
|
txt.setcc(xcenter + y, ycenter - x, 81, 7)
|
|
|
|
txt.setcc(xcenter - y, ycenter - x, 81, 8)
|
2020-03-21 23:43:46 +00:00
|
|
|
y++
|
2023-11-05 15:39:36 +00:00
|
|
|
if decisionOver2>=0 {
|
2020-03-21 23:43:46 +00:00
|
|
|
x--
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 -= 2*x
|
2020-03-21 23:43:46 +00:00
|
|
|
}
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 += 2*y
|
|
|
|
decisionOver2++
|
2020-03-21 23:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub disc(ubyte cx, ubyte cy, ubyte radius) {
|
|
|
|
; Midpoint algorithm, filled
|
2020-03-26 22:33:55 +00:00
|
|
|
ubyte x = radius
|
|
|
|
ubyte y = 0
|
2020-06-02 19:27:38 +00:00
|
|
|
byte decisionOver2 = 1-x as byte
|
2020-03-26 22:33:55 +00:00
|
|
|
ubyte xx
|
2020-03-21 23:43:46 +00:00
|
|
|
|
|
|
|
while x>=y {
|
2020-12-06 00:07:57 +00:00
|
|
|
xx = cx-x
|
|
|
|
repeat 2*x+1 {
|
2023-11-05 15:39:36 +00:00
|
|
|
txt.setcc(xx, cy + y, 81, 11)
|
|
|
|
txt.setcc(xx, cy - y, 81, 12)
|
2020-12-06 00:07:57 +00:00
|
|
|
xx++
|
2020-03-21 23:43:46 +00:00
|
|
|
}
|
2020-12-06 00:07:57 +00:00
|
|
|
xx = cx-y
|
|
|
|
repeat 2*y+1 {
|
2023-11-05 15:39:36 +00:00
|
|
|
txt.setcc(xx, cy + x, 81, 13)
|
|
|
|
txt.setcc(xx, cy - x, 81, 14)
|
2020-12-06 00:07:57 +00:00
|
|
|
xx++
|
2020-03-21 23:43:46 +00:00
|
|
|
}
|
2020-03-14 16:11:10 +00:00
|
|
|
y++
|
2023-11-05 15:39:36 +00:00
|
|
|
if decisionOver2>=0 {
|
2020-03-14 16:11:10 +00:00
|
|
|
x--
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 -= 2*x
|
2020-03-14 16:11:10 +00:00
|
|
|
}
|
2023-11-05 15:39:36 +00:00
|
|
|
decisionOver2 += 2*y
|
|
|
|
decisionOver2++
|
2020-03-14 16:11:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|