Using line styles, you can control how the lines and outlines are drawn. The most useful line styles are:
- line width
- line shape
You can use set_line_width()/get_line_width() to get or set line width.
The following program draws a rectangle whose borders width is 10.
from easygraphics import *
def main():
init_graph(400, 300)
set_line_width(10)
draw_rect(50, 50, 350, 250)
pause()
close_graph()
easy_run(main)
Using line shapes, you can draw dash line or dot line. Use set_line_style()/get_line_style() to set line shape.
LineStyle.SOLID_LINE | LineStyle.DASH_LINE | LineStyle.DOT_LINE |
LineStyle.DASH_DOT_LINE | LineStyle.DASH_DOT_DOT_LINE | LineStyle.NO_PEN |
The following program draws a rectangle with dash outlines.
from easygraphics import *
def main():
init_graph(400, 300)
set_line_width(10)
set_line_style(LineStyle.DASH_LINE)
draw_rect(50, 50, 350, 250)
pause()
close_graph()
easy_run(main)
If predefined line shapes is not satisfying, you can set custome line shape. To do this, you should:
- use get_target() or create_image() to get the Image object you want to draw.
- use the Image object's get_pen() to get the pen. It's a PyQt's QPen object.
- Use the pen's setDashPattern() to set custom line shape.
from easygraphics import *
def main():
init_graph(400, 300)
set_line_width(10)
target_image = get_target()
pen = target_image.get_pen()
pen.setDashPattern([1, 5, 2, 5])
draw_rect(50, 50, 350, 250)
pause()
close_graph()
easy_run(main)
After getting the pen object, you can set other pen attributes to get more line styles. See QPen's documentation.