Created
January 12, 2025 00:55
-
-
Save KonnorRogers/c4f473df7d47640b6da77457acaaa1fd to your computer and use it in GitHub Desktop.
drawing an "empty" circle in dragonruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also:
https://gist.github.com/xenobrain/bd1d5e8909686930e27f658e3d385d7a