# How to produce rotating LED effect

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

## 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 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 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 on other sites
You're welcome :). Good luck with your project.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 46
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002033
×