Need to create animated gear component

Hello there

I need to find or create a visual component which visually displays a rotating gear on an axle (or, a circle would do in a pinch, but I would prefer a gear). The user needs to have control over rotating speed, diameter, color, possibly size and number of teeth (if not too complicated), on/off, direction, and potentially inertia w/friction on shutoff.

I have no clue where to begin here. I have tried to find an existing component and I found an ancient component out there for Delphi 2 which I cannot seem to use (I use C++ Builder 5).

Does anyone know if there is something existing out there that can be adapted to my use?

Greg K
Who is Participating?
George TokasConnect With a Mentor Commented:
I see now...
So... DirectX is out... To mix DirectX even using the wrapper I have in a VCL component it will be pointless... Too much coding...
The component you sended me its also the same...
There are in my oppinion 2 ways..
1. Use a TImage or a TPainBox to display the animation. Use TImageLists to retrieve the stored bitmaps. One other posible way is to have them stored somewere else (a file maybe? ).. Use a TTimer or a place at Application->OnIdle function for triggering frame change. TTimer is better but have some limitations. But easyly can incorporated at the component.
2. You can use TAnimate component to descend your component. But this way you have to use an AVI you have to create. Because TAnimation can be control start frame and stop frame in the animation maybe it is a better approach... The (difficult) in my opinion is to create the AVI with all those you want.

Both of those suggestions are to create a new VCL component and the easiest way is to descend it from existing one. If I needed something like that I tend to use the second way. Recently we discovered some limitation on TImageList. Anyway each gear don't need more than 5 frames for animations if it is big in size. Small sizes need just 2.
So... In case no2.
Create the gears with preset sizes as many as you want. According to the size create the animation frames. Add all those frames to an AVI file. for each size you know the start frame and the number of frames. All those of course have to be added as new properties at your component. the AVI file must be included by default at your component.

When you finish you can create the component at runtime set the properties and run the animation.
I think this is the best way... Allways of course In My Hamble Oppinion...


George TokasCommented:
Post the code (if not to big) of the delphi component to see how we can modify it to work...
If it is big, and you want, contact me in private.. Details at my info page....

DPINCGKAuthor Commented:
Hello George, I emailed you but for anyone else's benefit the component I have tried is located here

It is called TGear and is developed for Delphi 2. However, I am very open to creating something myself. I just have no clue where to start. Initially I thought an animated icon would work, but now I have been wondering if DirectDraw is the way to go.

Greg K
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

George TokasCommented:
Hello Greg..
I received you mail... Thankfully it was not classified as junk mail..:-)
I run the demo and I noticed flickering... Good work though... It is completly made with a kind of TImage or TAnimate... Must me TImage because TAnimate was not a component on Delphi2...
Anyway what you want to do is very easy using DirectX but you need some tools for not to do code too much.
All those depent on the kind of your project.
There are directions to provide you but first I have to know what you want to do... Usually its a (a bit) complicated to mix DirectX with functions in a form... Thats why I said "what you want to do"... If this e-mail you used is valid I can send you a good wrapper around DirectX..

DPINCGKAuthor Commented:
Hi George

OK I will explain in a little more detail what I am envisioning. As mentioned, I use C++ Builder 5 (professional). The idea would be to have a component I can place on the palette that I could not only drop on the form but allocate dynamically, so the user can add gears to the form at runtime (usually this is not a problem with most VCL framework controls).

The end user would be using this control in an application to simulate motion for timing purposes (for instance, to put motor on/off commands in another stream of data, like a video file or so forth). The user would drop markers into the stream to turn a motor on or off, my application would read those from the stream, and the user would get a visual indication that the gear is moving or not.

This is the simplest possible application, but there is also RPM, friction, and inertia to take into effect so that if the user knows these quantities, they can plug them into the program somehow and ultimately have that show in the animation of the component. For instance, when the gear motion is stopped, the animation could slow to a halt depending on friction and inertia parameters. I don't know if the component can accomodate this feature - if not, the application could contain code to continually manipulate the component's speed. Eventually, it may also be possible to link a number of components to create a simulation of a gear box.

So in short here are what I see the properties, events and methods of the component to be:

== Properties ==
Number of teeth (nice to have but not necessary)
Speed in RPM as float
?? Friction
?? Inertia
?? LinkToOtherGears
?? MasterGear
?? SlaveGear

== Methods ==

== Events ==

I have to apologize because perhaps I ham not thinking out all the possibilities here and I don't really know animation components that involve physics really well. I hope this gives enough information.

DPINCGKAuthor Commented:
Thank you gtokas, I appreciate the suggestions. I am going to try method #2 and see how it works. I will visit back again in a day or two to come back and award points and at that point, I may have a question or two.

Thank you once again for your advice. :)

George TokasCommented:
It will be BEST if first solve the problem you have and CREATE what you want and THEN award any points to anyone...
I will be here if you need anything...

P.S. George anyway is the name...:-) The signature is "gtokas" Greg...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.