954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Drawing sin(x)/x graphic into PictureBox in animation mode by timer component.

I need to draw sin(x)/x graphic into PictureBox in animation mode by timer component. I have axes already on my picBox and graphic draws from 0;0. Also I have some code from this forum, but there my graphic draws FROM RIGHT TO THE LEFT, and I need to draw it FROM LEFT TO THE RIGHT. And I need to draw it in animation mode by timer. Could anybody help me?
Here's my drawing function:

private void drawStream()
        {
            const int scaleX = 35;
            const int scaleY = 35;
            
            Point picBoxTopLeft = new Point(0, 0);
            Point picBoxTopLeftm1 = new Point(-1, 0);          

            int halfX = picBox.Width / 2; 
            int halfY = picBox.Height / 2; 
            Size size = new Size(halfX + 20, picBox.Height);
          
            Graphics gr = picBox.CreateGraphics();
            gr.TranslateTransform(halfX, halfY);
           
            gr.ScaleTransform(scaleX, scaleY);
           
            gr.ResetClip();

            float lastY = (float)Math.Sin(0);
            float y = lastY;
            Pen p = new Pen(Color.Red, 0.015F);
            float stepX = 1F / scaleX; 

            for (float x = 0; x < 15; x += stepX)
            {
                gr.CopyFromScreen(picBox.PointToScreen(picBoxTopLeft), picBoxTopLeftm1, size, CopyPixelOperation.SourceCopy);             
                y = (float)Math.Sin(x);
                gr.DrawLine(p, -stepX, lastY, 0, y);
                lastY = y;                
            } 
        }

Thanx a lot.
P.S. Sorry for my English, I'm Ukrainian.

Dasharnb777
Newbie Poster
15 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Hi Dasharnb777, welcome!
Your code draws sin(x) not sin(x)/x. Remember, to avoid divide by zero.
Did you have a look at this snippet? http://www.daniweb.com/code/snippet217204.html

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

Thanx

Dasharnb777
Newbie Poster
15 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: