Skip to content

Instantly share code, notes, and snippets.

@KonnorRogers
Created January 12, 2025 00:55
Show Gist options
  • Save KonnorRogers/c4f473df7d47640b6da77457acaaa1fd to your computer and use it in GitHub Desktop.
Save KonnorRogers/c4f473df7d47640b6da77457acaaa1fd to your computer and use it in GitHub Desktop.
drawing an "empty" circle in dragonruby
def draw_circle(args, diameter: 200)
diameter.times do |i|
r1 = diameter / 2
h1 = i - r1
l1 = Math::sqrt(r1 * r1 - h1 * h1)
r2 = r1 - 4 # Modify this to adjust the size of the inner circle. the bigger this is, the more empty space, the smaller, the less empty space.
h2 = (i - r2) - (r1 - r2)
if h2.abs < r2
l2 = Math::sqrt(r2 * r2 - h2 * h2)
args.render_target(:open_circle).lines << [i, r1 - l2, i, r1 - l1]
args.render_target(:open_circle).lines << [i, r1 + l2, i, r1 + l1]
else
args.render_target(:open_circle).lines << [i, r1 - l1, i, r1 + l1]
end
end
circle = {
source_x: 0, source_y: 0,
source_w: diameter, source_h: diameter
}
args.outputs.sprites << circle.merge({
x: 500,
y: 500,
w: 200, h: 200, path: :open_circle,
})
end
@KonnorRogers
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment