Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Moving window along a cosine path

Moving window along a cosine path

Scheduled Pinned Locked Moved Algorithms
adobedata-structureshelptutorial
2 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tommy Svensson
    wrote on last edited by
    #1

    Hi all, Upon the start of my windows application I would like the splash screen window to move along the path of a cosine curve. More precisely I would like it to work like this: My splash window is positioned at the lower right corner of the screen. Now image a cosine graph under the interval of 0 <= degrees <= 180. I want the upper left corner of the splash screen to initially correspond to the coordinate of [180, cosine(180)]. Then, at some intervals I want the window to move to the "left" along the cosine curve all the way up to the top left corner of the screen, making a horizontally flipped S-shaped path (almost a flash-logo-like path). Since screens vary in sizes I need to know how to transpose a cosine curve to "fit" all screens. Any help would be greatly appreciated!!!!! /Tommy

    K 1 Reply Last reply
    0
    • T Tommy Svensson

      Hi all, Upon the start of my windows application I would like the splash screen window to move along the path of a cosine curve. More precisely I would like it to work like this: My splash window is positioned at the lower right corner of the screen. Now image a cosine graph under the interval of 0 <= degrees <= 180. I want the upper left corner of the splash screen to initially correspond to the coordinate of [180, cosine(180)]. Then, at some intervals I want the window to move to the "left" along the cosine curve all the way up to the top left corner of the screen, making a horizontally flipped S-shaped path (almost a flash-logo-like path). Since screens vary in sizes I need to know how to transpose a cosine curve to "fit" all screens. Any help would be greatly appreciated!!!!! /Tommy

      K Offline
      K Offline
      Kacee Giger
      wrote on last edited by
      #2

      I don't know what language you're using, but I've always used ::GetSystemMetrics(SM_CXSCREEN) to get the screen width and similar calls to get other screen dimensions. For your problem, since cos(180)=-1 and cos(0)=1, you will want to find the center of the screen to pivot from, but to do this you will need to subtract off the height of the splash screen and any borders. The following worked in a dialog based app: void CTestSplashDlg::SetPosition(double dDegrees) { const double pi = 3.1415926535; double dRadians = (2 * dDegrees * pi)/360; double dCos = cos(dRadians); CRect rect; GetClientRect(&rect); long nNewWidth = (long)(::GetSystemMetrics(SM_CXSCREEN) - rect.Width() - ::GetSystemMetrics(SM_CXDLGFRAME)) * (dDegrees/180); // Since cos(0) = 1 and cos(180) = -1, must have center of screen as cos(90) = 0 long nHeightCenter = (long)(::GetSystemMetrics(SM_CYSCREEN) - rect.Height() - ::GetSystemMetrics(SM_CYDLGFRAME) - ::GetSystemMetrics(SM_CYCAPTION))/2; long nNewHeight = (long)(nHeightCenter - (dCos * (nHeightCenter))); SetWindowPos(NULL, nNewWidth, nNewHeight, 0, 0, SWP_NOZORDER | SWP_NOSIZE); } when called with: for (double i = 180; i >= 0; i--) { SetPosition(i); Sleep(10); } Note that you would probably call this from a timer instead of a for loop and the starting position does not take into account the taskbar that may be at the bottom of the screen.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups