X_SIZE = 600 Y_SIZE = 600 STEP = 10 FEEDRATE = 3600 FILENAME = "wearin.gcode" MOVE_COMMAND = "G0 F{}".format(FEEDRATE) + " X{x} Y{y}\n" def next_move(travel_length, step_length, step_size): next_travel = travel_length yield (next_travel, 0) for step in xrange(step_size, step_length+step_size, step_size): yield (next_travel, step) if next_travel == 0: next_travel = travel_length else: next_travel = 0 yield (next_travel, step) with open(FILENAME, "w") as output: for x, y in next_move(X_SIZE, Y_SIZE, STEP): output.write(MOVE_COMMAND.format(x=x, y=y)) output.write(MOVE_COMMAND.format(x=0, y=0)) for y, x in next_move(Y_SIZE, X_SIZE, STEP): output.write(MOVE_COMMAND.format(x=x, y=y)) output.write(MOVE_COMMAND.format(x=0, y=0))