Sign in to follow this  

How to produce rotating LED effect

Recommended Posts

NDR008    122
Not sure if this is really an SDL question however I placed it here because in OpenGL I would use the rotate function to achieve the desired effect. Taken from: Chumby Redux (2009) [Accessed on: 13/08/2008] Available form: How would I produce that light going round? (In my case I need a single 'LED' lit at any instant.)

Share this post

Link to post
Share on other sites
kuroioranda    304
You can rotate images in SDL using the rotozoom functions in the SDL_gfx library.

This only rotates a surface, though. To make it rotate around the clock, you'll need a little trig in there as well.

psuedo-code for the basic idea:

void drawLed(int second)
//calculate the angle around the clock based on the second
float angle = second / PI * 2; //assuming angle is measured in radians

//calculate position around clock center
float ledPosX = cos(angle) * DISTANCE_FROM_CLOCK_CENTER;
float ledPosY = sin(angle) * DISTANCE_FROM_CLOCK_CENTER;

//rotate image
SDL_Surface rotatedImage = rotozoomSurface(ledImage, angle, 1.0, 1);

//copy image to screen
SDL_Rect dstRect;
dstRect.x = ledPosX;
dstRect.y = ledPosY;
SDL_BlitSurface (rotatedImage, null, backBuffer, dstRect);

//free the rotated image memory
SDL_FreeSurface (rotatedImage);

Share this post

Link to post
Share on other sites
NDR008    122
Thanks dude, the trig wasn't a problem but the rotation bit. I was thinking on lines of overlapping surfaces to give the impression that it is a square LED and stuff, but now I know how to do it. Thanks :)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this