Jump to content
  • Advertisement
Sign in to follow this  

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.

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.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!