from math import sin, radians size(600, 400) speed(30) def setup(): global i, s, k s = 0 # sinus counter goes from 0 to 1 by a sinus curve i = 0 # degrees goes from -90 to 90 degrees k = 4 # direktion and steps goes -1 to 1 def draw(): global i, s, k fill(0.3, 0.4, 0.2) s = sin(radians(i)) # radians converts degree to the sinus compatible input # s runs from 0 to 1 by sinus if ((i > 90) and (k > 0)) : # when the i goes higher then 90degree and k still is k = -4 # positive then change the direction of counting by negative k if (i <= -90 and k < 0) : # when i goes lower then -90 degree and k still is negative k = 4 # then change the direction of counting by positive k i = i + k # i is a counter by direction and step size of k rect(60, 60, 260+240 * s, 200 )
sorry this a cleaner version of my comments::
from math import sin, radians size(600, 400) speed(30) def setup(): global i, s, k s = 0 # sinus counter goes from -1 to 1 by a sinus curve i = 0 # degrees goes from -90 to 90 degrees k = 4 # direction and step size def draw(): global i, s, k fill(0.3, 0.4, 0.2) s = sin(radians(i)) # radians converts degree to the sinus compatible input # s runs from -1 to 1 by sinus if ((i > 90) and (k > 0)) : # when the i goes higher then 90degree and k still is k = -4 # positive then change the direction of counting by negative k if (i <= -90 and k < 0) : # when i goes lower then -90 degree and k still is negative k = 4 # then change the direction of counting by positive k i = i + k # i is a counter by direction and step size of k rect(60, 60, 260+240 * s, 200 )
By shuttering do you mean jumpy and uneven?
On my machine the animation from this code is jumpy with k set at 4 like it is. One thing to remember is that a sin wave is not linear so s is not going to move at the same rate throughout the animation. For instance when i is around 180 degrees s will be changing by about .07 between frames but when i is closer to 270 s will change by 0.004. So it will be jumpier in certain parts of the cycle than others.
Also, since the sin function is periodic you can save yourself some code--those if statements are doing something the sin function already does by itself. This might be a little easier to work with and lets you change k in the setup routine without it getting reset in the draw :
from math import sin, radians size(600, 400) speed(30) def setup(): global i, s, k i = 0 # degrees k = 4 # step size def draw(): global i, s, k fill(0.3, 0.4, 0.2) s = sin(radians(i)) # radians converts degree to the sinus compatible input i += k rect(60, 60, 260+240 * s, 200 )
i think i found my mistake - it is not the code.
i start the export while my animation was still running.
it seems that NodeBox is still execute the realtime animation while it export the movie.
if i stop the animation before everything is fine with 60fps
maybe it would be better to avoid this by default stopping realtime animations before export.
thanks a lot anonymous, you also showed me a nicer syntax!
by the way - what ist the limit of a counter which is running endless in a direction?
cheers,
toby
I'm pretty sure python will use long integers when it needs to. This should mean the the counter is only limited by memory which should be more than enough for almost anything. For instance nodebox doesn't balk at all at this enormous number:
print 2**1000
shuttered video export
Posted by toby_ on Jun 04, 2008i just have made a simple example which shows a square
scaled by a sinus curve.
when i export this with 30 fps and like 240 frames duration
i got a absolute shuttering movie.
the frame rate is set by speed(30) - so i dont understand
whats wrong.
i have also export the movie from tif to a more play able compression like intermedia or jpg or h264 - but thats not the
problem. the frames are already shuttered.
from math import sin, radians
size(600, 400)
speed(30)
def setup():
global i, s, k
s = 0 # sinus counter goes from 0 to 1 by a sinus curve
i = 0 # degrees goes from -90 to 90 degrees
k = 4 # direktion and steps goes -1 to 1
def draw():
global i, s, k
fill(0.3, 0.4, 0.2)
s = sin(radians(i)) # radians converts degree to the sinus compatible input
# s runs from 0 to 1 by sinus
if ((i > 90) and (k > 0)) : # when the i goes higher then 90degree and k still is
k = -4 # positive then change the direction of counting by negative k
if (i <= -90 and k < 0) : # when i goes lower then -90 degree and k still is negative
k = 4 # then change the direction of counting by positive k
i = i + k # i is a counter by direction and step size of k
rect(60, 60, 260+240 * s, 200 )