[RESOLVED] generating a sine wave
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] generating a sine wave

  1. #1
    Join Date
    Apr 2011
    Posts
    3

    [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]

  2. #2
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    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.

  3. #3
    Join Date
    Apr 2011
    Posts
    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));
    }
    
    }

  4. #4
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    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?

  5. #5
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    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.

  6. #6
    Join Date
    Aug 2008
    Posts
    902

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center