+""" piasketch - The Pi-A-Sketch program draws a few circles
+It is also a basic library for steppers controlling an X/Y device.
+The main functions are line(x,y) and circle(radius).
+PINS_A = [4, 25, 24, 23]
+PINS_B = [22, 21, 18, 17]
+SEQA = [(4, ), (4, 25), (25, ), (25, 24), (24, ), (24, 23), (23, ), (23, 4)]
+RSEQA = SEQA[::-1][1:] + SEQA[::-1][:1]
+SEQB = [(22, ), (22, 21), (21, ), (21, 18), (18, ), (18, 17), (17, ), (17, 22)]
+RSEQB = SEQB[::-1][1:] + SEQB[::-1][:1]
+ Before we can use them, we need to set the pins for both motors
+ gpio.setup(pin, gpio.OUT)
+def stepper(sequence, pins, delay=0.002):
+ One full step, based on an ordered sequence and corresponding pins
+ gpio.output(pin, gpio.HIGH if pin in step else gpio.LOW)
+def move(steps, axis="x"):
+ Move a certain number of steps on a specific axis. sign for direction
+ (seq, pins) = (SEQA, PINS_A) if axis == "x" else (SEQB, PINS_B)
+ seq = RSEQA if axis == "x" else RSEQB
+ Bresenham's line algorithm from rosetta code (ADA/Python),
+ adapted to relative positioning. It will be drawn from current
+ position to x1,y1. Negative number goes in other direction.
+ sx = -1 if 0 > x1 else 1
+ sy = -1 if 0 > y1 else 1
+ mid point circle drawing algorithm - basically Bresenham's.
+ It was converted for use with relative. Cant use the bitmap
+ approach of the original algorithm. Points are sequential
+ clockwise. It works, but it is ugly. I only had a few
+ minutes to write this. It needs to be cleaned up.
+ ddf_x, ddf_y = 1, -2 * radius
+ segment.append((x0 + x, y0 + y))
+ segment.append((x0 + y, y0 + x))
+ segment.append((x0 + y, y0 - x))
+ segment.append((x0 + x, y0 - y))
+ segment.append((x0 - x, y0 - y))
+ segment.append((x0 - y, y0 - x))
+ segment.append((x0 - y, y0 + x))
+ segment.append((x0 - x, y0 + y))
+ Draw a circle of specified radius. It is not centered. It will start
+ drawing a circle at its current position, going right and down.
+ points = _circlepoints(radius)
+ dx, dy = x - px, y - py
+ elif counter == quarter * 2:
+ elif counter == quarter * 3:
+ As a standalone app, draw a few circles
+ for radius in range(100,400,25):
+if __name__ == "__main__":