Results 1 to 4 of 4

Thread: fading triangle

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    fading triangle

    Bit of a big one here, but maybe someone has seen, or written some code that does something like this...

    I have a windows application that draws a rectangle, I want the rectangle to fade out over time... any suggestions (or better yet) code?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Set a timer and redraw the rectangle or triangle (or whatever) with a COLORREF c

    (unsigned char*)&c[0]=(unsigned char*)&a1[0]+time*((unsigned char*)&a2[0]-(unsigned char*)&a1[0])
    (unsigned char*)&c[1]=(unsigned char*)&a1[1]+time*((unsigned char*)&a2[1]-*(unsigned char*)&a1[1])
    (unsigned char*)&c[2]=(unsigned char*)&a1[2]+time*((unsigned char*)&a2[2]-(unsigned char*)&a1[2])

    where a1 is the rectangle orignal colour and a2 is the background colour. the float time should increase from 0 to 1
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    humm no I am not getting it

    I was playing around with what you suggested but I don't think I get it yet... here is what I was trying to do...


    #include <windows.h>
    #include <time.h>

    /* function prototypes */
    LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);

    char szAppName[] = "Fade";

    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
    PSTR lpszCmdLine, int nCmdShow)
    {
    HWND hwnd; /* handle of client area */
    MSG msg; /* messages (i.e., user activity) */
    WNDCLASSEX wndclass; /* window class to create */
    HACCEL hAccel; /* keyboard accelerators (i.e., hot keys) */

    /* register class, unless previously registered */
    if (!hPrevInstance) {
    wndclass.cbSize = sizeof (wndclass);
    wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = WindowProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon (hInstance, szAppName);
    wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)GetStockObject (BLACK_BRUSH);
    wndclass.lpszMenuName = szAppName;
    wndclass.lpszClassName = szAppName;
    wndclass.hIconSm = NULL;
    RegisterClassEx (&wndclass);
    }

    hwnd = CreateWindow (szAppName, "Fade Program",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
    CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,
    NULL, NULL, hInstance, NULL);

    ShowWindow (hwnd, nCmdShow);
    UpdateWindow (hwnd);

    hAccel = LoadAccelerators (hInstance, szAppName);

    /* event loop */
    while (GetMessage (&msg, NULL, 0, 0)) {
    if (!TranslateAccelerator (hwnd, hAccel, &msg)) {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
    }
    }
    return (msg.wParam);
    }

    /* Window procedure for client area */
    LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    static HINSTANCE hInstance; /* same as instance in WinMain() */
    HDC hDC; /* handle to device context -- allows screen output */
    static PAINTSTRUCT ps; /* not really "used" (yet), but required anyway */
    static RECT rect; /* size of client area */
    COLORREF c,a1,a2;
    HPEN GREEN;


    switch (message) {

    case WM_CREATE:
    hDC = GetDC(hwnd);
    //SetTimer(hwnd,1,100,NULL);
    return (0);

    case WM_SIZE:
    return(0);

    case WM_TIMER:
    //(unsigned char*)&c[0]=(unsigned char*)&a1[0]+time*((unsigned char*)&a2[0]-(unsigned char*)&a1[0]);
    //(unsigned char*)&c[1]=(unsigned char*)&a1[1]+time*((unsigned char*)&a2[1]-*(unsigned char*)&a1[1]) ;
    //(unsigned char*)&c[2]=(unsigned char*)&a1[2]+time*((unsigned char*)&a2[2]-(unsigned char*)&a1[2]) ;
    //GREEN =CreatePen(PS_SOLID,1,c);
    return (0);

    case WM_PAINT:
    hDC = BeginPaint(hwnd, &ps);

    GREEN =CreatePen(PS_SOLID,1,RGB(0,255,0));
    SelectObject(hDC,GREEN);

    MoveToEx(hDC,55,100,NULL);
    LineTo(hDC,155,100);

    EndPaint(hwnd, &ps);
    return (0);

    case WM_DESTROY:
    KillTimer(hwnd,1);
    PostQuitMessage (0);
    return (0);

    }
    return DefWindowProc (hwnd, message, wParam, lParam);
    }

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Quick, unrelated point - use [ code ] [ /code ] tags please
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width