Thread: Please Help!

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    3

    Please Help!

    hi everybody,

    i have a function paint (x,y) and i have to paint a city. (it is not a regular shape)
    Lets Assume this fuction paint(x,y) is painting point by point ok!!

    so could anybody give the ReCursive C code to paint the city

    Note:I know the coordinates of the border we can think it as a matrix data structure

    Thanks for your answers

  2. #2
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Well, since I don't know how your code is...I'll just kinda give you some pseudo code.

    Code:
    int height=20, width=50;
    
    for (int i=0; i<height; i++){
          for (int j=0; j<width; j++){
                  paint(j,i);
          }
    }
    Hope this is kind of the idea you were looking for. Again, it's just pseudo code, really...but it illustrates the idea. It will fill in the first row horizontally from left to right, then move down to the next row and fill that one in. The outer for loop doesn't increase and move to a new row until the inner loop has executed throughout the entire width of city.

    Oh, and that's not recursive...but it should be okay.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    5
    Quote Originally Posted by porsuk
    hi everybody,

    i have a function paint (x,y) and i have to paint a city. (it is not a regular shape)
    Lets Assume this fuction paint(x,y) is painting point by point ok!!

    so could anybody give the ReCursive C code to paint the city

    Note:I know the coordinates of the border we can think it as a matrix data structure

    Thanks for your answers
    Hi !
    Isn't so harrashing to pick a coordinate and put it as a pixel , and are you sure you will point all the pixel as a picture ?
    Why don't you scan a picture- change the JPG picture to binary code and transfer it into your C program.
    Try it
    Bye

  4. #4
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    You need to describe your problem in much more detail. What is this 'city' of which you speak? What describes the 'city'?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You paint a point x,y
    You then examine points x-1,y x+1,y, x,y-1 and x,y+1 to see if you've reached a border.
    If you haven't, recursively call yourself with x-1,y etc

    Note: This algorithm sucks, but it is what you asked for.

    If you want a serious answer (not a homework answe), then look up the scanline fill algorithm at a google prompt near you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed