Plotting and Previewing
Most of the time, plotting is as simple as sending an appropriate shapely object to the draw
function. See Making Art for more on how to create appropriate shapely geometry, but you are strongly encouraged to call scale_to_fit()
and optimize()
before plotting to make sure that your plot is the correct size for your page and the lines will be drawn in an order that doesn't waste a bunch of time with the pen in the air.
draw(drawing, width=elkplot.sizes.A3[0], height=elkplot.sizes.A3[1], layer_labels=None, preview=True, preview_dpi=128, plot=True, retrace=1, device=None)
Visualize and/or plot a given drawing. Automatically pauses the plotter between layers to allow for changing pens. Geometry can be given as a GeometryCollection (which will be treated as a multi-pen drawing), a list of geometries (in which case again, each will be treated as a separate pen), or any other shapely Geometry (which will be treated as a single layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
drawing |
Geometry | list[Geometry]
|
The shapely geometry to plot. |
required |
width |
float
|
The width of the page in inches (or any other unit if you pass in a |
A3[0]
|
height |
float
|
The height of the page in inches (or any other unit if you pass in a |
A3[1]
|
layer_labels |
Optional[list[str]]
|
An ordered list of labels for each pen-layer. Used only to remind you what pen you should use when swapping pens between layers. If excluded, layers will just be numbered. |
None
|
preview |
bool
|
Should an on-screen preview of the plot be displayed? |
True
|
preview_dpi |
float
|
How big should the preview be? (Enter the DPI of your monitor to get an actual-size preview.) |
128
|
plot |
bool
|
Should the AxiDraw actually plot this? (If |
True
|
retrace |
int
|
How many times should the AxiDraw draw each line? If this is set to 2, it will draw a whole layer, then draw that layer a second time, then either finish or prompt you to change pens. |
1
|
device |
Optional[Device]
|
The AxiDraw config to which the plot should be sent. If excluded, a |
None
|
Source code in elkplot/util.py
Managing the AxiDraw
The draw
function above takes an optional Device as input. The device contains all the settings for how the AxiDraw
actually goes about the business of plotting. This code was largely borrowed from the axi python library by Michael Fogleman. Generally speaking, I only pass Device objects to the draw function, but it also contains functions for directly controlling the AxiDraw.
A common use case is slowing down the AxiDraw for pens that don't leave behind enough ink at the current speed. That would look something like this:
import shapely
import elkplot
drawing = shapely.MultiLineString([...])
device = elkplot.Device(max_velocity=2)
elkplot.draw(drawing, device=device)
Device
Source code in elkplot/device.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
__init__(pen_up_position=-50, pen_down_position=-120, pen_up_speed=150, pen_down_speed=150, pen_up_delay=50, pen_down_delay=50, acceleration=16, max_velocity=4, corner_factor=0.001, jog_acceleration=16, jog_max_velocity=8, pen_lift_pin=2, brushless=True)
Construct a Device object that contains all the settings for the AxiDraw itself. The default values are chosen based on what works for me and my AxiDraw with the upgraded brushless penlift motor - you may need to change these for your AxiDraw.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pen_up_position |
float
|
To what level should the pen be lifted? (I found this value by trial and error.) |
-50
|
pen_down_position |
float
|
To what level should the pen be lowered? (I found this value by trial and error.) |
-120
|
pen_up_speed |
float
|
How fast should the pen be lifted? |
150
|
pen_down_speed |
float
|
How fast should the pen be lowered? |
150
|
pen_up_delay |
int
|
How long (in ms) should the AxiDraw wait after starting to raise the pen before taking the next action? (Lower is faster, but can lead to unwanted lines being drawn.) |
50
|
pen_down_delay |
int
|
How long (in ms) should the AxiDraw wait after starting to lower the pen before taking the next action? (Lower is faster, but can lead to wanted lines not being drawn.) |
50
|
acceleration |
float
|
How aggressively should the AxiDraw accelerate up to |
16
|
max_velocity |
float
|
How fast should the AxiDraw move when traveling at top speed? |
4
|
corner_factor |
float
|
What is the radius of the corner when making a sharp turn? Larger values can maintain higher speeds around corners, but will round off sharp edges. Smaller values are more accurate to the original drawing but have to slow down more at sharp corners. |
0.001
|
jog_acceleration |
float
|
How aggressively should the AxiDraw accelerate up to |
16
|
jog_max_velocity |
float
|
How fast should the AxiDraw move when traveling at top speed while the pen is lifted? |
8
|
pen_lift_pin |
int
|
To which pin on the driver board is the penlift motor connected? (Pin 0 is the bottom pin.) |
2
|
brushless |
bool
|
Is the connected motor the upgraded brushless motor? |
True
|
Source code in elkplot/device.py
close()
When you create a Device() object, it monopolizes access to that AxiDraw. Call this to free it up so other programs can talk to it again.
disable_motors()
enable_motors()
goto(x, y, jog=True)
Move the pen directly to a given point on the canvas. Points are measured in inches from the origin Args: x: The x-coordinate of the desired point y: The y-coordinate of the desired point jog: Should it travel at jog-speed or regular?
Source code in elkplot/device.py
home()
move(dx, dy)
Offset the current pen position. Args: dx: The offset in the x direction in inches dy: The offset in the y direction in inches
pen_down()
pen_up()
read_position()
Get the xy coordinates of the pen
Source code in elkplot/device.py
zero_position()
Set the current position of the pen as (0, 0). Called automatically when connecting to the device. For best results, always start and end with the motor in home position. If necessary, though, you can disable motors, manually reset the pen back home, and call this function.