Need to create animated gear component

Posted on 2005-05-16
Last Modified: 2013-11-17
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
Question by:DPINCGK
    LVL 16

    Expert Comment

    by:George Tokas
    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....


    Author Comment

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

    Expert Comment

    by:George Tokas
    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..


    Author Comment

    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.

    LVL 16

    Accepted Solution

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



    Author Comment

    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. :)

    LVL 16

    Expert Comment

    by:George Tokas
    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...

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now