Skip to content

Instantly share code, notes, and snippets.

@chrisws
Last active November 12, 2023 23:38
Show Gist options
  • Save chrisws/4bbf1b8a1aca58b9a45afdf0014ccbd9 to your computer and use it in GitHub Desktop.
Save chrisws/4bbf1b8a1aca58b9a45afdf0014ccbd9 to your computer and use it in GitHub Desktop.
We've squared the circle
rem https://youtu.be/H3xEbpnv5fo?feature=shared
rem Up and atom - We've squared the circle
rem Made for SmallBASIC https://smallbasic.github.io/
const col1 = RGB(10,255,10)
const col2 = RGB(255,10,10)
const x1 = xmax / 2
const y1 = ymax / 2
const r = 100
const buffer = 10
rem setup for white text on black background
color 15, 0
cls
rem draw the circle
circle x1, y1, r COLOR col1 filled
rem sum up all the coloured pixels
rem buffer accounts for any anti-aliasing
n = 0
for x = x1 - r - buffer to x1 + r + buffer
for y = y1 - r - buffer to y1 + r + buffer
if (point(x, y) != 0) then n++
next
next
rem draw the square
const j = int(sqr(n))
const x = x1 - j / 2
const y = y1 - j / 2
rect x, y, x + j, y + j color col2
print "Side: "; j
print "Radius: ";r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment