Monday 3 September 2012

Animation, rotating

Here a simple demo of rotating using DRAW commands, DRAW permits to rotate of any angle anything.
You can draw something the rotate something else, since the rotate command change only what is after it.
Look at this example:



Here the source:

Rebol []
ar: 0
k: 1
;image size is 100x24
temp: func [][compose/deep [draw [ translate 100x100 rotate (if ar > 360   [ar: ar // 360 ]   ar: ar + k   ar) image -50x-12 50x12 logo.gif]]]
view layout [
    b: box 200x200 rate 100 effect temp feel [engage: func [f a e][f/effect: temp show f]]
    c: slider 200x20 0.01 [
        k: to-integer   (face/data * 100 )
        d/text: to-string k
        show [b d]
        ]
    across
    text "Speed:"
    d: text "0001"
    ]
   
   

As you probably noticed,in order to change every time the screen, I added a fell function that 100 times at second redraw (show) the main box. Then I created a function that change every time the block to show. The function is called temp, and it increments every time the rotation angle of the image of a k value.
Temp function return a block to the effect which contains DRAW commands.
What does it mean?
It means that every time the window is showed, with k=1, rotation angle is 0-1-2-3-4-... and so on.
Moving the slider you change the k value, so with k=2, rotation angle is 0-2-4-6-8-... and so on.
Why did I dcide to change k instead of the rate of show?
Theoretically  it's the same, but practically not. You can ask to achieve a frame rate of 100 fps or more to your computer, but if your computer is slow, or you OS don't support such high frame rate, after a high value (for example 60) you won't notice any difference.
On the other hand, increasing the incremental step of rotation, you achieve the goal to visualize an high rotation speed, you eyes can't understand if the image is rotated very quick or with big angle each time.

2 comments: