C Graphics Primitives - PowerPoint PPT Presentation

About This Presentation
Title:

C Graphics Primitives

Description:

C++ Graphics Primitives April 15th void clearscreen(int c) clear the screen to background color c If c = 1 screen black void moveto(int x, int ... – PowerPoint PPT presentation

Number of Views:124
Avg rating:3.0/5.0
Slides: 13
Provided by: mbowden
Category:

less

Transcript and Presenter's Notes

Title: C Graphics Primitives


1
C Graphics Primitives
  • April 15th

2
  • void clearscreen(int c)
  • clear the screen to background color c
  • If c lt 0 screen white
  • If c gt 1 screen black

3
  • 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

4
  • int getmaxx()
  • Return the integer value of maxX for the screen
  • int getmaxy()
  • Return the integer value of maxX for the screen

5
Example
  • void main ()
  • int x,y
  • x getmaxx()
  • y getmaxy()
  • moveto(x/2, y/2)

6
  • void setcolor(int c)
  • Set the color of the pen that will be drawing
    lines and shapes on screen to color c
  • If c lt 0 pen color white
  • If c gt 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)

7
  • 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)

8
  • 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)

9
  • void circle(int x, int y, int r)
  • Draw a circle with center at (x,y) and radius r

10
  • 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)

11
  • 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 lt 100 y lt 100)
  • writedraw( Bingo! You clicked in the upper
    left corner!, 10, 10)
  • else
  • writedraw(soryytry again, 10, 10)

12
Click here to exit
Stop!
Write a Comment
User Comments (0)
About PowerShow.com