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.

Recommended Answers

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.