CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: TV static noise animation-adding random generator

    Okay have no idea why it wont upgrade to 2010 .. I did it N.P. ...

    Here is the VS 2010 ver of the same project ....

    Hope this works ...

    Gremmy...
    Attached Files Attached Files
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  2. #17
    Join Date
    Feb 2009
    Posts
    37

    Re: TV static noise animation-adding random generator

    Hi,

    Again, thanks. I am able to open these files and compile the project into an app.

    Yes. If I choose random and set the interval to 120, I get the precise animation style and effect that looks like the Flash demo. Fantastic!

    I will need to carefully look at the code, re-read what you've posted, to see what you've done to accomplish this, learn from it.

    Much thanks!

    Kind Regards,
    saratogacoach

  3. #18
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: TV static noise animation-adding random generator

    Great ... Glad it is what you were looking for....

    The main reason for the first two styles was to provide a exact 50/50 spread and also where you can allow one step and count the changes..

    The code is not too complicated and followed allot of what you already coded, with the difference of using a realizable picture box.

    Also i rearranged some of it so that it runs better, and faster..

    Note that there are no try catch blocks for incase ....... Only checking that is needed is that the text entry is numeric, however that can be taken care of with this small piece of code
    Code:
        Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
            If Not IsNumeric(e.KeyChar) Then
                e.Handled = True
            End If
        End Sub
    If your dont understand something, just ask .. ill try to explain it to you in laymans terms ...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  4. #19
    Join Date
    Feb 2009
    Posts
    37

    Re: TV static noise animation-adding random generator

    Hi Gremmy,

    Figured out where to place this additional code. It seems to work without error.

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    If Not IsNumeric(e.KeyChar) Then
    e.Handled = True
    End If
    End Sub

    I've been trying to do a few changes :

    successful:
    (1) increasing speed by increasing the dots changed per interval to 1000. Seems to better match the speed of the Flash and Delphi Windows demo's.

    so far unsuccessful:
    (2) trying to figure out (so far unsuccessfully) how to default to random and fill and (like in the Flash demo) clicking on the canvas screen to start and stop (toggle);

    so far unsuccessful:
    (3) setting up a 30 second default animation time-once started, runs for 30 seconds then stops.

    Any suggestions, help much appreciated.

    Kind Regards,
    Last edited by saratogacoach; February 23rd, 2011 at 12:28 PM.
    saratogacoach

  5. #20
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: TV static noise animation-adding random generator

    ARG .. have to retype .. still getting random BANNED IP Problems...

    Okay let me try again ...

    #1 - dots changed per interval is calculated in this bit of code
    Code:
            Dotcount = CInt(400 / (1000 / Timer1.Interval))
    It works like this....

    400 (dots) / (per) 1000 (ms) - the actual math used is a little more than that, in that it works out the number per frame.. but i took the numbers from your original spec..

    so to make it 1000 per second.. change the above line too
    Code:
            Dotcount = CInt(1000 / (1000 / Timer1.Interval))
    #2 - Goto "Form1.vb Design" in VS .. where you now see the forms design ...
    Click on the radio button that is labled 'Random'. Right click , Properties.. Scroll to Checked and set it to true. this will set random as default ...

    #3 - this is a little harder than the others..

    First at the top under all the other Private delcarations add
    Code:
        Private StartTime As Date
    (just above Public sub .....)

    In the Button1_click and button3_click subs .. Just after the 'Timer1.Enabled = True' add
    Code:
            StartTime = Date.Now
    and the last one for this mod...

    in the timer1_tick sub just after 'DrawPicture()' add
    Code:
            If StartTime.AddSeconds(30) < Date.Now Then
                Timer1.Enabled = False
            End If
    this should stop the code after 30 seconds..


    Now to trigger on a canvas click.. add this sub (same like last time)

    Code:
        Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
            Timer1.Interval = CInt(TextBox1.Text)
            Timer1.Enabled = Not Timer1.Enabled
            StartTime = Date.Now
        End Sub
    that should be it ....
    Last edited by GremlinSA; February 23rd, 2011 at 02:40 PM.
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  6. #21
    Join Date
    Feb 2009
    Posts
    37

    Re: TV static noise animation-adding random generator

    Hi Gremmy,

    Thanks again.

    All of changes finally went in without an error message.

    At first, the following code, adding it as a Sub, gave an error message:

    Code:
    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
            Timer1.Interval = CInt(TextBox1.Text)
            Timer1.Enabled = Not Timer1.Enabled
            StartTime = Date.Now
        End Sub
    error: Error 1 'Private Sub PictureBox1_Click(sender As Object, e As System.EventArgs)' has multiple definitions with identical signatures.

    I suspected this meant that there are conflicting items for PictureBox1, so I deleted:

    Code:
    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    
        End Sub
    With that piece of code removed, the new one substituted for it, all seems to work OK.

    Again, much thanks!

    Kind Regards,
    Last edited by saratogacoach; February 23rd, 2011 at 04:25 PM.
    saratogacoach

  7. #22
    Join Date
    Feb 2009
    Posts
    37

    Re: TV static noise animation-adding random generator

    Hi,

    I've been learning a lot and very much appreciate your help. Great progress! Getting a little more familiar with the VB UI, code window and editor.

    I have been reading online about using Tracker Bars. Two of these would be useful in Form1:

    (1) one slider to let the user set the length of time for the animation, ranging from a default of 30 seconds on the left (minimum) to 60 seconds on the right (maximum).

    (2) a second slider, instead of a text input box, for the timer interval, ranging from a minimum of, for example, 800 ms to a maximum of, for example, 1200 ms.

    While I can import 2 track bars into Form1 design, I'm not sure how to set up the code for each of these sliders to control the variables for length of time and timer interval.

    I would appreciate any code suggestions. (And, once I can add these 2 track bars, I would probably need to figure out how to not only delete the text input box, any other irrelevant controls, but also any other old code that would now conflict with these new controls to govern these variables. Big challenge.)

    I would welcome any suggestions on adding these, their code, and making this work without conflicts/errors.

    Thanks very much.

    Kind Regards,
    saratogacoach

  8. #23
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: TV static noise animation-adding random generator

    Use both (for now). Have the SLIDER UPDATE EVENT in the Text Event, and vice-versa. When you move the slider, the text will update.

    Also, set the upper and lower bounds of the slider, and use the same / as before, to come up with a &#37; of the total range desired. Display the % in the textbox
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #24
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: TV static noise animation-adding random generator

    Right this time you can make the changes .. i will guide you along you way...

    #1 - Remove the Textbox from the form ... Right click - 'delete' (you will get a few errors about textbox1 not been defined, dont worry about them right now)

    #2 - Add a slider (trackbar) to the form, right click and select 'properties' .. Name it TBinterval... change the minimum value to 100 and maximum value to 1000

    #3 - Now find in the code all the lines that have
    Code:
    Timer1.Interval = CInt(TextBox1.Text)
    and change them to
    Code:
    Timer1.Interval = TBinterval.Value
    The errors you had before should be clearing as you change each one ...

    #4 - delete the sub 'Private Sub TextBox1_KeyPress' as it is no longer needed (all 5 lines up to 'End Sub') .. this should take care of the last error....

    #5 - Add another Trackbar to the form, right click - 'properties' ... Name it TBTime... change the minimum value to 30 and maximum value to 60

    #6 - now find in the code the line that has
    Code:
    If StartTime.AddSeconds(30) < Date.Now Then
    and change it to
    Code:
    If StartTime.AddSeconds(TBTime.Value) < Date.Now Then
    this should take care of the changes needed to ad the sliders into the project ..

    no other code needs to be changed or removed ..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  10. #25
    Join Date
    Feb 2009
    Posts
    37

    Re: TV static noise animation-adding random generator

    Hi Gremmy,

    Thanks again. I was able to make these changes successfully.

    Continuing to better understand how to make things happen, add, delete, change controls and code.

    Much thanks!

    Kind Regards,
    Last edited by saratogacoach; February 24th, 2011 at 08:20 AM.
    saratogacoach

  11. #26
    Join Date
    Jul 2014
    Posts
    1

    Re: TV static noise animation-adding random generator

    Here's one that's 15 times faster - sorry it's a bit late being posted!

    Code:
    Option Strict On
    
    Imports System.Windows.Forms
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        Public Class syncObject
            Public Sub New()
            End Sub
        End Class
    
        Public syncOb As New syncObject()
    
        Public Declare Sub AttachConsole Lib "Kernel32" (ByRef dwProcessId As Long)
        Private Const ATTACH_PARENT_PROCESS As Integer = -1
    
        Private WithEvents timer As System.Windows.Forms.Timer
        Private frameCount As UShort = 0US
    
        Private gCanvasWidth As UShort = (500US \ 8) * 8
        Private gCanvasHeight As UShort = 300US
    
        Private gDelay As Integer = 1 'ms
        Private gProceed As Boolean = False
        Private gImage As New System.Drawing.Bitmap(gCanvasWidth, gCanvasHeight, PixelFormat.Format1bppIndexed)
    
        Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            gProceed = False
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.SetClientSizeCore(gCanvasWidth, gCanvasHeight)
            Me.Text = "Click the form to start and stop"
            SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
            AttachConsole(ATTACH_PARENT_PROCESS)
            timer = New Timer()
            timer.Interval = 1000
            timer.Start()
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick
            Console.WriteLine("FPS: " & frameCount)
            frameCount = 0
        End Sub
    
        Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
            If gProceed Then
                Me.FormBorderStyle=Windows.Forms.FormBorderStyle.Sizable
                Me.WindowState=FormWindowState.Normal
                gProceed = False
            Else
                Me.FormBorderStyle=Windows.Forms.FormBorderStyle.None
                Me.WindowState=FormWindowState.Maximized
                gCanvasWidth =CUShort((Me.Width \ 8) * 8)
                gCanvasHeight= CUShort(Me.height)
                gImage = New System.Drawing.Bitmap(gCanvasWidth, gCanvasHeight, PixelFormat.Format1bppIndexed)
                gProceed = True
                Dim vThread As New System.Threading.Thread(AddressOf GenerateStatic_Background)
                vThread.IsBackground = True
                vThread.Name = "Thread for generating static"
                vThread.Start(New Object)
            End If
        End Sub
    
        Private Delegate Sub DrawUpdate_Delegate(ByVal Arg As System.Object)
        Private Sub DrawUpdate(ByVal Arg As System.Object)
            gImage = DirectCast(Arg, System.Drawing.Bitmap)
            Me.Invalidate()
        End Sub
    
        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            SyncLock (syncOb)
                e.Graphics.DrawImageUnscaled(gImage, 0, 0)
            End SyncLock
        End Sub
    
        'Super fast speed static thread!
        Private Sub GenerateStatic_Background(ByVal Arg As System.Object)
            Dim vImg As New System.Drawing.Bitmap(gCanvasWidth, gCanvasHeight, PixelFormat.Format1bppIndexed)
            Dim bounds As Rectangle = New Rectangle(0, 0, vImg.Width, vImg.Height)
            Dim m_BitmapData As System.Drawing.Imaging.BitmapData = vImg.LockBits(bounds, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format1bppIndexed)
            Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
            vImg.UnlockBits(m_BitmapData)
            Dim ImageBytes(total_size) As Byte
            Dim vGen As New System.Security.Cryptography.RNGCryptoServiceProvider
            Dim vSeed(3) As Byte
            vGen.GetBytes(vSeed)
            Dim vRand As Random = New Random(BitConverter.ToInt32(vSeed, 0))
            While gProceed
                frameCount += 1US
                If frameCount Mod 5 = 1 Then System.Threading.Thread.Sleep(gDelay)
                SyncLock (syncOb)
                    m_BitmapData = vImg.LockBits(bounds, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format1bppIndexed)
                    vRand.NextBytes(ImageBytes)
                    Marshal.Copy(ImageBytes, 0, m_BitmapData.Scan0, total_size)
                    vImg.UnlockBits(m_BitmapData)
                End SyncLock
                Try
                    Me.Invoke(New DrawUpdate_Delegate(AddressOf DrawUpdate), CType(vImg, System.Object))
                Catch e As Exception
                End Try
            End While
        End Sub
    
    
    End Class

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured