-
April 28th, 2011, 01:53 PM
#1
[RESOLVED] generating a sine wave
Hay guys,
I'm trying to generate a sine wave. I have some code but I don't know what i'm missing from it.
Any help or comments would be great.
[code]
void CSine_wave1View::OnPaint()
{
CPaintDC dc(this);
CRect Recto;
GetClientRect(&Recto);
CBrush bgBrush(BLACK_BRUSH);
dc.SelectObject(bgBrush);
dc.Rectangle(Recto);
CPen PenBlue(PS_SOLID,1,RGB(0,0,255));
dc.SelectObject(PenBlue);
for(int x=0; x<Recto.Width();x+=20)
{
dc.MoveTo(x,0);
dc.LineTo(x,Recto.Height());
}
for (int y=0; y<Recto.Height();y+=20)
{
dc.MoveTo(0,y);
dc.LineTo(Recto.Width(),y);
}
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetViewportOrg(340,200);
dc.SetWindowExt(1000,200);
dc.SetViewportExt(1000,200);
double PI=3.14159;
int ScaleX=100;
int ScaleY=100;
for(double i=0;i<400; i+=0.01)
{
double j = sin(4*PI/ScaleX *i)* ScaleY;
dc.SetPixel(i,j,RGB(255,0,0));
}
}
[\code]
-
April 28th, 2011, 01:56 PM
#2
Re: generating a sine wave
The first thing you'll need is an attention to detail. For example, take an extra 2 seconds to look at your post, notice the code tags didn't work, & fix it.
-
April 28th, 2011, 02:09 PM
#3
Re: generating a sine wave
Code:
void CSine_wave1View::OnPaint()
{
CPaintDC dc(this);
CRect Recto;
GetClientRect(&Recto);
CBrush bgBrush(BLACK_BRUSH);
dc.SelectObject(bgBrush);
dc.Rectangle(Recto);
CPen PenBlue(PS_SOLID,1,RGB(0,0,255));
dc.SelectObject(PenBlue);
for(int x=0; x<Recto.Width();x+=20)
{
dc.MoveTo(x,0);
dc.LineTo(x,Recto.Height());
}
for (int y=0; y<Recto.Height();y+=20)
{
dc.MoveTo(0,y);
dc.LineTo(Recto.Width(),y);
}
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetViewportOrg(340,200);
dc.SetWindowExt(1000,200);
dc.SetViewportExt(1000,200);
double PI=3.14159;
int ScaleX=100;
int ScaleY=100;
for(double i=0;i<400; i+=0.01)
{
double j = sin(4*PI/ScaleX *i)* ScaleY;
dc.SetPixel(i,j,RGB(255,0,0));
}
}
-
April 28th, 2011, 02:30 PM
#4
Re: generating a sine wave
Next, provide a *lot* more information about what your problem is. Is it printing anything at all? What difficulty did you have debugging it?
-
April 28th, 2011, 02:30 PM
#5
Re: generating a sine wave
And, please, take an extra half second to properly indent the code. Especially when you want other people to read it.
-
April 28th, 2011, 02:31 PM
#6
Re: generating a sine wave
Since the code you posted is incomplete, and can't be compiled, you should start off by telling us what your code is doing as is and what it should be doing according to you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|