//------------------------------------------------------------------- // PAULTRAP.cpp Windows 32 Anwendung in Microsoft Visual C++ 6.0 //------------------------------------------------------------------- #include #include //------------------------------------------------------------------- double sx, // stab x sy, // stab y px, // position x py, // position y vx, // geschwindigkeit x vy, // geschwindigkeit y ax, // beschleunigung x ay, // beschleunigung y dx, // stababstand x dy, // stababstand y u, // umrechnungsfaktor grad zu rad a, // diagonalbeschleunigung f, // feldstaerke r, // diagonalabstand w, // phasenwinkel t, // zeitschritte v; // ladungsvorzeichen int x, // bild x y; // bild y //------------------------------------------------------------------- static int cxClient, cyClient ; HDC hdc ; LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("PAULTRAP") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("Program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, TEXT ("PAULTRAP"), WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, SW_SHOWMAXIMIZED) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } //------------------------------------------------------------------- void bere(void){ // beschleunigungsrechner dx=px-sx ; // stababstand x dy=py-sy ; // stababstand y r=sqrt(dx*dx+dy*dy) ; // diagonalabstand a=v*f/r ; // diagonalbeschleunigung ax=ax+a*dx/r ; // beschleunigung x ay=ay+a*dy/r ; // beschleunigung y } // return unterprogrammende //------------------------------------------------------------------- LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps ; switch (message) { case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; //------------------------------------------------------------------- Ellipse(hdc, 70, 70,130,130); // stab links oben Ellipse(hdc,270,270,330,330); // stab rechts unten Ellipse(hdc,270, 70,330,130); // stab rechts oben Ellipse(hdc, 70,270,130,330); // stab links unten //------------------------------------------------------------------- px=143 ; // startposition x py=157 ; // startposition y vx=0.0037 ; // startgeschwindigkeit x vy=0.0051 ; // startgeschwindigkeit y u=atan(1)/45 ; // umrechnungsfaktor grad zu rad for(t=0;t<5001;t=t+1){ ; // zeitschritte for(w=0;w< 356;w=w+5){ ; // phasenwinkel f=sin(w*u)*0.05 ; // feldstaerke ax=0 ; // beschleunigung x ay=0 ; // beschleunigung y sx=0 ; // stab x links sy=0 ; // stab y oben v= 1 ; // ladungsvorzeichen bere() ; // beschleunigungsrechner sx=200 ; // stab x rechts sy=200 ; // stab y unten v= 1 ; // ladungsvorzeichen bere() ; // beschleunigungsrechner sx=200 ; // stab x rechts sy=0 ; // stab y oben v=-1 ; // ladungsvorzeichen bere() ; // beschleunigungsrechner sx=0 ; // stab x links sy=200 ; // stab y unten v=-1 ; // ladungsvorzeichen bere() ; // beschleunigungsrechner vx=vx+ax ; // geschwindigkeit x vy=vy+ay ; // geschwindigkeit y px=px+vx ; // position x py=py+vy ; // position y x=(int)floor(100.5+px) ; // bild x y=(int)floor(100.5+py) ; // bild y SetPixel(hdc,x,y,RGB(0,0,0)); // punkt zeichnen } // next w naechster phasenwinkel } // next t naechster zeitschritt //------------------------------------------------------------------- EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } //-------------------------------------------------------------------