grid.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 23 行

CPP
23
字号
#include "canvas.h"     // for Canvas
#include "strutils.h"   // for tostring(int)
// illustrates line and text drawing in Canvas class
int main()
{
    const int GRID_SIZE = 200;
    const int SIZE=  20;   // fudge dimensions to make room for text
    Canvas c(GRID_SIZE+SIZE, GRID_SIZE+SIZE,100,100);
    int j;
    for(j=0; j <= GRID_SIZE; j+= SIZE)
    {   c.SetColor(BLACK);       
        c.DrawString(tostring(j), Point(0,j));  // draw text labels
        c.DrawString(tostring(j), Point(j,0));
    }
    c.SetColor(BLUE);
    for(j=0; j <= GRID_SIZE; j+= SIZE)
    {   c.DrawLine(Point(j,0), Point(j,GRID_SIZE));  // horizontal line 
        c.DrawLine(Point(0,j), Point(GRID_SIZE,j));  // vertical line
    }    
    c.runUntilEscape();
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?