
-----------------------------------
agnivohneb
Wed Sep 05, 2007 6:34 pm

Randomizing an exact amount on the screen
-----------------------------------
I want to place a specific number of dots (example 6) in a 15 by 15 pixel area I want to randomize the output so the dots so up in a different spot every time. Any help I am not that good with math. If you need any more info just ask.

-----------------------------------
Clayton
Wed Sep 05, 2007 6:48 pm

RE:Randomizing an exact amount on the screen
-----------------------------------
Think about this logically... Really, problem solving is one of the most important aspects of Computer Science. Break your big problem down into smaller problems.

1)You need to draw a dot randomly
2)You need to section off a 15 x 15 pixel area on the screen
3)The dot needs to appear in this area
4)Repeat 1) - 3) five more times

-----------------------------------
Nick
Wed Sep 05, 2007 10:05 pm

RE:Randomizing an exact amount on the screen
-----------------------------------
well what i'd do is make an x and y varible for the dot's location then use randint to randomize where it goes and use randint to limit where the dots can go

-----------------------------------
d2bb
Thu Sep 06, 2007 7:42 am

RE:Randomizing an exact amount on the screen
-----------------------------------
not even sure his question made to much sense, but just make a program to draw random x + y values inbetween 1-whatever our screen size is.


After this use a counted-loop it and you should be good.

-----------------------------------
agnivohneb
Fri Sep 07, 2007 10:11 pm

Re: Randomizing an exact amount on the screen
-----------------------------------
I figured it out
var x, y, x2, y2 : int := 1
var num : array 1 .. 15, 1 .. 15 of int

for i : 1 .. 15
    for j : 1 .. 15
        num (i, j) := Rand.Int (0, 225)
    end for
end for

for i : 1 .. 225 by 15
    for j : 1 .. 225 by 15
        for k : 1 .. num (x2, y2)
            loop
                x := Rand.Int (i, i + 14)
                y := Rand.Int (j, j + 14)
                exit when whatdotcolor (x, y) not= 7
            end loop
            Draw.Dot (x, y, black)
        end for
        y2 += 1
    end for
    x2 += 1
    y2 := 1
end for
I only set num to a random number for now i will change it later to use a specific number. I'm on the right track now. I think.

-----------------------------------
Nick
Fri Sep 07, 2007 11:06 pm

RE:Randomizing an exact amount on the screen
-----------------------------------
you looking for something like this?

var x, y : int

for i : 1 .. 6
    x := Rand.Int (100, 115)
    y := Rand.Int (100, 115)
    drawdot (x, y, black)
end for


what u did was go WAY to indepth for something pretty simple

-----------------------------------
agnivohneb
Fri Sep 07, 2007 11:19 pm

RE:Randomizing an exact amount on the screen
-----------------------------------
That is the same thing I had only I expanded it to more 15x15 boxes there are 15x15 boxes = 225 pixels up and 225 pixels over each individual box is a unique number and when i release the program next week you will see were I'm going with this.

-----------------------------------
Nick
Sat Sep 08, 2007 11:28 am

RE:Randomizing an exact amount on the screen
-----------------------------------
oh i get it i still dont get where ur going but i assume both ways would work for my way just make my for loop inside 2 others and have those 2 for loops equal the x and y inside the Rand.Int... when i get less lazy ill show u
