All pastes #1721436 Raw Edit

Anonymous

public cpp v1 · immutable
#1721436 ·published 2009-12-20 17:12 UTC
rendered paste body
    #include "stdafx.h"    #include <windows.h>    #include <math.h>         void renderDrop(int ballX, int ballY, int mx, int my)    {      float dt = 0.01f;      float g = 100.f;      float vy = -sqrt(2 * abs(float(my - ballY)) * g);      float t = sqrt(abs(float(my - ballY) + 1) * 2 / g);      float vx = float(mx - ballX) / t;      float x = float(ballX);      float y = float(ballY);           HDC hdc = GetDC(0);      for(int i = 0; i < 600; i++)      {        x += vx * dt;        y += vy * dt;        vy += g * dt;        SetPixel(hdc, int(x), int(y), 255*256 + 255);      }           ReleaseDC(0, hdc);    }         int _tmain(int argc, _TCHAR* argv[])    {      int ballX = 0,          ballY = 0;           bool ctrlPressed = false;      bool altPressed = false;      bool draw = false;           while (true)      {        bool ct = GetAsyncKeyState(VK_LCONTROL) < 0;        if (!ct && ctrlPressed)        {          POINT p;          GetCursorPos(&p);          ballX = p.x;          ballY = p.y;          ctrlPressed = false;        }        ctrlPressed = ct;             bool al = GetAsyncKeyState(VK_LMENU) < 0;             if (!al && altPressed)          draw = !draw;             if (draw)        {          POINT p;          GetCursorPos(&p);          altPressed = false;          renderDrop(ballX, ballY, p.x, p.y);        }        altPressed = al;             Sleep(10);      }           return 0;    }