Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Randomizing an exact amount on the screen
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
agnivohneb




PostPosted: Wed Sep 05, 2007 6:34 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Wed Sep 05, 2007 6:48 pm   Post subject: 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




PostPosted: Wed Sep 05, 2007 10:05 pm   Post subject: 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




PostPosted: Thu Sep 06, 2007 7:42 am   Post subject: 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




PostPosted: Fri Sep 07, 2007 10:11 pm   Post subject: Re: Randomizing an exact amount on the screen

I figured it out
Turing:
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




PostPosted: Fri Sep 07, 2007 11:06 pm   Post subject: RE:Randomizing an exact amount on the screen

you looking for something like this?

Turing:
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




PostPosted: Fri Sep 07, 2007 11:19 pm   Post subject: 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




PostPosted: Sat Sep 08, 2007 11:28 am   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: