Challenge:
Version:
1
Winner?:
No
Code Snippet:
sync on : sync rate 100 #constant scrx screen width() #constant scry screen height() #constant sm = 40 #constant sl = 10.0 #constant grav = -0.2 type T x# as float y# as float sx# as float sy# as float endtype dim S(sm) as T `vectors r = make vector2(1) `Reposition all segments for a = 1 to sm S(a).x# = 512 + a*5 S(a).y# = 512 next a do cls S(1).x# = mousex() S(1).y# = scrY - mousey() for a = 2 to sm HandleSegment(a) next a sync loop function HandleSegment(a) `Get the position of the parent segment px# = S(a - 1).x# py# = S(a - 1).y# dx# = S(a).x# - px# dy# = S(a).y# - py# `Gravity S(a).sy# = S(a).sy# + grav `Get the length set vector2 1, dx#, dy# l# = length vector2(1) `If the length is bigger than the max if l# > sl `Apply force fx# = dx# / l# * S(a).sy# fy# = dy# / l# * S(a).sy# inc S(a).sx#, fx# * 0.8 if dy# < 0 then inc S(a).sy#, fy# `Reposition S(a).x# = px# + (dx# / l# * sl) S(a).y# = py# + (dy# / l# * sl) endif `the acceleration depends on the mass, but i'll use a standard value S(a).sx# = S(a).sx# * 0.8 S(a).sy# = S(a).sy# * 0.8 `Update position inc S(a).x#, S(a).sx# inc S(a).y#, S(a).sy# ink rgb(rnd(255), rnd(255), rnd(255)), 0 line S(a).x#, scry - S(a).y#, px#, scry - py# endfunction