tags:

views:

66

answers:

1

I am trying to create a simple visualization of what my code does. I am making a Poisson-Disk-Distribution class to generate a set of random points in a bounded rectangular region. Basically, what it does is it randomly generates a specified number of points in the bounded region and makes sure that each point is at least a certain distance away from all the other points. The random points will be used later to generate a random maze.

I am finished coding, but I want to perform a quick visual check of whether or not it works. I want to output the points as text on the console. Every point generated has an X-value and a Y-value, so I was hoping that I could output the generated points in the console by somehow marking an x wherever a point may lie.

For example, if I were to have a bounding rectangle of width and height of 4, and the points p1 = (0, 0) and p2 = (2, 2) it could output the following:

----
--x-
----
x---

Where - are empty spaces on the graph and x are the points p1 and p2.

So, I'm kind of stumped as to how to code this printing function. It sounds simple in my head, but I can't seem to implement it.

Oh, I tagged this as homework, but its not really part of my project. I just wanted to check if my code is actually working properly by implementing this quick (well, not so quick for me) function. Any hints/suggestions/solutions are welcome.

Thank you!

--

Edit:

The "points" are Point objects that hold two integer values for their x and y coordinates The poisson-disk-generator generates a specified number of Point objects and places them in a list

+3  A: 

Assuming your data structure is a list of (x,y) pairs, a simple printing function could be:

for each row
    for each column in current row
        if the pair (col,row) exists in the list of (x,y) points
            print "x"
        else
            print "-"
    print newline

Since this has at least three nested loops, it's not the world's most efficient algorithm but it will be perfectly fast for any grid that you could reasonably print to the console. Improvements could be gained by pre-sorting the list of generated points and changing the searching algorithm, but you probably won't need to do that for now.

Greg Hewgill
Wow, a response within minutes (seconds!?) of posting!
veol
The sun never sets on Stack Overflow.
Greg Hewgill
Thank you! I was able to convert this pseudo-code to something that works. Although, funnily enough, it looks like the only thing I had to debug was this print function. Heh.
veol