130 likes | 274 Views
C++ Graphics Primitives. April 15th. void clearscreen(int c) clear the screen to background color c If c <= 0 screen white If c >= 1 screen black. void moveto(int x, int y) Cursor moves to position (x,y) (without drawing anything on the screen) The value x must be between 0 and maxX
E N D
C++ Graphics Primitives April 15th
void clearscreen(int c) • clear the screen to background color c • If c <= 0 screen white • If c >= 1 screen black
void moveto(int x, int y) • Cursor moves to position (x,y) (without drawing anything on the screen) • The value x must be between 0 and maxX • The value y must be between 0 and maxY
int getmaxx() Return the integer value of maxX for the screen int getmaxy() Return the integer value of maxX for the screen
Example void main () { int x,y; x = getmaxx(); y = getmaxy(); moveto(x/2, y/2); }
void setcolor(int c) • Set the color of the pen that will be drawing lines and shapes on screen to color c • If c <= 0 pen color white • If c >= 1 pen color black • Note: white pen on white screen (also black pen on black screen) will not show up (can be used to erase)
void lineto(int x, int y) • Draw a straight line from current position of cursor to position (x,y) on screen using current pen color • Example: … clearscreen(0); //screen white setcolor(1); //pen black moveto(20,20); //move cursor to (20,20) lineto(100,100);
void rectangle(int x1, int y1, int x2, int y2) • Draw a rectangle with upper left corner at position (x1, y1) and lower right corner (x2, y2)
void circle(int x, int y, int r) • Draw a circle with center at (x,y) and radius r
void writedraw(type value, int x, int y) - where type can be int, char or a text (string) - display the value at position (x,y) on screen Example: ... writedraw(3, 10, 10); writedraw(“Stop right here!!”, 100, 100); writedraw(‘a’, 25, 25); …
void getmouse(int &x, int &y) • Get into x and y the current mouse coordinates at the instant when the mouse is clicked • Example: int x, y; getmouse(x,y); if (x <= 100 && y <= 100) { writedraw( “Bingo! You clicked in the upper left corner!”, 10, 10); } else { writedraw(“soryy…try again…”, 10, 10); }
Click here to exit Stop!