Click here to Skip to main content
15,868,141 members
Articles / Multimedia / GDI+

A Thumb Rotator

Rate me:
Please Sign up or sign in to vote.
4.82/5 (23 votes)
2 Dec 2008CPOL2 min read 49.9K   2K   49   15
A fast and furious - one step far from - screensaver application.

Image 1

Introduction

First of all, remember, this is not the best way to make a Thumb Rotator!!! And now, let's see what a Thumb Rotator is. It is a program which tells you where your pictures are, and it will show them by rotating them slowly around an ellipse, pretending they are on a 3D space, simulating a mirror on the floor, using fake lighting algorithms...

In this article, there is no DirectX, OpenGL, or anything like them.

First step

First of all, we will arrange the images around an ellipse. To obtain the - let's say - 10 points, with x0, y0 for the center of the screen, and R1 and R2 as great and little radius (it's an ellipse!):

C#
for (int angle=0; angle<360; angle+=36)
{
   double dAngle=DEGREE_TO_RADIANS(angle);
   int x=x0+R1*cos(dAngle);
   int y=y0-R2*sin(dAngle);
   // do something with the x,y - for example, draw the image (scaled!)
}

Animate!

To animate, simply use a timer. And for every step, add some increment to the angle of every image. Take a look at the code in the zip file!

Add perspective

Two simple tricks: first, draw images from the top Y position to the bottom. In an ellipse-arranged-thumb-rotator, this works fine. Second, draw scaled from the top Y position to the bottom. The images on the top have to be smaller than the images on the bottom.

Add lighting effect

To draw the shadow/fading/upside-down image on the bottom, simply follow these steps:

  1. Create a copy of the image
  2. Make it upside-down
  3. For every pixel in the copied image, change the alpha value according to this rule, scaling linear: 255 to the top (no transparence), 0 to the bottom (maximum transparence)

Make images on the top darker. Simply draw a black, semi-transparent rectangle on them!!!

Interact with the mouse

Monitor your mouse while it is being moved!. If it's moving near the center, there should be no rotation. When the mouse is on the left, make the rotation from left to right. When the mouse is on the right, make the rotation in the reverse direction.

Every time you draw an image, remember its position. So, when the mouse is moving, you can perform the "hit test". The "under mouse pointer" image has full light, no darker effect on it (remember the previous paragraph).

That's all! Have fun. Remember, this is not the best way to do it, but it works! :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Leonardo
Italy Italy
Hi Smile | :)
I was born in 1970 (Augusta - Italy).
I live in Taranto - Italy.
I work in Taranto - Italy.
I like computer science!!!
That's all!

Comments and Discussions

 
GeneralMy vote of 5 Pin
nanjiefenghuamie15-Dec-22 7:58
nanjiefenghuamie15-Dec-22 7:58 
GeneralGreat Pin
N. Henrik Lauridsen8-Oct-15 4:39
N. Henrik Lauridsen8-Oct-15 4:39 
QuestionGreat Post. THANK YOU. Pin
Bhavesh Patel29-Jul-15 23:56
Bhavesh Patel29-Jul-15 23:56 
GeneralMy vote of 5 Pin
IKalai4-Apr-13 19:44
IKalai4-Apr-13 19:44 
GeneralThank you Pin
futurejo27-Jul-09 7:05
futurejo27-Jul-09 7:05 
Generaltwo problems Pin
francisngl15-May-09 14:51
francisngl15-May-09 14:51 
GeneralTitle needs work. Pin
muzzdeni5-Mar-09 15:18
muzzdeni5-Mar-09 15:18 
GeneralChange the title Pin
kosmonafta9-Dec-08 21:23
kosmonafta9-Dec-08 21:23 
Generalcool Pin
tigerfCPRJ8-Dec-08 12:13
tigerfCPRJ8-Dec-08 12:13 
QuestionDLL to be integrated? Pin
Hegemon8-Dec-08 7:01
Hegemon8-Dec-08 7:01 
Big Grin | :-D
Hello
I am not a C++ developer, I use VB.NET.
It is very nice!!
Is it easy to convert the form in a control (dll) so we can import it. Not as a screesaver but inside another solution /I am looking for the iTunes effect in my program and this is just great.
Thanks in advance and good work!
Regards.

....

GeneralNice code Pin
johannesnestler5-Dec-08 5:51
johannesnestler5-Dec-08 5:51 
GeneralNice Pin
Dhimant Trivedi5-Dec-08 0:03
Dhimant Trivedi5-Dec-08 0:03 
GeneralThe article needs a better title PinPopular
PIEBALDconsult3-Dec-08 5:08
mvePIEBALDconsult3-Dec-08 5:08 
GeneralNice... Pin
Paw Jershauge2-Dec-08 23:06
Paw Jershauge2-Dec-08 23:06 
Generale = mc^2 Pin
Tefik Becirovic2-Dec-08 22:58
Tefik Becirovic2-Dec-08 22:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.