Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

coordinate

Posted on 2010-09-13
6
162 Views
Last Modified: 2012-06-27
dear sir,

The below code is use to draw a random circle with random color in picture box have given size for high and width

The code should draw this random circle to be cover the area of the picture square in constraint :
1. be equal or less of the area of the picture.
2. not be cost more than maximum cost as in the image.

The inputs are:
1. high & width of the picture box by 2 combo box's.
2. the random size of fixed circle (high, width) will be selected randomly from the list box as in the image.
3. the cost of each circle size also selected for same index in the circle size list box as in the image.

The sub routine is worked fine to the constraints but:
1. Random some time is select one item and the we still have space to fill and also the cost still equal or same the maximum cost and we still have some cost to be add as well space and that is not correctly.
2. When it's start to draw new circle randomly it should not draw in coordinate of X if it's bigger than Y or if Y coordinate use much length that X the system will move to draw in consume more x to be close to Y coordinate and so except the if start will be 0,0 and or if the x=y length it's program choice to move any one.

the current code is move row by row when it finish fill Y then go to new x coordinate.--->
Dim area_w As Double = Me.ComboBox3.Text  'width of area

        Dim area_h As Double = Me.ComboBox4.Text  'hieght area
        Dim redBrush As New SolidBrush(color_circle)
        ' Create location and size of ellipse.



        'calculate number of circle

        Dim total_area As Double = (area_w) * (area_h)

        Dim w_circle As Integer = 0

        Dim r As New Random
        Dim w_cricle_total As Integer = 0

        Me.vieform.Width = area_w + 10
        Me.vieform.Height = area_h + 10

        'Me.vieform.CreateGraphics.Clear(color_circle4)
        'color_circle4 = RandomQBColor()
        'Me.vieform.CreateGraphics.Clear(color_circle4)
        color_circle = RandomRGBColor()
        Dim redBrush3 As New SolidBrush(color_circle)
        'MsgBox(total_area)
        Dim size1 As Integer
        Dim x1 As Integer = 0

        Dim y1 As Integer = 0
        Me.vieform.CreateGraphics.Clear(color_circle4)
        Dim i2, total_c_w1, total_c_h1, start_x1 As Integer
        x1 = TextBox1.Text
        i2 = TextBox2.Text

        Me.TextBox17.Text = ""
        Dim collections1 As String = ""

        Dim total_cost As Double = 0
        Dim cost As Double = 0

        Do Until w_cricle_total >= total_area
            myList.SelectedIndex = r.Next(0, myList.Items.Count - 1)
            w_circle = (myList.SelectedItem) * (myList.SelectedItem)
            Me.ListBox1.SelectedIndex = Me.myList.SelectedIndex
            cost = Me.ListBox1.SelectedItem
            total_cost = cost + total_cost
            ' MsgBox(myList.SelectedItem.ToString & "--" & ListBox1.SelectedItem.ToString)
            size1 = CInt(myList.SelectedItem)
            w_cricle_total = w_cricle_total + w_circle
            color_circle = RandomRGBColor()
            redBrush3.Color = color_circle
            '  Me.vieform.CreateGraphics.FillEllipse(redBrush3, x1, y1, size1, size1)
            Dim LocalMousePosition As Point
            LocalMousePosition = Me.vieform.PointToClient(Cursor.Position)


            MsgBox(LocalMousePosition.X & "=---" & LocalMousePosition.Y)

            If total_cost <= Val(Me.TextBox16.Text) Then


                If x1 < area_w Then
                    total_c_w1 = total_c_w1 + 1

                    Me.vieform.CreateGraphics.FillEllipse(redBrush3, x1, i2, size1, size1)


                Else

                    i2 = i2 + size1

                    If i2 < area_h Then
                        x1 = 0
                        total_c_h1 = total_c_h1 + 1
                        x1 = start_x1 + x1
                        Me.vieform.CreateGraphics.FillEllipse(redBrush3, x1, i2, size1, size1)


                    Else
                        Exit Sub

                    End If

                End If

                x1 = x1 + size1

                collections1 = CStr(size1) & "," & collections1
                Me.TextBox17.Text = collections1
                Me.TextBox10.Text = total_cost

            End If

        Loop

Open in new window

Capture42.PNG
0
Comment
Question by:abdallah1973
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:DjDezmond
ID: 33670003
so whats your question?

I quickly noticed this line:

Dim total_area As Double = (area_w) * (area_h)

What area is this calculating? is it the circles area?

This smells like homework to me....
0
 

Author Comment

by:abdallah1973
ID: 33670662
The total_area is the full space of picture box

the question is that we need draw number of circle inside this area but it must not be more than size of the picture box area and not more that maximum cost  =120000  as sample.

When it draw it must start from 0,0 and always measure for length of x and y.

That mean if it's start draw and the length  of drawing of x is more than y then the system will go to start consume more y length and so (balancing).

The system will random select size and cost from listbox  and also the colour of circle will be random.

The code is not for homework but it's a type of idea for doing some presentation for one client.
0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 33671409
OK, I will see if I can recreate the solution. I fear you may be making this more complicated than it needs to be, so I will split it up into different sections.

One question though, what is the "cost"? what does that refer to?
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 9

Accepted Solution

by:
DjDezmond earned 500 total points
ID: 33671541
In fact, I'm still not following...

You want to basically draw a number of circles inside the picture box, but:
  - The sizes are randomly selected from your list box
  - The color is randomly picked
  - They must not overlap
  - They must not exceed the size of the picturebox

is that right?

I don't understand what you are trying to say about x being more than y... its a circle, so length x and length y would always be equal...?

I would really like to help you, but I don't understand enough about what you are trying to achieve, sorry.
0
 

Author Comment

by:abdallah1973
ID: 33671700
it can be overlap.
each randomally selected size from list box have cost

100-->300
200-->1000
....
if random select 100 and 200 that mean the cost is 1300 and 1300 must less or equal the maximum cost.

Regarding x and y.

I will give more information later
0
 

Author Comment

by:abdallah1973
ID: 34256412
I apply another question but more explaination and some parts is solved
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26647424.html#a34256404
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Calling web service and its methods dynamically 2 73
Sql server, import complete table, using vb.net 9 43
Visual Studios 1 76
Looping through datagridview and dataset ? 6 24
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question