Results 1 to 12 of 12

Thread: Bubble Maker

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    25

    Bubble Maker

    Could someone please tell me if I am doing this right. I know I am not because it won't work but am I even close? I am trying to take a png file and use that to make a balloon in that shape on a pictureBox(someone suggested yesterday). The bubbles are supposed to float to the top of the vat and then pop. I looked at my book and tried it from there. I put a pictureBox on my panel and then imported the (andy.png) into the pictureBox. When I run it a page opens up (application designer.vb) with a line with green in it. Is it possible to do what I need to do this way? I am really lost. Any help would be greatly appreciated.

    I have a bunch of stuff commented out.




    Form1.vb:
    Public Class Form1
    Private Foam As New List(Of Bubble)
    Private CurrentAge As Integer
    Private Rand As New Random
    Dim x_intercept(0, 0)
    Dim y_intercept(0, 0)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    timBubbleTimer.Interval = 100
    timBubbleTimer.Enabled = False
    pnlVat.BackColor = Color.LightGray
    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    Foam = New List(Of Bubble)
    CurrentAge = 0
    Dim g As Graphics = pnlVat.CreateGraphics
    g.FillRectangle(New SolidBrush(Color.LightGray), pnlVat.DisplayRectangle)
    timBubbleTimer.Enabled = True
    timBubbleTimer.Start()
    End Sub

    Private Sub timBubbleTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timBubbleTimer.Tick, PictureBox1.Move
    CurrentAge += 1
    Dim PX As Integer
    Dim PY As Integer
    PX = 10
    PY = 10
    Static Count
    Count = (Count + 1) Mod 2
    If Count = 1 Then
    PictureBox1.Image = Image.FromFile("Andy.png")

    Else
    PictureBox1.Image = Image.FromFile("NoAndy.png")
    End If

    PictureBox1.SetBounds(PictureBox1.Left + PX, PictureBox1.Top + PY, 0, 0)
    If (PictureBox1.Top + PictureBox1.Height) > Height Then PY = -PY
    If PictureBox1.Top < 0 Then PY = -PY
    If (PictureBox1.Left + PictureBox1.Width) > Width Then PX = -PX
    If PictureBox1.Left < 0 Then PX = -PX
    Count = (Count + 1) Mod 3
    Select Case Count
    Case 0
    PictureBox1.Image = Image.FromFile("Andy.png")
    Case 1
    PictureBox1.Image = Image.FromFile("NoAndy.png")
    End Select


    'Dim MaxX, MaxY As Integer
    'MaxX = pnlVat.Width
    'MaxY = pnlVat.Height

    'Dim g As Graphics
    'g = pnlVat.CreateGraphics
    'Dim p As New Point(0, 0)



    'PX = Rand.Next(4, MaxX - 4)
    'PY = Rand.Next(MaxY - 34, MaxY - 4)
    'p = New Point(PX, PY)
    'Foam.Add(New Bubble(p, Brush.newColor, Pen.DimGray))

    'pnlVat.Refresh()

    'For i As Integer = 0 To Foam.Count - 1 Step 1
    ' If Foam(i).GetLocation.X > MaxX Then
    'Foam(i).Remove(g)
    'Foam(i).GetLocation()

    ' End If
    'If Foam(i).GetLocation.Y < 0 Then
    ' Foam(i).Remove(g)
    ' Foam(i).GetLocation()

    'End If


    '' Foam(i).Remove(g)

    'Foam(i).Move()
    'Foam(i).Draw(g)
    'Foam(i).Grow()


    'Next


    ' Add code here to create, move, resize, erase and redraw all the bubbles in the Foam list

    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
    timBubbleTimer.Stop()
    timBubbleTimer.Enabled = False
    End Sub


    End Class


    Bubble.vb


    Public Class Bubble
    Private BubSize As Integer
    Private BubColor As Color
    Private BubOutlineColor As Color
    Private BubLocation As Point
    Private BubAge As Integer
    Shared Graphics As Graphics



    Public Sub New(ByVal NewLoc As Point, ByVal NewColor As Color, ByVal NewOutlineColor As Color)
    'Dim New List As New Bubble

    ' Initialize the attributes of a new bubble here
    Dim g As Graphics = Bubble.Graphics
    BubColor = Color.Aqua
    BubOutlineColor = Color.AntiqueWhite
    'BubLocation = (y)
    BubAge = 0
    BubSize = (1)








    End Sub

    Public Function GetLocation() As Point
    Return BubLocation
    End Function

    Public Function GetSize() As Integer
    Return BubSize
    End Function

    Public Sub Move()
    Move()

    ' Add code here to change a bubble's location

    End Sub

    Public Sub Remove(ByVal g As Graphics)
    Remove(g)



    ' Add code here to remove a bubble from the list

    End Sub

    Public Sub Draw(ByVal g As Graphics) ' Add code to draw the current bubble

    'Dim myPng As Image("andy.png", "noAndy.png")
    'Dim g As Graphics = Graphics.FromHwnd(PictureBox)
    ''g.DrawImage(myPNG, 150, 200)
    'Dim myBrush As System.Drawing.Brush()
    'Dim BubGraphics As System.Drawing.Graphics
    'BubGraphics = Bubble.CreateGraphics()
    'formGraphics.DrawEllipse(Brush, New Rectangle(0, 0, 200, 300))
    ''myBrush.Dispose()
    'BubGraphics.Dispose()



    ' Dim width As Integer = bm.Width - (bm.Width * percentResize) 'image width.

    ' Dim height As Integer = bm.Height - (bm.Height * percentResize) 'image height



    ' g.DrawImage(bm, New Rectangle(0, 0, width, height), New Rectangle(0, 0, bm.Width, _
    'bm.Height), GraphicsUnit.Pixel)

    ' g.Dispose()

    ' bm.Dispose()

    End Sub
    Public Sub UnDraw(ByVal g As Graphics)
    UnDraw(g)

    ' Add code to erase the current bubble from the display

    End Sub

    Public Sub Grow()
    BubSize += 1
    End Sub

    End Class



    Application designer.vb

    <auto-generated>
    ' This code was generated by a tool.
    ' Runtime Version:4.0.30319.261
    '
    ' Changes to this file may cause incorrect behavior and will be lost if
    ' the code is regenerated.
    ' </auto-generated>
    '------------------------------------------------------------------------------

    Option Strict On
    Option Explicit On


    Namespace My

    'NOTE: This file is auto-generated; do not modify it directly. To make changes,
    ' or if you encounter build errors in this file, go to the Project Designer
    ' (go to Project Properties or double-click the My Project node in
    ' Solution Explorer), and make changes on the Application tab.
    '
    Partial Friend Class MyApplication

    <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
    Public Sub New()
    MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
    Me.IsSingleInstance = false
    Me.EnableVisualStyles = true
    Me.SaveMySettingsOnExit = true
    Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
    End Sub

    <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
    Protected Overrides Sub OnCreateMainForm()
    Me.MainForm = Global.Suds.Form1 This is the one that keeps showing up.
    End Sub
    End Class
    End Namespace

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Bubble Maker

    It looks like alll your changes have combined to confuse the heck out of the Designer. As you have at least 5 times more code than you could possibly need hanging about already, your best bet would be to start a new project anyway at this point so I'd do that! If you're using picture boxes the basic routine really shouldn't take more than Timer and half a dozen lines of code.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    25

    Re: Bubble Maker

    I know I am not getting this. I really don't know how to create the bubble from the png file. Could you please help me understand how to get started?

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Bubble Maker

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    4.         'set starting position of bubble, below the form
    5.         PictureBox1.Location = New Point(50, Me.Bottom)
    6.         ' you can experiment with random x values
    7.     End Sub
    8.  
    9.     Private Sub Form1_Shown(sender As System.Object, e As System.EventArgs) Handles MyBase.Shown
    10.         ' start the movement when form is visible
    11.         Timer1.Start()
    12.     End Sub
    13.  
    14.  
    15.     Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    16.         ' subtract 2 from the vertical position to move the box upward
    17.         PictureBox1.Top -= 2
    18.         ' with more experimentation you could add some sideways movement to make it more bubble like
    19.         If PictureBox1.Top <= 0 Then ' reached top of form client area
    20.             PictureBox1.Location = New Point(50, Me.Bottom) ' reset and start again
    21.         End If
    22.     End Sub
    23.  
    24. End Class

    To really make it classy, use an animated gif instead of your png!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    25

    Re: Bubble Maker

    thank you so much. I will see what I can do with that. Thanks again.

  6. #6
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Bubble Maker

    I'm stuck on a similar assignment. Sorry for piggybacking off this thread, but I didn't want to start an unnecessary one.

    Basically, one part that Paule didn't have is that there is a start button on the form, and when the start button is clicked, the timer sets off drawing ellipses(or bubbles) at random intervals in random set of sizes, shapes, and colors that are determined by a class called Bubbles, separate from the main form. The bubbles appear in a panel called pnlVat and are counted on a label, "popping" when they reach the top of the panel.

    I really hope someone can help, basically I am trying to set up the ellipses to where they appear from the settings I set on the Bubble class. I am using

    BubbleDraw.FillEllipse(BubBrush, New Rectangle(New Point(BubLocation), New Size(BubSize, BubSize)))

    to draw the bubbles, again on a separate class. They need to show up at a specific size and color, selected from a sub called NewLoc, NewColor, and NewOutlineColor that are used when one is drawn on clicking the start button.

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Bubble Maker

    OK. So what's the problem? You seem to have a reasonable grasp of what's required so what specifically do you need help with?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  8. #8
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Bubble Maker

    Basically, I'm stuck getting everything done in Bubbles.VB to interact with elements in the main form, specifically how to use the panel (pnlVat) to declare a location for the ellipses to be drawn. Right now, I'm mainly wanting to make sure I can get everything I've declared to show up. Then I'll need a new ellipse drawn using my settings at every tick.

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Bubble Maker

    If you're doing this as a separate class, it makes sense to Inherit at least the basic Control class. Apart from giving you ready made graphics and repaint you also get standard properties like Location, and Size built in and you can add instances of the class to the panel (or any other container) without problems.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  10. #10
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Bubble Maker

    Ok, I have got the bubble drawn and working. Now, I'm having issues making the picture box (which the bubble is being drawn in, something I've added recently) duplicate. Basically, what I need is at a random new tick, a new picture box needs to be drawn/created.

    I'm wracking my brain for a solution online, but everything I've found hasn't worked. I've tried setting the index to 0, which gave me an error (not that I knew what to do with it anyway) and I have no clue where to go from here.

    I just need a new picture box that draws bubbles at ticks. If I could get help, that would be great.

  11. #11
    New Member
    Join Date
    May 2013
    Posts
    2

    Re: Bubble Maker

    Hello strkhal

    I could not get my program to draw, could you give me any example code on what I should do on my Bubble's Class? Here's my code

    Public Class Bubble
    Private BubSize As Integer
    Private BubColor As Color
    Private BubOutlineColor As Color
    Private BubLocation As Point
    Private BubAge As Integer

    Public Sub New(ByVal NewLoc As Point, ByVal NewColor As Color, ByVal NewOutlineColor As Color)

    ' Initialize the attributes of a new bubble here
    BubColor = Color.Bisque
    BubOutlineColor = Color.Azure
    BubAge = 0
    BubSize = (1)
    BubLocation = NewLoc

    End Sub

    Public Function GetLocation() As Point
    Return BubLocation
    End Function

    Public Function GetSize() As Integer
    Return BubSize
    End Function

    Public Sub Move()

    ' Add code here to change a bubble's location
    BubLocation.X = BubLocation.X - 1
    BubLocation.Y = BubLocation.Y - 1

    End Sub

    Public Sub Remove(ByVal Foam As List(Of Bubble))
    ' Add code here to remove a bubble from the list
    Foam.Remove(Me)

    End Sub

    Public Sub Draw(ByVal g As Graphics)

    ' Add code to draw the current bubble
    'Dim BubbleDraw As
    Dim greenEllipse As New Drawing.SolidBrush(Color.Green)
    'g.FillEllipse(greenEllipse, 20, 20, 100, 100)
    g.FillEllipse(greenEllipse, New Rectangle(New Point(BubLocation), New Size(BubSize, BubSize)))
    End Sub

    Public Sub UnDraw(ByVal g As Graphics)

    ' Add code to erase the current bubble from the display
    'g.Dispose()
    g.Clear(Color.White)

    End Sub

    Public Sub Grow()
    BubSize += 1
    End Sub

    End Class

  12. #12
    New Member
    Join Date
    May 2013
    Posts
    2

    Re: Bubble Maker

    Hello strkhal

    I've been looking at your example code as well up top, I tried it out, but no luck.

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