Thread: grid

  1. #1
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186

    Question grid

    I'm working on a cellular automata program. (Conway's Game of Life) for example.

    Heres a java example: http://hensel.lifepatterns.net/
    click on "Enjoy Life" to launch applet.

    You can see theres a grid which is clickable.

    How would i go about making a grid in win32? Just draw lines and specify xy coordinates for the boxes?
    the best things in life are simple.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    That's it. Make a pen, and use LineTo/MoveToEx to do the drawing:

    Code:
    for(x = startX; x < maxX; x += grid_spread){
    MoveToEx(hdc, x, startY);
    LineTo(hdc, x, maxY);
    }
    for(y = startY; y < maxY; y += grid_spread){
    MoveToEx(hdc, startX, y);
    LineTo(hdc, maxX, y);
    }


    Hope that helps.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    What if I load a bitmap of a grid. Could I still make the individual boxes clickable and fillable?
    the best things in life are simple.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I would use an array of RECT's.
    Then use PtInRect() and a loop using the array index to work out where has been clicked.
    FillRect() Rectangle() FrameRect() ect to draw them again with the loop.

    If you use a bitmap then you will have to calculate a scale based on the screen size to image size.

    Code:
    	for(i=0;i<ROWS;i++)
    	{
    		
    		for(j=0;j<COLS;j++)
    		{
    			if(PtInRect(&(rBoardRect[i][j]),MousePoint))
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. More Windows Trouble
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 04-12-2005, 10:02 AM
  2. Cleaning up a Grid of Memory
    By Epo in forum C++ Programming
    Replies: 9
    Last Post: 02-25-2005, 10:23 AM
  3. Find a word in a 2d grid
    By The_Kingpin in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2005, 05:38 PM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  5. I need help making a grid!
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 09-02-2002, 05:46 AM