def to_dc_svg(self,f_name="svg_out", path = os.path.expanduser("~"), color_dict = {0:Color(0.0),1:Color(1.0)}, cdim=Interval(500,500), draw_recs=True,draw_nodes=False,draw_link=False): # this uses Decodes. OK for nodes and link, slow for cells. svg_out = dc.makeOut(dc.Outies.SVG, f_name, path, canvas_dimensions=cdim, flip_y = False) lines = [] pts = [] pts2 = [] # total list, includes empty nodes - use for line list recs = [] coord = self.pts for i in range(len(self.pts)): p = self.pts[i] r = PGon.rectangle(p, self.cell[i][0], self.cell[i][1]) val = self.val[i] r.set_color(color_dict[val[0]][int(val[2])]) recs.append(r) print "putting rectangles, ", if draw_recs : svg_out.put(recs) print "edges, ", if draw_link : svg_out.put(lines) print "nodes" if draw_nodes : svg_out.put(pts) print "drawing tp file ", svg_out.draw() print "done"
dist = random.uniform(1,size) pts.append(CylCS().eval(dist, r_ints[i].b)) return pts # initialize parameters print rand_points(10,100) sheet_size = Interval(240,240) no_rects = 40 no_sheets = 1 shapes = [] for i in range(no_rects): shapes.append(PGon(rand_points(random.randint(3,10),random.randint(1,min(sheet_size.a,sheet_size.b)/3)))) new_list = bin_polygons(shapes,sheet_size, 'w', reverse_list = True) #for n,i in enumerate(new_list): # print 'item ',n,' : = ',i.pts outie = dc.makeOut(dc.Outies.SVG, f_prefix, canvas_dimensions=Interval(no_sheets * sheet_size.a,sheet_size.b), flip_y = True) scale = 1 for x in new_list: outie.put(x) outie.draw() raw_input("press enter...")
import decodes as dc from decodes.core import * from decodes.io import * from decodes.io.pyautocad import * acad = Autocad(False, True) outie = dc.makeOut(dc.Outies.ACAD, "wayout") pt = Point(0, 10) # Testing points pts = [Point(i, i) for i in range(10)] # Testing Segments segs = [Segment(pt, Point(5, 0)) for pt in pts] # Testing Rays rays = [Ray(pt, Point(i + 1, 0)) for i, pt in enumerate(pts)] # Testing Line line = Line(pt, Point()) # Testing Vecs vecs = [Vec(i, 5, 0) for i in range(10)] # Testing PLine plines = [PLine([pt, Point(15, 1, 0), Point(20, 1, 0)]) for pt in pts] # Testing PGon pgon = PGon([pt, Point(0, 5, 0), Point(-3, 15, 0)]) # Testing Meshes mesh4 = Mesh( [Point(), Point(-5, 0, 0), Point(0, -5, 0), Point(-5, -5, 0)], [[0, 1, 2, 3]]) mesh3 = Mesh([Point(), Point(-5, 0, 0), Point(0, -5, 0)], [[0, 1, 2]]) mesh3.set_color(1, 0.5, 0.5)
import decodes as dc from decodes.core import * from decodes.io import * from decodes.io.pyautocad import * acad = Autocad(False, True) outie = dc.makeOut(dc.Outies.ACAD, "wayout") pt = Point(0,10) # Testing points pts = [Point(i, i) for i in range(10)] # Testing Segments segs = [Segment(pt, Point(5,0)) for pt in pts] # Testing Rays rays = [Ray(pt, Point(i+1,0)) for i,pt in enumerate(pts)] # Testing Line line = Line(pt, Point()) # Testing Vecs vecs = [Vec(i,5,0) for i in range(10)] # Testing PLine plines = [PLine([pt,Point(15,1,0),Point(20,1,0)]) for pt in pts] # Testing PGon pgon = PGon([pt,Point(0,5,0),Point(-3,15,0)]) # Testing Meshes mesh4 = Mesh([Point(),Point(-5,0,0),Point(0,-5,0),Point(-5,-5,0)], [[0,1,2,3]]) mesh3 = Mesh([Point(),Point(-5,0,0),Point(0,-5,0)], [[0,1,2]]) mesh3.set_color(1,0.5,0.5) mesh3.set_weight(3) # Testing Curves
for i in range(1,len(e)): flag = True for t in r: if is_same(e[i],t): r.remove(t) flag = False break if flag : r.append(Segment(e[i].spt, e[i].ept)) print outie = dc.makeOut(dc.Outies.SVG, "svg_out", canvas_dimensions=Interval(1000,500), flip_y = True) scale = 50 for x in r: x.set_color(Color(1,1,0)) x.set_weight(1) outie.put(x) outie.draw() raw_input("Hit any key...")
sheet_size = Interval(240,240) no_rects = 40 no_sheets = 1 # create list of random shapes shapes = [] for i in range(no_rects): shapes.append(PGon(packing.rand_points(random.randint(3,10),random.randint(1,min(sheet_size.a,sheet_size.b)/3)))) # sort, bin and extract the polygons print "sorting..." shapes_sorted = packing.sort_polygons(shapes, 'a', reverse_list = True) print "packing..." sheets_filled = packing.bin_polygons(shapes_sorted, sheet_size) print "extracting..." shapes_packed = packing.extract_polygons(sheets_filled) no_sheets = len(sheets_filled) # send the geometry to an outie outie = dc.makeOut(dc.Outies.SVG, f_prefix, canvas_dimensions=Interval(no_sheets * sheet_size.a,sheet_size.b), flip_y = True) for x in shapes_packed: outie.put(x) outie.draw() raw_input("press enter...")
import decodes as dc from decodes.core import * from decodes.core import PGon p = [] xmax = 500 ymax = 500 r = dc.core.PGon.rectangle(Point(xmax/2,ymax/2),xmax,ymax) for n in range(1): outie = dc.makeOut(dc.Outies.SVG, "svg_"+'%03d'%n, canvas_dimensions=Interval(xmax,ymax), flip_y = True) p.append(outie) scale = 50 print "putting ...", p[n].put(r) print "done" for x in range(10): for y in range(10): pt = Point(x*scale,y*scale) pt.set_color(Color(1,0,0)) pt.set_weight(2*y+1.5) p[n].put(pt) print "drawing ...", p[n].draw() print "done" ''' def func(t): return Point(t*scale,math.sin(t)*scale) crv = Curve(func,Interval(0,math.pi*2))
def sheldon_packing(width, shape): result = [] cut = sheldon_cut(w,shape) if cut: # returns True if cuttable result.append(cut[0]) result.append(sheldon_packing(width, cut[1])) else: result.append(shape) return result pts = packing.rand_points(4,size) for i in range(4): pts[i] = pts[i] + Vec(i_size.a/2.0,i_size.b/2.0) shape = PGon(pts) shape.set_color(Color(0.0)) # send the geometry to an outie outie = dc.makeOut(dc.Outies.SVG, f_prefix, canvas_dimensions=i_size, flip_y = True) ''' for x in strips_packed: outie.put(x) ''' outie.put(shape) outie.draw() raw_input("press enter...")
import decodes as dc from decodes.core import * from decodes.core import PGon p = [] xmax = 500 ymax = 500 r = dc.core.PGon.rectangle(Point(xmax / 2, ymax / 2), xmax, ymax) for n in range(1): outie = dc.makeOut(dc.Outies.SVG, "svg_" + '%03d' % n, canvas_dimensions=Interval(xmax, ymax), flip_y=True) p.append(outie) scale = 50 print "putting ...", p[n].put(r) print "done" for x in range(10): for y in range(10): pt = Point(x * scale, y * scale) pt.set_color(Color(1, 0, 0)) pt.set_weight(2 * y + 1.5) p[n].put(pt) print "drawing ...", p[n].draw() print "done" ''' def func(t):
stock_size = Interval(0,300) height = stock_size.b/10.0 no_lengths = 40 no_strips = 1 # create list of random shapes strips = [] for i in range(no_lengths): strips.append(random.randint(height,stock_size.b/2.0)) # sort, bin and extract the polygons print "sorting..." strips.sort(reverse=True) print "packing..." stock_filled = packing.bin_strips(strips, stock_size) print "extracting..." strips_packed = packing.extract_strips(stock_filled, height = height) no_stock = len(stock_filled) # send the geometry to an outie outie = dc.makeOut(dc.Outies.SVG, f_prefix, canvas_dimensions=Interval(stock_size.b,no_stock*height), flip_y = True) for x in strips_packed: outie.put(x) outie.draw() raw_input("press enter...")
if cut: # returns True if cuttable result.append(cut[0]) result.append(sheldon_packing(width, cut[1])) else: result.append(shape) return result pts = packing.rand_points(4, size) for i in range(4): pts[i] = pts[i] + Vec(i_size.a / 2.0, i_size.b / 2.0) shape = PGon(pts) shape.set_color(Color(0.0)) # send the geometry to an outie outie = dc.makeOut(dc.Outies.SVG, f_prefix, canvas_dimensions=i_size, flip_y=True) ''' for x in strips_packed: outie.put(x) ''' outie.put(shape) outie.draw() raw_input("press enter...")
no_strips = 1 # create list of random shapes strips = [] for i in range(no_lengths): strips.append(random.randint(height, stock_size.b / 2.0)) # sort, bin and extract the polygons print "sorting..." strips.sort(reverse=True) print "packing..." stock_filled = packing.bin_strips(strips, stock_size) print "extracting..." strips_packed = packing.extract_strips(stock_filled, height=height) no_stock = len(stock_filled) # send the geometry to an outie outie = dc.makeOut(dc.Outies.SVG, f_prefix, canvas_dimensions=Interval(stock_size.b, no_stock * height), flip_y=True) for x in strips_packed: outie.put(x) outie.draw() raw_input("press enter...")