drawing lines and rectangles in c++

This is a discussion on drawing lines and rectangles in c++ within the C++ Programming forums, part of the General Programming Boards category; hi im making a program that dependent on the users imputs and the calculations afterward displays a grid. the trouble ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    118

    drawing lines and rectangles in c++

    hi im making a program that dependent on the users imputs and the calculations afterward displays a grid.
    the trouble is that i am not sure how to draw lines or rectangles i know that i need to put co-ordinates but i dont really know how to make the line draw on screen.
    oh and another question is my program starts with this code
    Code:
    // PROGRAM TO WORK MATERIALS OUT FOR A CEILING
    
    #include <iostream>
     
    using namespace std;
    bool YesNo(char* prompt)
    {
          cout << prompt;
          char yesno;
          cin.ignore(cin.rdbuf()->in_avail());
          yesno = cin.get();
          cin.ignore(cin.rdbuf()->in_avail());
          return(yesno == 'Y' || yesno == 'y');
    }
    
    int main()
    {
    int long_wall;
    int short_wall;
    int atile, btile, totaltile;
    int runnersinglerow; 
    int rsr, rowsofrunner,totalrunner,theover;
    int a1200a, a1200,b1200a, b1200, total1200;
    int a600,a600a, b600,b600a, total600;
    
    do {
    cout<< "please enter the the length of the longest wall if the\n";
    cout<<" sofit is concerete otherwise enter the length of the wall\n";
    cout<<"opposite the joists.ok ive fixed it now it will work every time :) i hope lol\n";
    cin>>long_wall;
    cin.ignore();
    
    cout<< "now enter the lenght of the other wall.\n";
    cin>>short_wall;
    cin.ignore();
    
           rsr=long_wall%3600;
           runnersinglerow=long_wall/3600;
           rowsofrunner=short_wall/1200;
           theover=rowsofrunner/2; 
               
         if (rsr<1800)
           totalrunner=runnersinglerow*rowsofrunner+theover;       
           
           if (rsr>1800)
           runnersinglerow++;    
           totalrunner=runnersinglerow*rowsofrunner;
           cout<<"you will need... "<<totalrunner<<" runners\n";
              
              
               a1200=(long_wall/600);
               b1200=(short_wall/1200+1);
               total1200=a1200*b1200;
               cout<<"you will need... "<<total1200<<" 1200 bars\n";
                  
                  
                   a600=long_wall/600+1;
                   b600=short_wall/1200+1;
                   total600=a600*b600;
                   cout<<"you will need... "<<total600<<" 600 bars\n";
                        
                        
                        atile=long_wall/600+1;
                        btile=short_wall/600+1;
                        totaltile=atile*btile;
                        cout<<"you will need... "<<totaltile<<" tiles\n";
                        
    cout<<"dont forget this is the proto type lol\n";
    }
    
    while(YesNo("Restart? (Y / Any key) "));
          
          return 0;
    }
    ok so my code works fine but now is it possible to make this same program display graphics? thank you in advance
    oh and by the way just so people dont think im a stealer the yes no part of the code was not wrote by me niether do i at this point really understand it.
    Last edited by thestien; 10-05-2006 at 03:40 PM.

  2. #2
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    here is my pusdo code for the rectangle i need to make first
    draw rectangle(0,0,long_wall,sort_wall)

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    and for the first line i need to draw
    draw line
    start (0,short_wall%1200/2+600)
    end (long_wall,shortwall%1200/2+600)

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    please help me sombody just post a few keywords to google or somthing lol
    im really stuck and cant find any thing.
    what i really need is the
    cout<< ;
    that makes text so how do i cout a rectangle so to speak
    and cout a line?

  5. #5
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Some advice:
    1) Use descriptive variable names.
    2) Graphics can't be done with plain ol' C++.
    3) Indent your code.
    4) Don't bump your posts an hour after your original.
    5) You need an API of sorts.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    ok thank you for the advice could u recomend what i should learn in order to make these lines and rectangles and sorry about bumping i really want to finish the program because ive done all of the sums i need and planned the rest of the code.

  7. #7
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Well since your in a hurry, I would reccomend either Allegro library or SDL. I would go with Allegro, since it has functions for drawing lines and rectangles very easily. I think DirectX would be overkill, since knowledge of WindowsAPI is needed.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    ok thank you again but do these things work in dev-c++?
    i mean i can learn as i go so time aint really a problem it was just i thought it might of been similar to cout which would of meant a quick fix.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    2) Graphics can't be done with plain ol' C++.
    No, but something like this can:
    Code:
    +-------------------+
    | Total lines: 4286 |
    +-------------------+
    If that's what you want then you should be able to do it with a few for loops or even hard coded strings.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    ok thank you again but do these things work in dev-c++?
    i mean i can learn as i go so time aint really a problem it was just i thought it might of been similar to cout which would of meant a quick fix.

  11. #11
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Quote Originally Posted by dwks
    No, but something like this can:
    Code:
    +-------------------+
    | Total lines: 4286 |
    +-------------------+
    If that's what you want then you should be able to do it with a few for loops or even hard coded strings.
    Yes, I understand. Some cool things can be done with simple ASCII chars. But I would think he wanted something more professional looking

    Yes, these will work with Dev-C++. Just follow the instructions[on the site] for which ever library you pick.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  12. #12
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    ok thanks for your help guys er ill have a look into this i just found an example on the dev-c++ for open gl which makes a window with a star like shape in it ill try to recode that to see if i can make the grid i need

  13. #13
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    It might be a lot of code to handle. It contains Win32 code, which is needed to create the window. With SDL or Allegro a window is created automatically, so no need to mess with 70 lines of code, just to create a window. Also, SDL is cross platform, not sure about Allegro though (OpenGL is cross platform as well).
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  14. #14
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    ahh cool so sdl sounds the best bet for me.
    do i have to rewrite my original program i mean does sdl still use cout<<
    and cin>> or will all these things be slighly different?

  15. #15
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Well, graphics aren't very simple. The easiest for creating graphics would be the libraries I just said, then, OpenGL or DirectX after. Here is an SDL tutorial, I suggest you take a look: http://lazyfooproductions.com/SDL_tutorials/index.php
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing program architecture - information needed
    By Marko_D in forum Windows Programming
    Replies: 1
    Last Post: 11-28-2003, 06:46 PM
  2. Drawing a triangle with hatch marks?
    By Bajanine in forum Windows Programming
    Replies: 4
    Last Post: 05-19-2003, 05:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21