-
-
Notifications
You must be signed in to change notification settings - Fork 490
circ
TimotheeGreg edited this page Aug 24, 2023
·
16 revisions
circ (x, y, radius, color)
- x, y : the coordinates of the circle's center
- radius : the radius of the circle in pixels
- color: the index of the desired color in the current palette
This function draws a filled circle of the desired radius and color with its center at x, y. It uses the Bresenham algorithm.
-- title: circ demo
-- author: Filippo
-- desc: circ wiki demo
-- script: lua
-- pal: 0000001b2632493c2bf7e26bbe263344891a31a2f2ffffff005784a46422ffffffeb8931a3ce27b2dcefbfce72ffffff
--init balls
balls={}
d=1
for i=0,50 do
ball={x =math.random(10,220),
y =math.random(10,126),
dx=math.random(1,2)*d,
dy=math.random(1,2)*d,
r =math.random(6,12),
c =math.random(1,6)}
balls[i]=ball
d=d*-1
end
function TIC()
cls()
for k,b in pairs(balls) do
--move the ball
b.x=b.x+b.dx
b.y=b.y+b.dy
--check right/left walls
if b.x >= 240-b.r then
b.x=240-b.r-1 --constraints inside the wall
b.dx=-b.dx --reverse direction
elseif b.x < b.r then
b.x=b.r
b.dx=-b.dx
end
--check bottom/top walls
if b.y >= 136-b.r then
b.y=136-b.r-1
b.dy=-b.dy
elseif b.y < b.r then
b.y=b.r
b.dy=-b.dy
end
--draw balls
circ(b.x,b.y,b.r,b.c)
circ(b.x+b.r/4,b.y-b.r/4,b.r/4,b.c+7)
end
end
-- title: circ example
-- author: Al Rado
-- desc: particular qualities 'circ'
-- script: lua
poke(0x3FF8,2)
cls(15)
SCREEN_WIDTH=240
SCREEN_HEIGHT=136
STEP=20
for radius=1, 6 do
--vertical
circ(radius,radius*STEP,radius,0)
circ(SCREEN_WIDTH-radius-1,radius*STEP,radius,0)-- minus one!
--horizontal
circ(radius*STEP,radius,radius,0)
circ(radius*STEP,SCREEN_HEIGHT-radius-1,radius,0)-- minus one!
end
function TIC() end
TIC-80 tiny computer https://tic80.com | Twitter | Telegram | Terms
Built-in Editors
Console
Platform
RAM & VRAM | Display | Palette | Bits per Pixel (BPP) |
.tic
Format | Supported Languages
Other
Tutorials | Code Snippets | Libraries | External Tools | FFT
API
- BDR (0.90)
- BOOT (1.0)
- MENU
- OVR (deprecated)
- SCN (deprecated)
- TIC
- btn & btnp
- circ & circb
- clip
- cls
- elli & ellib (0.90)
- exit
- fget & fset (0.80)
- font
- key & keyp
- line
- map
- memcpy & memset
- mget & mset
- mouse
- music
- peek, peek4
- peek1, peek2 (1.0)
- pix
- pmem
- poke, poke4
- poke1, poke2 (1.0)
- rect & rectb
- reset
- sfx
- spr
- sync
- ttri (1.0)
- time
- trace
- tri & trib (0.90)
- tstamp (0.80)
- vbank (1.0)