A little math geekiness on a boring workday...

NuclearNed

Raconteur
May 18, 2001
7,831
295
126
Its been a slow day at work, so I wrote a little program that generates cool pictures from polar coordinates. The math geek in me is showing. Maybe if anybody wants me to, I'll post the code for my program (its uber short).


image 1
image 2
image 3
image 4
image 5
 

NuclearNed

Raconteur
May 18, 2001
7,831
295
126
Here is the first of 2 files (test3.h). I'll post test3.cpp in another post:

class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};

class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
protected:
const static int scalar = 240;
double XPolarFn(double);
double YPolarFn(double);
const static long Off = 1;
const static long On = 0;
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
 

NuclearNed

Raconteur
May 18, 2001
7,831
295
126
And here is test3.cpp:

#include <stdafx.h>
#include <math.h>
#include "test3.h"
CMyApp myApp;

BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMainWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}

BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()

CMainWindow::CMainWindow()
{
Create(NULL, "TEST");
}

double CMainWindow::XPolarFn(double angle)
{
double value;
value = sin(angle);
value *= scalar;
return(value);
}

double CMainWindow::YPolarFn(double angle)
{
double value;
value = sin(angle) * sin(.9 * angle);
value *= scalar;
return(value);
}

void CMainWindow::eek:nPaint()
{
CClientDC dc (this);
CRect rect;
double angle, angle_increment, centerX, centerY;

angle_increment = 0.01;
GetClientRect(&amp;rect);
centerX = rect.Width() / 2;
centerY = rect.Height() / 2;

for(angle = 0; angle <= 360; angle += angle_increment)
dc.SetPixel((int)(XPolarFn(angle) * cos(angle) + centerX), (int)(YPolarFn(angle) * sin(angle) + centerY), 0);
}
 

Gibson486

Lifer
Aug 9, 2000
18,378
1
0
OK, I have officially decided to do a major that requires little or no programming...