Sign in to follow this  

How to produce rotating LED effect

This topic is 3413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. http://www.linuxjournal.com/images/webarticles/widget-led_clock.png Taken from: Chumby Redux (2009) [Accessed on: 13/08/2008] Available form: http://www.linuxjournal.com/content/chumby-redux 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
You can rotate images in SDL using the rotozoom functions in the SDL_gfx library.
http://www.ferzkopp.net/joomla/content/view/19/14/

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
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

This topic is 3413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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