Anim Editor: added more animation interpolation types, greyed out timeline that isn't part of the animation

This commit is contained in:
Maruno17
2024-03-12 19:11:51 +00:00
parent f0fae4b9ec
commit ae32d59eb9
7 changed files with 117 additions and 32 deletions

View File

@@ -22,16 +22,14 @@ class Bitmap
end
end
# TODO: Add more curve types once it's decided which ones they are. See
# INTERPOLATION_TYPES.
def draw_interpolation_line(x, y, width, height, gradient, type, color)
start_x = x
end_x = x + width - 1
start_y = (gradient) ? y + height - 1 : y
end_y = (gradient) ? y : y + height - 1
case type
when :linear
# NOTE: https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
start_x = x
end_x = x + width - 1
start_y = (gradient) ? y + height - 1 : y
end_y = (gradient) ? y : y + height - 1
dx = end_x - start_x
dy = -((end_y - start_y).abs)
error = dx + dy
@@ -52,6 +50,40 @@ class Bitmap
draw_y += (gradient) ? -1 : 1
end
end
when :ease_in, :ease_out, :ease_both # Quadratic
start_y = y + height - 1
end_y = y
points = []
(width + 1).times do |frame|
x = frame / width.to_f
case type
when :ease_in
points[frame] = (end_y - start_y) * x * x
when :ease_out
points[frame] = (end_y - start_y) * (1 - ((1 - x) * (1 - x)))
when :ease_both
if x < 0.5
points[frame] = (end_y - start_y) * x * x * 2
else
points[frame] = (end_y - start_y) * (1 - (((-2 * x) + 2) * ((-2 * x) + 2) / 2))
end
end
points[frame] = points[frame].round
end
width.times do |frame|
line_y = points[frame]
if frame == 0
line_height = 1
else
line_height = [(points[frame] - points[frame - 1]).abs, 1].max
end
if !gradient # Going down
line_y = -(height - 1) - line_y - line_height + 1
end
fill_rect(start_x + frame, start_y + line_y, 1, line_height, color)
end
else
raise _INTL("Unknown interpolation type {1}.", type)
end
end
end