def plot_hpgl_file(file): '''Send an HPGL file to the plotter found connected to the computer.''' plotter = instantiate_virtual_plotter((0,0), (20000,15000)) plotter.set_origin_bottom_left() plotter.write_file(file) ## call flush( ) to wait till all data is written before exiting... plotter._serial_port.flush( ) io.view(plotter)
def plot_hpgl_file(file): """Send an HPGL file to the plotter found connected to the computer.""" plotter = instantiate_virtual_plotter((0, 0), (20000, 15000)) plotter.set_origin_bottom_left() plotter.write_file(file) ## call flush( ) to wait till all data is written before exiting... plotter._serial_port.flush() io.view(plotter)
def main(): plotter = instantiate_virtual_plotter(Coordinate(0, 0), Coordinate(30000, 20000)) data_file = open("./media/indoor_temp.txt", "r") data = data_file.readlines() print "read %d data points." % len(data) # make an empty list and fill it with data points as coordinates points = [] x = 0 for y in data: # we use rstrip() to remove the line break y_value = eval(y.rstrip()) * 100 # print "y_value: %f" % y_value c = Coordinate(x, y_value) points.append(c) x += 10 data_path = shapes.path(points) plotter.select_pen(4) plotter.write(data_path) # let's offset it and plot it again! offset(data_path, (1000, 1000)) plotter.select_pen(5) plotter.write(data_path) # let's draw a box around our offset plot (min, max) = data_path.minmax_coordinates (width, height) = max - min r = shapes.rectangle(width, height) # a rectangle has its center at (0,0) # so we shift it over so that its lower, left corner is (0,0) # and we shift it some more to fit around our offset data transforms.offset(r, (width / 2, height / 2)) transforms.offset(r, min) plotter.select_pen(6) plotter.write(r) # take a looksee! io.view(plotter)
def main(): plotter = instantiate_virtual_plotter(Coordinate(0, 0), Coordinate(30000, 20000)) data_file = open("./media/indoor_temp.txt", 'r') data = data_file.readlines() print "read %d data points." % len(data) #make an empty list and fill it with data points as coordinates points = [] x = 0 for y in data: #we use rstrip() to remove the line break y_value = eval(y.rstrip()) * 100 #print "y_value: %f" % y_value c = Coordinate(x, y_value) points.append(c) x += 10 data_path = shapes.path(points) plotter.select_pen(4) plotter.write(data_path) #let's offset it and plot it again! offset(data_path, (1000, 1000)) plotter.select_pen(5) plotter.write(data_path) #let's draw a box around our offset plot (min, max) = data_path.minmax_coordinates (width, height) = max - min r = shapes.rectangle(width, height) #a rectangle has its center at (0,0) #so we shift it over so that its lower, left corner is (0,0) #and we shift it some more to fit around our offset data transforms.offset(r, (width/2, height/2)) transforms.offset(r, min) plotter.select_pen(6) plotter.write(r) #take a looksee! io.view(plotter)
def main(): print("Importing media/square.hpgl") f = import_hpgl_file("./media/square.hpgl") print( "Here are the contents of the file, expanded into a list of chiplotle objects:" ) print(f) print("\nAnd here are the raw hpgl commands:") for c in f: print(c.format) # We can use io.view() to take a look... io.view(f) # small delay to give our external postscript reader time to # load the output file time.sleep(1) # We can also send the commands to a plotter. # We'll use a virtual plotter in this example: plotter = instantiate_virtual_plotter() # Now we'll send the contents of the file to the plotter # so we can take a look. plotter.write(f) # And now we'll use io.view() to view what the virtual plotter has drawn. io.view(plotter) time.sleep(1) # We know from looking at the contents of the file above that the first thing # the hpgl code does is select pen 1. Let's change that to pen 2: print("\nbefore:") print(f[0]) f[0] = hpgl.SP(2) print("\nafter:") print(f[0]) # We'll clear the virtual plotter so that we can start a new drawing: plotter.clear() plotter.write(f) # now we should see the same plot with a different color io.view(plotter) time.sleep(1) # Now maybe I want to add a little somethingsomething: c = shapes.circle(1000) # insert the plotter into the list of commands at the position just before # the last pen up (PU;) command: f.insert(len(f) - 1, c) print("\nWe've inserted a circle (Path) into the list of commands:") print(f) plotter.clear() plotter.select_pen(3) plotter.write(f) io.view(plotter)
def main(): print 'Importing media/square.hpgl' f = import_hpgl_file("./media/square.hpgl") print "Here are the contents of the file, expanded into a list of chiplotle objects:" print f print "\nAnd here are the raw hpgl commands:" for c in f: print c.format # We can use io.view() to take a look... io.view(f) # small delay to give our external postscript reader time to # load the output file time.sleep(1) # We can also send the commands to a plotter. # We'll use a virtual plotter in this example: plotter = instantiate_virtual_plotter() # Now we'll send the contents of the file to the plotter # so we can take a look. plotter.write(f) # And now we'll use io.view() to view what the virtual plotter has drawn. io.view(plotter) time.sleep(1) # We know from looking at the contents of the file above that the first thing # the hpgl code does is select pen 1. Let's change that to pen 2: print "\nbefore:" print f[0] f[0] = hpgl.SP(2) print "\nafter:" print f[0] # We'll clear the virtual plotter so that we can start a new drawing: plotter.clear() plotter.write(f) # now we should see the same plot with a different color io.view(plotter) time.sleep(1) # Now maybe I want to add a little somethingsomething: c = shapes.circle(1000) # insert the plotter into the list of commands at the position just before # the last pen up (PU;) command: f.insert(len(f) - 1, c) print "\nWe've inserted a circle (Path) into the list of commands:" print f plotter.clear() plotter.select_pen(3) plotter.write(f) io.view(plotter)
#!/usr/bin/env python from chiplotle import * from chiplotle.tools.plottertools import instantiate_virtual_plotter """ Demonstrates the use of a virtual plotter with the generic plotter. Paper will automatically be set to 8.5x11" (ANSI A). You must have hp2xx installed for io.view() to work! """ plotter = instantiate_virtual_plotter() plotter.margins.soft.draw_outline() plotter.goto_center() plotter.select_pen(1) plotter.write(hpgl.CI(1000)) plotter.select_pen(2) plotter.write(hpgl.CI(500)) plotter.select_pen(3) plotter.write(hpgl.CI(250)) plotter.select_pen(4) plotter.write(hpgl.CI(125)) io.view(plotter)
You must have hp2xx installed for io.view() to work! ''' ''' compute size of paper: there are 40 plotter units per mm HP7550A reference lists 11x17 (ANSI B) max plot dimensions as: 254 x 411mm ''' paper_width = 411 * 40 paper_length = 254 * 40 plotter = instantiate_virtual_plotter(type="HP7550A", left_bottom = Coordinate(0,0), right_top = Coordinate(paper_width, paper_length) ) plotter.margins.soft.draw_outline() plotter.goto_center() plotter.select_pen(1) plotter.write(hpgl.CI(1000)) plotter.select_pen(2) plotter.write(hpgl.CI(500)) plotter.select_pen(3) plotter.write(hpgl.CI(250)) plotter.select_pen(4) plotter.write(hpgl.CI(125)) io.view(plotter)
Demonstrates the use of a virtual plotter with a specific plotter definition. You must have hp2xx installed for io.view() to work! ''' ''' compute size of paper: there are 40 plotter units per mm HP7550A reference lists 11x17 (ANSI B) max plot dimensions as: 254 x 411mm ''' paper_width = 411 * 40 paper_length = 254 * 40 plotter = instantiate_virtual_plotter(type="HP7550A", left_bottom=Coordinate(0, 0), right_top=Coordinate( paper_width, paper_length)) plotter.margins.soft.draw_outline() plotter.goto_center() plotter.select_pen(1) plotter.write(hpgl.CI(1000)) plotter.select_pen(2) plotter.write(hpgl.CI(500)) plotter.select_pen(3) plotter.write(hpgl.CI(250)) plotter.select_pen(4) plotter.write(hpgl.CI(125)) io.view(plotter)
:license: GNU Lesser General Public License, Version 3 (http://www.gnu.org/copyleft/lesser.html) """ from chiplotle import * from chiplotle.tools.plottertools import instantiate_virtual_plotter import math import random # select the first plotter configured in chiplotle #~ plotter = instantiate_plotters()[0] # real hardware plotter # hint: change to a virtual plotter, useful for testing and debug plotter = instantiate_virtual_plotter(type="HP7550A") # virtual plotter # global scaling values scx = 296 ; scy = 420 # (A3 size: 297 x 420) plotter.write(hpgl.SC([(-scx/2,scx/2),(-scy/2,scy/2)])) # pick up the first pen plotter.select_pen(1) # schotter setup w = 22 # width (how many squares - es. 22) h = 12 # height (how many squares - es. 12) s = 15 # square size (es. 15) rs = 0.015 # random step (rotation increment in degrees) dp = 2.25 # dampen (soften random effect for position)
from chiplotle import * from chiplotle.tools.plottertools import instantiate_virtual_plotter plotter = instantiate_virtual_plotter(type="DXY1300") plotter.margins.hard.draw_outline() plotter.select_pen(2) b = 0 import math def dotproduct(v1, v2): return sum((a*b) for a, b in zip(v1, v2)) def length(v): return math.sqrt(dotproduct(v, v)) def angle(v1, v2): return math.acos(dotproduct(v1, v2) / (length(v1) * length(v2))) dotproduct((2,2) , (1,1)) length((1,1)) import numpy as np def unit_vector(vector): """ Returns the unit vector of the vector. """ return vector / np.linalg.norm(vector) def angle_between(v1, v2): """ Returns the angle in radians between vectors 'v1' and 'v2':: >>> angle_between((1, 0, 0), (0, 1, 0))
#!/usr/bin/env python from chiplotle import * from chiplotle.tools.plottertools import instantiate_virtual_plotter ''' Demonstrates the use of a virtual plotter with the generic plotter. Paper will automatically be set to 8.5x11" (ANSI A). You must have hp2xx installed for io.view() to work! ''' plotter = instantiate_virtual_plotter() plotter.margins.soft.draw_outline() plotter.goto_center() plotter.select_pen(1) plotter.write(hpgl.CI(1000)) plotter.select_pen(2) plotter.write(hpgl.CI(500)) plotter.select_pen(3) plotter.write(hpgl.CI(250)) plotter.select_pen(4) plotter.write(hpgl.CI(125)) io.view(plotter)
def main(): plotter = instantiate_virtual_plotter(Coordinate(0, 0), Coordinate(30000, 20000)) width = plotter.margins.soft.width height = plotter.margins.soft.height left = plotter.margins.soft.left right = plotter.margins.soft.right bottom = plotter.margins.soft.bottom top = plotter.margins.soft.top print "width: %d height: %d" % (plotter.margins.soft.width, plotter.margins.soft.height) pens = raw_input("\nhow many pens do you want to use? ") numPens = int(pens) #start in a random spot plotter.goto(random.randint(left, right), random.randint(bottom, top)) penNum = 1 while True: plotter.select_pen(penNum) whichGesture = random.randint(0,5) if whichGesture == 0: print "circle!" #plotter.circle(random.randint(10,5000), random.randint(1,180)) plotter.write(hpgl.CI(random.randint(10,5000), random.randint(1,180))) elif whichGesture == 1: print "rect!" plotter.write(hpgl.ER((random.randint(10,5000), random.randint(10,5000)))) elif whichGesture == 2: print "filled rect!" ft = random.randint(1,8) if ft == 1 or ft == 2: ft = 1 if ft == 3 or ft == 4 or ft == 5: ft = 3 if ft == 6 or ft == 7 or ft == 8: ft = 4 space = random.randint(10,100) angle = random.randint(0,3) * 45 print "fill type: %d space: %d angle: %d" % (ft, space, angle) #plotter.fill_type(ft, space, angle) #plotter.filled_rectangle_relative(random.randint(10,2000), random.randint(10,2000)) plotter.write(hpgl.RR((random.randint(10, 2000), random.randint(10, 2000)))) plotter.write(hpgl.FT(ft, space, angle)) elif whichGesture == 3: print "draw a crazy line!" plotter.pen_down() plotter.goto(random.randint(left, right), random.randint(bottom, top)) plotter.pen_up() elif whichGesture == 4: print "draw an abstract shape!" numPoints = random.randint(2,4) print "numPoints: ", numPoints firstX = random.randint(left, right) firstY = random.randint(bottom, top) plotter.goto(firstX, firstY) plotter.pen_down() xRange = width/5 yRange = height/5 for i in range(numPoints): plotter.nudge(random.randint(int(-xRange), int(xRange)), random.randint(int(-yRange), int(yRange))) plotter.goto(firstX, firstY) plotter.pen_up() elif whichGesture == 5: print "just jump around!" plotter.goto(random.randint(left, right), random.randint(bottom, top)) #pick a new pen? pickPen = random.randint(0,99) if pickPen < 25: penNum += 1 if penNum == numPens + 1: break plotter.select_pen(0) io.view(plotter)
def main(): plotter = instantiate_virtual_plotter(Coordinate(0, 0), Coordinate(30000, 20000)) width = plotter.margins.soft.width height = plotter.margins.soft.height left = plotter.margins.soft.left right = plotter.margins.soft.right bottom = plotter.margins.soft.bottom top = plotter.margins.soft.top print "width: %d height: %d" % (plotter.margins.soft.width, plotter.margins.soft.height) pens = raw_input("\nhow many pens do you want to use? ") numPens = int(pens) # start in a random spot plotter.goto(random.randint(left, right), random.randint(bottom, top)) penNum = 1 while True: plotter.select_pen(penNum) whichGesture = random.randint(0, 5) if whichGesture == 0: print "circle!" # plotter.circle(random.randint(10,5000), random.randint(1,180)) plotter.write(hpgl.CI(random.randint(10, 5000), random.randint(1, 180))) elif whichGesture == 1: print "rect!" plotter.write(hpgl.ER((random.randint(10, 5000), random.randint(10, 5000)))) elif whichGesture == 2: print "filled rect!" ft = random.randint(1, 8) if ft == 1 or ft == 2: ft = 1 if ft == 3 or ft == 4 or ft == 5: ft = 3 if ft == 6 or ft == 7 or ft == 8: ft = 4 space = random.randint(10, 100) angle = random.randint(0, 3) * 45 print "fill type: %d space: %d angle: %d" % (ft, space, angle) # plotter.fill_type(ft, space, angle) # plotter.filled_rectangle_relative(random.randint(10,2000), random.randint(10,2000)) plotter.write(hpgl.RR((random.randint(10, 2000), random.randint(10, 2000)))) plotter.write(hpgl.FT(ft, space, angle)) elif whichGesture == 3: print "draw a crazy line!" plotter.pen_down() plotter.goto(random.randint(left, right), random.randint(bottom, top)) plotter.pen_up() elif whichGesture == 4: print "draw an abstract shape!" numPoints = random.randint(2, 4) print "numPoints: ", numPoints firstX = random.randint(left, right) firstY = random.randint(bottom, top) plotter.goto(firstX, firstY) plotter.pen_down() xRange = width / 5 yRange = height / 5 for i in range(numPoints): plotter.nudge(random.randint(int(-xRange), int(xRange)), random.randint(int(-yRange), int(yRange))) plotter.goto(firstX, firstY) plotter.pen_up() elif whichGesture == 5: print "just jump around!" plotter.goto(random.randint(left, right), random.randint(bottom, top)) # pick a new pen? pickPen = random.randint(0, 99) if pickPen < 25: penNum += 1 if penNum == numPens + 1: break plotter.select_pen(0) io.view(plotter)