easygraphics.legacy包¶
用于兼容BGI的模块。
本模块使用BGI里面的函数名重新命名了Easygraphics里面的各函数,以便将原有的BGI程序移植到python中。
函数¶
-
easygraphics.legacy.
arc
(x: int, y: int, start: int, end: int, rad: int, img: easygraphics.image.Image = None)¶ 画一个圆弧
arc() draws the outline of an arc in the current drawing color. The circular arc is centered at (‘x’,’y’) with a radius of ‘rad’. The arc travels from ‘start’ to ‘end.
- Note: ‘start’ and ‘end’ are in degrees; 0 degrees is a 3
- o’clock.
-
easygraphics.legacy.
bar
(left: float, top: float, right: float, bottom: float, image: easygraphics.image.Image = None)¶ Draws a rectangle with upper left corner at (left, top) and lower right corner at (right,bottom).
The rectangle doesn’t have outline.
参数: - left – x coordinate value of the upper left corner
- top – y coordinate value of the upper left corner
- right – x coordinate value of the lower right corner
- bottom – y coordinate value of the lower right corner
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
circle
(x: float, y: float, r: float, image: easygraphics.image.Image = None)¶ Draw a circle outline centered at (x,y) with radius r.
The circle is not filled.
参数: - x – x coordinate value of the circle’s center
- y – y coordinate value of the circle’s center
- r – radius of the circle
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
cleardevice
(image: easygraphics.image.Image = None)¶ Clear the image to show the background.
参数: image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
clearviewport
(image: easygraphics.image.Image = None)¶ clear view port to show the background.
参数: image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
closegraph
()¶ Close the graphics windows.
The program will exit too.
>>> from easygraphics import * >>> init_graph(800,600) >>> pause() >>> close_graph()
-
easygraphics.legacy.
drawpoly
(*end_points, image: easygraphics.image.Image = None)¶ Draw a poly line.
“end_points” is a 2D points list. Each 2 values in the list make a point. A poly line will be drawn to connect adjacent end_points defined by the the list.
For examples , if “end_points” is [50,50,550,350, 50,150,550,450, 50,250,550,550], draw_poly_line() will draw 5 lines: (50,50) to (550,350), (550,350) to (50,150), (50,150) to (550,450), (550,540) to (50,250) and(50,250) to (550,550).
>>> from easygraphics import * >>> init_graph(600,600) >>> draw_poly_line(50,50,550,350,50,150,550,450,50,250,550,550) >>> pause() >>> close_graph()
参数: - end_points – point value list
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
ellipse
(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)¶ Draw an elliptical arc from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.
Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.参数: - x – x coordinate value of the ellipse’s center
- y – y coordinate value of the ellipse’s center
- start_angle – start angle of the arc
- end_angle – end angle of the arc
- radius_x – radius on x-axis of the ellipse
- radius_y – radius on y-axis of the ellipse
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
fillellipse
(x, y, radius_x, radius_y, image: easygraphics.image.Image = None)¶ Draw an ellipse centered at (x,y) , radius on x-axis is radius_x, radius on y-axis is radius_y.
The ellipse is filled and has outline.
参数: - x – x coordinate value of the ellipse’s center
- y – y coordinate value of the ellipse’s center
- radius_x – radius on x-axis of the ellipse
- radius_y – radius on y-axis of the ellipse
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
fillpoly
(*vertices, image: easygraphics.image.Image = None)¶ Fill a polygon.
“vertices” is a 2D point list. Each 2 values in the list make a point. A polygon will be drawn to connect adjacent points defined by the the list.
For examples , if “vertices” is [50,50,550,350, 50,150], fill_polygon() will fill a triangle with vertices at (50,50) , (550,350) and (50,150).
The polygon doesn’t have outline.
>>> from easygraphics import * >>> init_graph(600,600) >>> set_fill_color(Color.LIGHT_MAGENTA) >>> fill_polygon(50,50,550,350,50,150) >>> pause() >>> close_graph()
参数: - vertices – point value list
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
floodfill
(x: int, y: int, border_color, image: easygraphics.image.Image = None)¶ Flood fill the image starting from(x,y) and ending at borders with border_color.
The fill region border must be closed,or the whole image will be filled!
参数: - x – x coordinate value of the start point
- y – y coordinate value of the start point
- border_color – color of the fill region border
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
getbkcolor
(image: easygraphics.image.Image = None) → PyQt5.QtGui.QColor¶ Get the background color of the image.
参数: image – the target image whose background color is to be gotten. None means it is the target image (see set_target() and get_target()). 返回: background color of the specified image
-
easygraphics.legacy.
getcolor
(image: easygraphics.image.Image = None) → PyQt5.QtGui.QColor¶ Get the foreground (drawing) color of the specified image.
it will be used when drawing lines or shape outlines
参数: image – the target image whose foreground color is to be gotten. None means it is the target image (see set_target() and get_target()). 返回: foreground color of the specified image
-
easygraphics.legacy.
getfillsettings
(img: easygraphics.image.Image = None)¶ get fill settings
返回: fill style, fill color
-
easygraphics.legacy.
getimage
(left: int, top: int, right: int, bottom: int, target_img: easygraphics.image.Image)¶ Capture specified region on the graphics windows to target image.
参数: - left – x coordinate of the capture region’s upper left corner
- top – y coordinate of the capture region’s upper left corner
- right – x coordinate of the capture region’s bottom right corner
- bottom – y coordinate of the capture region’s bottom right corner
- target_img – image to save the capture
-
easygraphics.legacy.
getlinesettings
(img: easygraphics.image.Image = None)¶ Get line settings
返回: line style, line width
-
easygraphics.legacy.
getmaxx
(img: easygraphics.image.Image = None) → int¶ Get the maximum x value of graphics screen
返回: the maximum x value
-
easygraphics.legacy.
getmaxy
(img: easygraphics.image.Image = None)¶ Get the maximum y value of graphics screen
返回: the maximum y value
-
easygraphics.legacy.
getpixel
(x: int, y: int, image: easygraphics.image.Image = None) → PyQt5.QtGui.QColor¶ Get a pixel’s color on the specified image.
参数: - x – x coordinate value of the pixel
- y – y coordinate value of the pixel
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
返回: color of the pixel
-
easygraphics.legacy.
getx
(image: easygraphics.image.Image = None) → float¶ Get the x coordinate value of the current drawing position (x,y).
Some drawing functions will use the current pos to draw.(see line_to(),line_rel(),move_to(),move_rel()).
参数: image – the target image whose drawing pos is to be gotten. None means it is the target image (see set_target() and get_target()). 返回: the x coordinate value of the current drawing position
-
easygraphics.legacy.
gety
(image: easygraphics.image.Image = None) → float¶ Get the y coordinate value of the current drawing position (x,y).
Some drawing functions will use the current pos to draw.(see line_to(),line_rel(),move_to(),move_rel()).
参数: image – the target image whose drawing pos is to be gotten. None means it is the target image (see set_target() and get_target()). 返回: the y coordinate value of the current drawing position
-
easygraphics.legacy.
initgraph
(width: int = 800, height: int = 600, headless: bool = False)¶ Init the easygraphics system and show the graphics window.
If “headless” is True, easygraphics will run in headless mode, which means there will be no graphics window. Use this mode if you want to draw and save image to files.
参数: - width – width of the graphics window (in pixels)
- height – height of the graphics window (in pixels)
- headless – True to run in headless mode.
>>> from easygraphics import * >>> init_graph(800,600) #prepare and show a 800*600 window
-
easygraphics.legacy.
line
(x1, y1, x2, y2, image: easygraphics.image.Image = None)¶ Draw a line from (x1,y1) to (x2,y2) on the specified image.
It’s the same with line().
参数: - x1 – x coordinate value of the start point
- y1 – y coordinate value of the start point
- x2 – x coordinate value of the end point
- y2 – y coordinate value of the start point
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
linerel
(dx: float, dy: float, image: easygraphics.image.Image = None)¶ Draw a line from the current drawing position (x,y) to (x+dx,y+dy), then set the drawing position is set to (x+dx,y+dy).
参数: - dx – x coordinate offset of the new drawing position
- dy – y coordinate offset of the new drawing position
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
lineto
(x: float, y: float, image: easygraphics.image.Image = None)¶ Draw a line from the current drawing position to (x,y), then set the drawing position is set to (x,y).
参数: - x – x coordinate value of the new drawing position
- y – y coordinate value of the new drawing position
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
moverel
(dx: float, dy: float, image: easygraphics.image.Image = None)¶ Move the drawing position by (dx,dy).
If the old position is (x,y), then the new position will be (x+dx,y+dy).
The drawing position is used by line_to(), line_rel().
参数: - dx – x coordinate offset of the new drawing position
- dy – y coordinate offset of the new drawing position
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
moveto
(x: float, y: float, image: easygraphics.image.Image = None)¶ Set the drawing position to (x,y).
The drawing position is used by line_to(), line_rel() and move_rel().
参数: - x – x coordinate value of the new drawing position
- y – y coordinate value of the new drawing position
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
outtext
(text: str, img: easygraphics.image.Image = None)¶ Display the given text on the current position
参数: text – text to be displayed
-
easygraphics.legacy.
outtextxy
(x: int, y: int, text: str, img: easygraphics.image.Image = None)¶ Display the given text on the specified position
参数: - x – x pos of the string
- y – y pos of the string
- text – text to be displayed
-
easygraphics.legacy.
pieslice
(x: float, y: float, start_angle: int, end_angle: int, r: float, img: easygraphics.image.Image = None)¶
-
easygraphics.legacy.
putimage
(left: int, top: int, src_image: easygraphics.image.Image, mode: int, dst_image: easygraphics.image.Image = None)¶ Puts a previously-saved bit image back onto the screen.
The coordinates (‘left’,’top’) are used to place the image on the screen.
image is a previously screen copy (using getimage()).
‘op’ determines how the color for each destination pixel is computed. This is based on the pixel already on the screen and the source pixel in memory. The available ops are COPY_PUT, XOR_PUT, OR_PUT, AND_PUT and NOT_PUT
参数: - left – left position on the screen to be copied
- top – top position on the screen to be copied
- src_image – the image to be copied
- op – copy operation
-
easygraphics.legacy.
putpixel
(x: int, y: int, color, image: easygraphics.image.Image = None)¶ Set a pixel’s color on the specified image.
参数: - x – x coordinate value of the pixel
- y – y coordinate value of the pixel
- color – the color
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
rectangle
(left: float, top: float, right: float, bottom: float, image: easygraphics.image.Image = None)¶ Draws a rectangle outline with upper left corner at (left, top) and lower right corner at (right,bottom).
The rectangle is not filled.
参数: - left – x coordinate value of the upper left corner
- top – y coordinate value of the upper left corner
- right – x coordinate value of the lower right corner
- bottom – y coordinate value of the lower right corner
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
sector
(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)¶ Draw an elliptical pie from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.
The pie is filled and has outline.
Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.参数: - x – x coordinate value of the ellipse’s center
- y – y coordinate value of the ellipse’s center
- start_angle – start angle of the pie
- end_angle – end angle of the pie
- radius_x – radius on x-axis of the ellipse
- radius_y – radius on y-axis of the ellipse
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
setbkcolor
(color, image: easygraphics.image.Image = None)¶ Set and change the background color.
the possible color could be consts defined in Color class, or the color created by rgb() function, or PyQt5’s QColor , QGradient object or Qt.GlobalColor consts (see the pyqt reference).
参数: - color – the background color
- image – the target image whose background color is to be set. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
setcolor
(color, image: easygraphics.image.Image = None)¶ Set the foreground (drawing) color of the specified image.
it will be used when drawing lines or shape outlines.
the possible color could be consts defined in Color class, or the color created by rgb() function, or PyQt5’s QColor , QGradient object or Qt.GlobalColor consts (see the pyqt reference).
参数: - color – the foreground color
- image – the target image whose foreground color is to be set. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
setfillstyle
(pattern, color, img: easygraphics.image.Image = None)¶ Set fill pattern :param pattern: fill style :param color: fill color
-
easygraphics.legacy.
setlinestyle
(linstyle, upattern, thickness, img: easygraphics.image.Image = None)¶ Set line style :param linstyle: line style :param upattern: no use :param thickness: line width :param img: :return:
-
easygraphics.legacy.
settextjustify
(horiz: int, vert: int)¶ Set Current Text Justification Settings
settextjustify() controls text justification with respect to the current position (CP). The text is justified horizontally and vertically.
Constants of the text_just for ‘horiz’ are: LEFT_TEXT, CENTER_TEXT, RIGHT_TEXT
Constants of the text_just for ‘vert’ are: TOP_TEXT, CENTER_TEXT, BOTTOM_TEXT
-
easygraphics.legacy.
setviewport
(left: int, top: int, right: int, bottom: int, clip: bool = True, image: easygraphics.image.Image = None)¶ Set the view port of the the specified image.
View port is the drawing zone on the image.
>>> from easygraphics import * >>> init_graph(800,600) >>> draw_rect(100,100,300,300) >>> set_view_port(100,100,300,300) >>> circle(100,100,50) >>> circle(100,100,100) >>> circle(100,100,120) >>> pause() >>> close_graph()
参数: - left – left of the view port rectangle
- top – top of the view port rectangle
- right – right of the view port rectangle
- bottom – bottom of the view port rectangle
- clip – if True, drawings outside the port rectangle will be clipped
- image – the target image whose view port is to be gotten. None means it is the target image (see set_target() and get_target()).
-
easygraphics.legacy.
setwritemode
(mode, img: easygraphics.image.Image = None)¶ Set Write Mode for Line Drawing
This function sets the writing mode for line drawing. If mode is 0, lines overwrite the screen’s current contents. On the other hand, If mode is 1, an exclusive OR (XOR) is done.
-
easygraphics.legacy.
textheight
(image: easygraphics.image.Image = None) → int¶ Return height of the text (font height).
参数: image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()). 返回: height of the text (font height)
-
easygraphics.legacy.
textwidth
(text: str, image: easygraphics.image.Image = None) → int¶ Return width of the text.
参数: - text – the text
- image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
返回: 文字内容的宽度