Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Brush Trouble

$
0
0
What I want my code to do is to randomly scribble in a picturebox, then whenever the brush goes over an area that has already been passed over it paints a darker shade over that spot. But right now I can't get the brush to scribble even one color. Can someone help me make this brush work, then make it paint darker over areas already painted? Thanks.

How I imagine the result to look:
Posted Image


My code so-far:
 Private Sub MapDraw()

        Dim x As Integer
        Dim y As Integer
        Dim xmax As Integer
        Dim clr As Integer
        Dim j As Integer



        bm = New Bitmap(PictureBox1.Width, PictureBox1.Height)
        Using g As Graphics = Graphics.FromImage(bm)
            g.Clear(PictureBox1.BackColor)
        End Using
        ' clear residual image
        xmax = bm.Width - 1

        PictureBox1.Image = bm

        ' MsgBox(PictureBox1.BackColor.A & " " & PictureBox1.BackColor.R & " " & PictureBox1.BackColor.G & " " & PictureBox1.BackColor.B)/>/>
        brush1 = New SolidBrush(Color.Black)

        Do Until j = 1000
            j = j + 1
            ProgressBar1.Value = j
            Randomize()
            ' Generate random value between 1 and 6.
            Dim rand As Integer = CInt(Int((4 * Rnd()) + 1))
            If rand = 1 Then
                y = y + 1

            ElseIf rand = 2 Then
                y = y - 1

            ElseIf rand = 3 Then   'depending on random number,
                x = x + 1
                'add or subtract for x or y value 
            ElseIf rand = 4 Then
                x = x - 1
            End If

            If x > PictureBox1.Width Then
                x = PictureBox1.Width
            End If
            If y > PictureBox1.Height Then
                y = PictureBox1.Height
            End If

            PlotPoint(x, y, brush1)

        Loop


    End Sub
    Private Sub PlotPoint(ByRef x As Integer, ByRef y As Integer, ByRef hue As Brush)
        Dim gr As Graphics = Graphics.FromImage(PictureBox1.Image)
        Dim Dot As Rectangle
        Dim dotsize As Integer = 4

        Dot.X = x
        Dot.Y = y

       
        gr.FillEllipse(hue, Dot)


        PictureBox1.Refresh()
    End Sub

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>