Created
March 27, 2020 23:18
-
-
Save mroberti/2dbfaa82a0484c40869b761179d15259 to your computer and use it in GitHub Desktop.
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 tick args | |
# defaults | |
args.state.start_x ||= 10 | |
args.state.end_x ||= 1260 | |
args.state.start_tick ||= 180 | |
args.state.duration ||= 300 | |
# calc | |
next_percentage = ease_percentage current_tick: args.state.tick_count, | |
start_tick: args.state.start_tick, | |
duration: args.state.duration | |
next_x = args.state.end_x*next_percentage # TODO: Using the percentage from the function above determine next x | |
# render | |
args.outputs.solids << [next_x, 360, 10, 10] | |
if args.state.tick_count < args.state.start_tick && args.state.tick_count != 0 | |
countdown = args.state.start_tick - args.state.tick_count | |
args.outputs.labels << [640, 400, "#{countdown.idiv(60) + 1}", 10, 1] | |
elsif args.state.tick_count > (args.state.start_tick + args.state.duration) | |
args.outputs.labels << [640, 400, "Simulation has ended. Click anywhere to reset.", 0, 1] | |
end | |
# input | |
if args.inputs.mouse.click | |
args.gtk.reset | |
end | |
end | |
def ease_percentage opts | |
return opts[:start_value] if opts[:current_tick] < opts[:start_tick] | |
return opts[:end_value] if opts[:current_tick] > (opts[:start_tick] + opts[:duration]) | |
# TODO | |
theValue = (opts[:current_tick]- opts[:start_tick])/(opts[:duration]) | |
puts "theValue: " + theValue.to_s | |
return theValue | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment