Skip to content

Instantly share code, notes, and snippets.

@mroberti
Created March 26, 2020 15:40
Show Gist options
  • Save mroberti/3810d0c601ddbcd4eca18a53dd33587a to your computer and use it in GitHub Desktop.
Save mroberti/3810d0c601ddbcd4eca18a53dd33587a to your computer and use it in GitHub Desktop.
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_x = ease current_tick: args.state.tick_count,
start_tick: args.state.start_tick,
duration: args.state.duration,
start_value: args.state.start_x,
end_value: args.state.end_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 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])
$gtk.args.outputs.labels << [640, 400, "TODO: look at line 36.", 0, 1]
totalDistance = opts[:end_value] - opts[:start_value]
theValue = (totalDistance*((opts[:current_tick]-opts[:start_tick])/opts[:duration]))+opts[:start_value]
puts theValue
return theValue
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment