Quote Originally Posted by saratogacoach View Post
Hi,

I took a look at Richard Newcombe's animation article as suggested. As a beginner using VB, applying the new drawing method is way to complex for me.
????????

It's not a new method .. it's almost the same as the one your using..

Change your core code to look like this ... (i've highlighted key changes...)

Code:
                Dim vCurrentDot As New System.Drawing.Rectangle(0, 0, gDotSize, gDotSize)
                Dim vCurrentRow As Integer = 0
                Dim vCurrentCol As Integer = 0
                Dim vPens(2) As System.Drawing.Brush

                vPens(0) = Brushes.Black
                vPens(1) = Brushes.White


                'Iterate each dot... come up with a random black or white state, and draw it to the image.
                For i As Integer = 0 To vTotalDots - 1

                    'Generate random black or white state for this dot.
                    vCurrentRand = vRand.Next(0, 2) 'Either 0 or 1
                    'If vCurrentRand = 0 Then vCurrentColor = System.Drawing.Color.Black Else vCurrentColor = System.Drawing.Color.White

                    'Draw this dot.
                    vGr.FillRectangle(vPens(vCurrentRand), vCurrentDot)

                    'Increment the current dot for the next iteration.
                    vCurrentCol += 1 : vCurrentDot.X += gDotSize
                    If vCurrentCol = vCols Then
                        vCurrentCol = 0 : vCurrentDot.X = 0
                        vCurrentRow += 1 : vCurrentDot.Y += gDotSize
                    End If
                Next
then at the top change the delay to 15 ms
Code:
    Private gDelay As Integer = 15 'ms
now test your project...

One problem is that you has the code Sleep for 100 ms.. meaning at best you could get 10 FPS ... (not quite what you were looking for...)
reducing to 15 ms can increase it to ~ 60 FPS. However with the method your using, if all the code takes 10 ms to complete then that gets added to the 15 ms sleep time.. so you have 25 ms between Frames..

If you follow my article, the timer method explained there can also trigger every 15 ms, however the code execution time is not added to the frame time.. unless code execution time is longer than the timer.

The other thing is that using sleep functions inside loops is not the generally accepted method.

It will also eliminate the problem you put this code in for
Code:
 If Me.InvokeRequired Then
                    Try
                        Me.Invoke(New DrawUpdate_Delegate(AddressOf DrawUpdate), CType(vImg, System.Object))
                    Catch ex As Exception
                        'Error cuz you ended the program without allowing the thread to stop.
                        'To prevent this error, you could set gProceed = False in the Form_Closing event so the thread can end naturally.
                        'This Try block just prevents the error message.
                    End Try
                Else
                    DrawUpdate(CType(vImg, System.Object))
                End If