Rotate an Image
Moderators: heatherlaine, kevinmiller, robinmiller, malte
Rotate an Image
Hi all, I'm new to LiveCode and Animation Engine although I do have programming experience in other languages. This may seem simple but I'm trying create an effect on a graphic that shows it spinning and fading in, and enlarging in place simultaneously as the page opens. So far I've tried the code below which works for the most part but I don't know how to 1) Do this with Animation Engine and 2) Create the effects simultaneously. I see a function in AE called spiral and I'm assuming that it may do the rotation but there is no sample and I've been unable to get it to work. Any help is appreciated.
repeat with BlendOut = 100 to 0 step -1
set the blendLevel of image splash.png to BlendOut
wait 10 milliseconds with messages
end repeat
repeat with imageAngle = 360 to 0 step -10
set the angle of image "splash.png" to imageAngle
wait 10 milliseconds with messages
end repeat
repeat with imagePercent = 100 to 1 step -3
set the width of image "splash.png" to (tWidth/imagePercent)
set the height of image "splash.png" to (tHeight/imagePercent)
wait 35 milliseconds with messages
end repeat
repeat with BlendOut = 100 to 0 step -1
set the blendLevel of image splash.png to BlendOut
wait 10 milliseconds with messages
end repeat
repeat with imageAngle = 360 to 0 step -10
set the angle of image "splash.png" to imageAngle
wait 10 milliseconds with messages
end repeat
repeat with imagePercent = 100 to 1 step -3
set the width of image "splash.png" to (tWidth/imagePercent)
set the height of image "splash.png" to (tHeight/imagePercent)
wait 35 milliseconds with messages
end repeat
Re: Rotate an Image
Hi basheps,
welcome to liveCode and AE!
what you will want to read up on is the usage of send in time. Using repeat is not your friend in this context.
In an animationEngine context, many handlers exist to help you doing fades and stuff like that.
look at aeFadeIn / aeFadeOut in the animationEngine docs. It is a simple command with a few parameters that let you specify, how you would want your object to fade in (amount of time the fade should take, etc). Now, aeFadeIn sends a callback message to the target object. You can trap that and do the rotation in the callback handler.
Please let me know if you need a specific code example and I will be whipping something up.
All the best,
Malte
welcome to liveCode and AE!
what you will want to read up on is the usage of send in time. Using repeat is not your friend in this context.
In an animationEngine context, many handlers exist to help you doing fades and stuff like that.
look at aeFadeIn / aeFadeOut in the animationEngine docs. It is a simple command with a few parameters that let you specify, how you would want your object to fade in (amount of time the fade should take, etc). Now, aeFadeIn sends a callback message to the target object. You can trap that and do the rotation in the callback handler.
Please let me know if you need a specific code example and I will be whipping something up.
All the best,
Malte
-
- VIP Livecode Opensource Backer
- Posts: 4000
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Rotate an Image
Hi basheps,
it turns out that it is not easy to set the angle of an image and change its size at the same time. If you set the angle of an image Livecode always uses the original image to calculate the angle, this overrides the setting of width and height.
With a bit of image vodoo you can arrive at an image that you set the angle and the size at the same time.
Here is a stack that lets you make a png image from a text field. You then have three buttons that either change the angle, grow the image or both.
It uses the send in time structure Malte recommended. It does not use animation engine. (actually I doubt that animation engine provides a means to rotate and grow an image at the same time, it is such an ugly hack )
Have a look at the scripts.
Kind regards
Bernd
it turns out that it is not easy to set the angle of an image and change its size at the same time. If you set the angle of an image Livecode always uses the original image to calculate the angle, this overrides the setting of width and height.
With a bit of image vodoo you can arrive at an image that you set the angle and the size at the same time.
Here is a stack that lets you make a png image from a text field. You then have three buttons that either change the angle, grow the image or both.
It uses the send in time structure Malte recommended. It does not use animation engine. (actually I doubt that animation engine provides a means to rotate and grow an image at the same time, it is such an ugly hack )
Have a look at the scripts.
Kind regards
Bernd
Re: Rotate an Image
This is perfect. Exactly what I was looking for! Thank you so much for the sample and for the tips.
Re: Rotate an Image
Just curious on how to implement this sample on multiple images simultaneously. I've tried:
but it only does the rotation on the last image and not the first.
What is the correct way to do this? Thanks in advance.
Code: Select all
on openCard
-- start rotation/animation
initVars "splash1.png"
initVars "splash2.png"
end openCard
on initVars pSplashImage
put pSplashImage into sSplashImage
put the width of image sSplashImage into sWidth
put the height of image sSplashImage into sHeight
put the loc of image sSplashImage into sLoc
put 100 into sCounter
send AnimateSplash to me in 0 milliseconds
end initVars
What is the correct way to do this? Thanks in advance.
-
- VIP Livecode Opensource Backer
- Posts: 4000
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Rotate an Image
Hi basheps,
Kind regards
Bernd
try this:Just curious on how to implement this sample on multiple images simultaneously
Kind regards
Bernd
Re: Rotate an Image
Once again thank you for the sample bn. I am going to try to work on this some more in order to make it a reusable function that I can pass in an array of images or all images in a group and have it rotate each one together.
-
- VIP Livecode Opensource Backer
- Posts: 4000
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Rotate an Image
Hi basheps,
here is a version that uses an array and works with as many images as you want, just pass the names of the images.
But if you overdo it Livecode will be slow to rotate too many images at the same time, I tried it with 6 images and it is noticeably slower. If you change the stepsize of sCounter you can compensate for that to some degree.
It also depends on the size of the images you want to rotate.
I thought I let you try it first but in case it did not work out with the array here is one way to do it.
Kind regards
Bernd
here is a version that uses an array and works with as many images as you want, just pass the names of the images.
But if you overdo it Livecode will be slow to rotate too many images at the same time, I tried it with 6 images and it is noticeably slower. If you change the stepsize of sCounter you can compensate for that to some degree.
It also depends on the size of the images you want to rotate.
I thought I let you try it first but in case it did not work out with the array here is one way to do it.
Kind regards
Bernd
Re: Rotate an Image
Once again it worked perfectly! Thanks again Bernd.
Re: Rotate an Image
MODERATORS why hasn't the previous post been removed yet?
[Moderator edit]
The post this refers to has now been removed
[/moderator edit]
[Moderator edit]
The post this refers to has now been removed
[/moderator edit]
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- VIP Livecode Opensource Backer
- Posts: 9833
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Rotate an Image
I would like to remove it, but there's something odd about this thread which prevents me from doing so. We'll have to wait for another admin with higher privileges to take care of it.Mark wrote:MODERATORS why hasn't the previous post been removed yet?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Rotate an Image
OK, thanks for letting me/us know.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode