Tutorial: A simple triangle shape
Interface
- Click on the plus signs () to see the comments about the corresponding line of code.
- You can also click on the copy icon located at the upper right corner to copy the code to your clipboard.
- Clicking on the images will open them.
- Graphic output of the scripts are shown next to or below the code snippets.
- Some examples may have more then one script in the same block. These are presented in a tabbed format. You can click on the tabs to see the other scripts.
-
Always import the library like this!
And never usefrom simetri import *
since it may create a lot of problems! Your namespace will be polluted and debugging will be very difficult. -
- We do not need to specify
sizefor the canvas. It will be automatically computed if it is not used. canvas = sg.Canvas(back_color=sg.yellow)can be used to set the background color.canvasis the conventional variable name for theCanvasinstances but you can use any valid variable name.
- We do not need to specify
-
Points
- Points can be any sequence of (x, y) or (x, y, 1) values.
[(10, 20), (30, 40), ...], ([15.5, 20., 1], [35, 40, 1], ...) are all valid. simetriinternally converts them to floating pointnumpyarrays.- The units for cooordinates is
pnts.72pnts = 1in - Point sizes should be reasonable. If a shape is too large to fit into a page or too small to see clearly, we may have numerical problems.
- Points can be any sequence of (x, y) or (x, y, 1) values.
-
By default
shape.closed = Falseunless the start and end points are equivalent.
sg.Shape(points, closed=True)can be used to create a closed shape. -
The default value for
shape.line_width = 1butcanvas.draw()can overwrite any style attributes. -
All angles in SİMETRİ is counterclockwise positive and in radians. To convert between radians and angles, you can use
sg.radians(angle)andsg.degrees(angle)utility functions to convert an angle from degrees to radians and from radians to degrees respectively. -
You can use
canvas.save("/your/path/here.pdf")or in Windowscanvas.save("c:/your/path/here.svg")to generate an output file. The supported formats are:.tex,.pdf,.svg,.ps,.eps, and.png. You can also use theshowflag to show the output in a web-browser (the default value forshowisTrue). Only.pdf,.svg, and.pngfiles can be shown) You can use theoverwriteflag to overwrite any existing files.
canvas.save("/your/path/here.pdf", show=False, overwrite=True)
