def __init__(self): pg.init() pg.font.init() pg.display.set_caption("TETRIS") self.sound_manager = SoundManager() pg.mixer.music.load("Sounds/Music.mp3") pg.mixer.music.set_volume(0.3) pg.mixer.music.play(-1) self.main_surface = pg.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) self.playground_surf = pg.Surface( (GRID_SIZE[0] * CELL_SIZE * UI_SCALE, GRID_SIZE[1] * CELL_SIZE * UI_SCALE)) self.next_surf = pg.Surface((220 * UI_SCALE, 220 * UI_SCALE)) self.font = pg.font.Font("Fonts/ARCADECLASSIC.TTF", int(FONT_SIZE * UI_SCALE)) if "top.scr" in os.listdir(): with open("top.scr") as file: self.top = int(file.read()) else: self.top = 0 self.score = 0 self.lines = 0 self.colors = np.zeros(GRID_SIZE, dtype=object) self.grid_colliders = np.zeros(GRID_SIZE) self.cur_shape = Shape(self, 5, -1) self.next_shape = Shape(self, 5, -1) self.game_over = False
def test_check_NoShape_x_y(self): shape = Shape() for i in range(5): self.assertEqual(shape.coordsTable[Pentominoes.NoShape][i][0], shape.x(i)) self.assertEqual(shape.coordsTable[Pentominoes.NoShape][i][1], shape.y(i))
def __init__(self, start_x, start_y, radius): Shape.__init__(self, start_x, start_y, "circle") if self.check_bounds(radius): self.setRadius(radius) else: raise OutOfBoundShapeError
def __init__(self, perimeterCoordinates, pic): # list of x,y coordinates which make up the outline of a blob # self.ignore = perimeterCoordinates < 4 self.center = (-1, -1) self.orientation = -1 self.blobCoordinates = [] perimeterCoordinates = sorted(perimeterCoordinates, key=itemgetter(1)) self.perimeter = np.array(perimeterCoordinates) for i in range(len(self.perimeter)): self.perimeter[i][0], self.perimeter[i][1] = self.perimeter[i][ 1], self.perimeter[i][0] Shape.__init__(self, self.perimeter, pic) #print(perimeterCoordinates) alreadyProcessedRow = [] for i in range(len(perimeterCoordinates)): y = perimeterCoordinates[i][1] if (y in alreadyProcessedRow) == False: xmax = perimeterCoordinates[i][0] xmin = perimeterCoordinates[i][0] alreadyProcessedRow.append(y) j = i while (perimeterCoordinates[j][1] == y): if perimeterCoordinates[j][0] < xmin: xmin = perimeterCoordinates[j][0] if perimeterCoordinates[j][0] > xmax: xmax = perimeterCoordinates[j][0] j = j + 1 if j == len(perimeterCoordinates): break for a in range(xmin, xmax): self.blobCoordinates.append([a, y])
def test_shape(self): shape = Shape((0, 0, 0), 'wood') self.assertEqual('Color: (0, 0, 0) Material : wood Max_Temp: 20', str(shape)) shape2 = Shape((0, 0, 0), 'wood') self.assertEqual(shape, shape2) shape3 = Shape((0, 23, 0), 'woodds') self.assertNotEqual(shape, shape3)
def __init__(self, init_x_1, init_y_1, init_x_2, init_y_2, init_x_3, init_y_3): Shape.__init__(self, init_x_1, init_y_1, "triangle") if self.check_bounds(init_x_1, init_y_1, init_x_2, init_y_2, init_x_3, init_y_3): self.setPoints(init_x_1, init_y_1, init_x_2, init_y_2, init_x_3, init_y_3) else: raise OutOfBoundShapeError
def subdivide(self, subdivisionLevel): nodes = [] for originalNode in self.originalNodes: node = Shape(originalNode.name) # start from level 2 since level 1 subdivision is equal to object itself. for i in range(subdivisionLevel - 1): node.subdivide() nodes.append(node) self.nodes = nodes
def shapeAndStoreIfBetter(temp, shapes): embedTree(temp) shape = Shape(temp) if not shape.type in shapes or shapes[shape.type].better(shape): newTree = copy.copy(temp) newTree.children = copy.copy(temp.children) shape.tree = newTree shapes[shape.type] = shape
def new_piece(self): self.current_piece = self.next_piece self.next_piece = Shape() self.next_piece.set_random_shape() self.cur_x = self.width // 2 + 1 self.cur_y = self.height - 1 + self.current_piece.min_y() if not self.try_move(self.current_piece, self.cur_x, self.cur_y): self.current_piece.set_shape(Pentominoes.NoShape) self.is_over = True
def restart(self): pg.mixer.music.rewind() self.score = 0 self.lines = 0 self.colors = np.zeros(GRID_SIZE, dtype=object) self.grid_colliders = np.zeros(GRID_SIZE) self.cur_shape = Shape(self, 5, -1) self.next_shape = Shape(self, 5, -1) self.game_over = False
def parse(fileName): """ Use this parser to enable subidivision properly """ # returns shape object shape = Shape() objFile = open(fileName) for line in objFile: splitedLine = line.split() if (len(splitedLine) != 0 and splitedLine[0] != '#'): definition = splitedLine[0] if (definition == 'o'): shape.setShapeName(splitedLine[1]) elif (definition == 'v'): shape.addVertice(float(splitedLine[1]), float(splitedLine[2]), float(splitedLine[3])) elif (definition == 'f'): face = [] for i in splitedLine[1:]: face.append(int(i) - 1) shape.addFace(face) return shape
def alignmentMark(wid=50): toReturn = Shape([]) w = wid/2. x = wid/12. pline = Polyline([Vector(w, x), Vector(w, 2.5*x), Vector(2.5*x, 2.5*x), Vector(2.5*x, w), Vector(x, w), Vector(x,x)]) m = Matrix(0, 1, -1, 0); for i in range(0, 4): toReturn.add(pline); pline *= m return toReturn
def __init__(self, name, conf, props, globdat): self.name = name myConf = conf.makeProps(name) myProps = props.getProps(name) self.type = myProps.get("type", "Periodic") self.strain = myProps.find("strainRate", None) self.factor = myProps.get("coarsenFactor", 1.0) self.numTNode = myProps.get("numTNode", 10) myConf.set("type", self.type) myConf.set("strainRate", self.strain) myConf.set("coarsenFactor", self.factor) myConf.set("numTNode", 10) mesh = globdat.get("mesh") self.rank = mesh.rank #----------------------------------------------------------------------- # initialize #----------------------------------------------------------------------- # Add displacement doftypes types = ['u', 'v', 'w'] self.udofTypes = [types[x] for x in range(self.rank)] mesh.addTypes(self.udofTypes) # Add traction doftypes types = ['tx', 'ty', 'tz'] self.tdofTypes = [types[x] for x in range(self.rank)] mesh.addTypes(self.tdofTypes) # Get specimen dimensions self.__boundingBox(mesh) self.__setTolerances() # Get boundary nodes self.__findBndNodes(mesh) self.__sortBndNodes(mesh) # Find corner nodes self.__findCornerNodes() # Create boundary element self.bshape = Shape.shapeFactory(myConf, myProps) self.ipCount = self.bshape.nIP self.tnodeCount = self.bshape.nnod self.tdofCount = self.tnodeCount * self.rank self.localrank = self.bshape.ndim if self.localrank != self.rank - 1: msg = "Shape ndim = {}. Should be {}".format( self.localrank, self.rank - 1) raise ValueError(msg) # Create traction mesh self.tnodes = NodeSet() self.__findSmallestElement(mesh) self.__createTractionMesh2(mesh)
def starkChip(wire=10): boxdim = 200 padsize = 100 # membrane(boxdim).plot() toReturn = Shape([]); dev = dev2D() box = rect(Vector(0,0), Vector(1,1)) for x in range(0, 4): for y in range(0,4): text = (font.shapeFromStringBoundedCentered(str(x+1) + str(y+1), -1, 7*5) + Vector(-85, 0)).setMaterial(3) text2 = (font.shapeFromStringBoundedCentered(str(x+1) + str(y+1), -1, 5) + Vector(-35, 0)).setMaterial(1) toReturn.add(dev + Vector(x-1.5, y-1.5)*boxdim*2); toReturn.add(text + Vector(x-1.5, y-1.5)*boxdim*2); toReturn.add(text2 + Vector(x-1.5, y-1.5)*boxdim*2 + Vector(0, 10)); #toReturn.add(text2 + Vector(x-1.5, y-1.5)*boxdim*2 + Vector(0, -10)); for xx in range(0,4): for yy in range(0,4): if not (xx == x and yy == y): toReturn.add(box + Vector(2*(xx-2)-35+.5, 2*(yy-2)-10+.5) + Vector(x-1.5, y-1.5)*boxdim*2); # for x in range(0, 4): # toReturn.add(rect(Vector(0,0), Vector(padsize, padsize)) + Vector((x-2)*boxdim*2 + 40, boxdim*2*2)); # toReturn.add(rect(Vector(0,0), Vector(padsize, padsize)) + Vector((x-1)*boxdim*2 - padsize, boxdim*2*2)); return toReturn
def example_device(g1, g2, string): toReturn = Shape([]); toReturn.add(gratingMike(g1)) toReturn.add(gratingMike(g2)) toReturn.add(connectAndThicken(g1, g2, "MONOCIRCULAR")) toReturn.add(font.shapeFromStringBoundedCentered(string, w=0, h=2) + Vector(10,10)) return toReturn
def membrane(boxdim=200, viawid=16, boxnum=7, viagap=75): toReturn = Shape([]); box = rect(Vector(-.5,-.5)*boxdim, Vector(.5,.5)*boxdim) line = Polyline([Vector(-(boxdim - viagap)/2., boxdim/2.), Vector((boxdim - viagap)/2., boxdim/2.)]); via = thickenPolyline(line, "LINEAR", viawid/2., "SHARP", "ROUND") box = box.intersect(via); box = box.intersect(via*Matrix(math.pi/2)); box = box.intersect(via*Matrix(math.pi)); box = box.intersect(via*Matrix(3*math.pi/2)); #edge = box.intersect(rect(Vector(-boxdim, -boxdim/2.+viagap), Vector(boxdim, boxdim))) #r = rect(Vector(-boxdim, -boxdim/2.+viagap), Vector(boxdim, boxdim)) #edge = box.intersect(r) for x in range(0, boxnum+2): for y in range(0, boxnum+2): if x == 0 and y == 0: 0 elif x == boxnum+1 and y == 0: 0 elif x == 0 and y == boxnum+1: 0 elif x == boxnum+1 and y == boxnum+1: 0 elif x == 0: 0 #toReturn.add(edge + Vector(x,y)*boxdim) elif x == boxnum+1: 0 #toReturn.add(edge + Vector(x,y)*boxdim) elif y == 0: 0 #toReturn.add(edge + Vector(x,y)*boxdim) elif y == boxnum+1: 0 #toReturn.add(edge + Vector(x,y)*boxdim) else: toReturn.add(box + Vector(x, y)*boxdim) #toReturn.setMaterial(4).plot() return (toReturn + Vector(-boxdim*(boxnum+1)/2., -boxdim*(boxnum+1)/2.)).setMaterial(4)
def __init__(self, name, conf, props, globdat): self.name = name myConf = conf.makeProps(name) myProps = props.getProps(name) self.type = myProps.get("type", "Solid") self.group = myProps.get("elements", "All") myConf.set("type", self.type) myConf.set("elements", self.group) mesh = globdat.get("mesh") self.rank = mesh.rank if self.group != "All": key = int(re.search(r'\d+', self.group).group()) group_name = mesh.groupNames[key] logging.debug(" Obtaining elements from {}".format(group_name)) idx = mesh.groupNames.keys().index(key) self.ielements = mesh.groups[idx] logging.debug(" Elements in mesh.groups[{}]".format(idx)) else: group_name = next(iter(mesh.groupNames.values())) self.ielements = mesh.groups[0] logging.debug(" Obtaining elements from {}".format(group_name)) #----------------------------------------------------------------------- # initialize #----------------------------------------------------------------------- # Add types types = ['u', 'v', 'w'] self.types = [types[x] for x in range(self.rank)] mesh.addTypes(self.types) # Add dofs self.inodes = mesh.getNodeIndices(self.ielements) mesh.addDofs(self.inodes, self.types) # Add thickness (2D) if self.rank == 2: self.t = myProps.get("thickness", 1.0) myConf.set("thickness", self.t) # Create element self.shape = Shape.shapeFactory(myConf, myProps) localrank = self.shape.ndim if localrank != self.rank: msg = "Shape ndim = {}. Should be {}".format(localrank, self.rank) raise ValueError(msg) # Create material self.mat = Material.materialFactory(myConf, myProps)
def main(argv): parser = argparse.ArgumentParser( description="Generate a cuboid dataset" ) parser.add_argument( "output_directory", help="Save the dataset in this directory" ) parser.add_argument( "--n_samples", type=int, default=10, help="Number of training samples to be generated" ) parser.add_argument( "--max_n_shapes_per_samples", type=int, default=4, help="Number of shapes per sample" ) args = parser.parse_args(argv) # Check if output directory exists and if it doesn't create it if not os.path.exists(args.output_directory): os.makedirs(args.output_directory) # Create a directory based on the type of the shapes inside the output # directory output_directory = os.path.join( args.output_directory, "spheres_dataset" ) print "Saving models to %s" % (output_directory,) prog = Progbar(args.n_samples) for i in range(args.n_samples): prims = build_sequentially_attaching_sheres( np.random.choice(np.arange(2, args.max_n_shapes_per_samples)) ) c = Shape.from_shapes(prims) # Create subdirectory to save the sample base_dir = os.path.join(output_directory, "%05d" % (i,), "models") if not os.path.exists(base_dir): os.makedirs(base_dir) # print base_dir # Save as obj file c.save_as_mesh(os.path.join(base_dir, "model_normalized.obj"), "obj") c.save_as_mesh(os.path.join(base_dir, "model_normalized.ply"), "ply") c.save_as_pointcloud( os.path.join(base_dir, "model_normalized_pcl.obj"), "obj" ) prog.update(i + 1)
def parse(file_path): if not exists(file_path): raise FileNotFoundError(f"No such file or directory: {file_path}") if not isfile(file_path): raise ValueError(f"{file_path} is not a file") _, extension = splitext(file_path) if extension != ".obj": raise ValueError(f"Expected .obj file but get {extension} file") name = None vertices = [] faces = [] groups = {} current_group = [] groups["default"] = current_group with open(file_path, "r") as file: for line in file: if line.startswith("o"): name = line elif line.startswith("g"): values = line.split() group_name = values[1] if group_name not in groups: current_group = [] # Create new group groups[ group_name] = current_group # Save group to groups else: current_group = groups[group_name] elif line.startswith("v"): # current_group["vertices"].append(create_point(line)) vertices.append(create_point(line)) elif line.startswith("f"): current_group.append(create_face(line)) # faces.append(create_face(line)) # return name, vertices, faces shapes = [] for group in groups: if len(groups[group]) is not 0: mesh = Mesh(vertices.copy(), groups[group]) min_index = min(mesh.indexes) max_index = max(mesh.indexes) mesh.positions = mesh.positions[min_index:max_index + 1] for face in mesh.faces: face.indexes = list( map(lambda x: x - min_index, face.indexes)) mesh.invalidate_indexes() shapes.append(Shape(group, mesh)) return shapes
def shapeFromString(self, string): toReturn = Shape([],[]) # dv = Vector(1. + self.linegap/self.width,0) v = Vector(0,0) w = Vector(0,0) for char in string: # plt.plot([v.x, v.x, v.x + wid, v.x + wid, v.x], [v.y, v.y + hgt, v.y + hgt, v.y, v.y]) # toReturn.polylines.extend( [(letter + v - Vector(shift, 0))] ) if char != '\n': letter = self[char] bb = letter.getBoundingBox() if bb != None: wid = bb[1].x - bb[0].x hgt = bb[1].y - bb[0].y shift = bb[0].x else: wid = 1 hgt = 1 shift = 0 for polyline in letter.polylines: toReturn.polylines.extend( [(polyline + v - Vector(shift, 0))] ) # polyline = self[char] # (polyline + v).plot() v += Vector(wid + .2, 0) else: v = Vector(0,v.y-hgt - .6) # # polyline = font2[char] # (polyline + w).plot() # w += dv toReturn.sizeCalc() return toReturn
def __init__(self, width, height, board=None, score=0): self.width = width self.height = height self.speed = 500 self.is_over = False self.is_paused = False self.next_piece = Shape() self.current_piece = Shape() self.shapes_on_lath = set() self.next_piece.set_random_shape() self.score = score self.removed_l = 0 self.added_points = 1 self.n_lines_to_up_lvl = 2 self.cur_x = 0 self.cur_y = 0 if board is None: self.board = [] else: self.board = board self.clear_board()
def __init__(self, x, y, radius, degree=150, scanning_max=360, scanning_min=0, scanning_mode="CIRCLE", origin="PERIMETER"): #TODO origin = CENTER is broken for rebroadcasting self.uuid = str(uuid.uuid4()) self.x = x self.y = y self.radius = radius # for drawing self.colorDict = dict() self.lastColor = colour.Color("Blue") self.shape = Shape(center=(self.x, self.y)) self.circle = Circle(self.radius * 2) # end drawing section self.rays = [] self.vertex_list = None r_b = [ color for color in colour.Color("Red").range_to( colour.Color("Green"), 120) ] b_g = [ color for color in colour.Color("Green").range_to( colour.Color("Blue"), 120) ] g_r = [ color for color in colour.Color("Blue").range_to( colour.Color("Red"), 120) ] self.colors = r_b + b_g + g_r self.energy = 0 self.energy_color = None self.scanning_max = scanning_max self.scanning_min = scanning_min if degree > self.scanning_max: degree = self.scanning_max elif degree < self.scanning_min: degree = self.scanning_min self.degree = degree self.scanning_mode = scanning_mode #self.scanning_mode_options = ["CIRCLE", "RANDOM"] self.origin = origin
def largeArray(n=8, d=10, wid=.27, kinds=["LINEAR", "QBEZIER", "CBEZIER", "CIRCULAR", "MONOCIRCULAR"]): font = TTF("/Users/I/Desktop/diamondGDS/fonts/VeraMono.ttf") # font = TTF("/Users/I/Desktop/diamondGDS/fonts/courier-bold.ttf") toReturn = Shape([]) v = Vector(0,0) dv = Vector(n*d*2) basedir = Vector(0,1) c0 = Connection(v.copy(), -basedir.copy(), wid) c1 = Connection(v.copy(), basedir.copy(), wid) # c0.dir = basedir # # c0.wid = wid # c1.wid = wid # for kind in kinds: for i in range(0,n+1): c1.v = basedir.rotate(i*math.pi/n)*(d) for j in range(0,2*n): print "\n0x" + ("%X" % i) + ("%X" % j) c1.dir = basedir.rotate(j*math.pi/n) # print c0, c1 # (c0 + Vector(d*i*1.5, d*j*1.5) + v).plot() # (c1 + Vector(d*i*1.5, d*j*1.5) + v).plot() polyline = connectAndThicken(c0, c1, kind) if isinstance(polyline, Polyline): toReturn.add(polyline + (Vector(d*i*1.5, d*j*1.5) + v)) toReturn.add(font.shapeFromStringBoundedCentered(("%X" % i) + ("%X" % j), w=0, h=2) + (Vector(d*i*1.5, d*j*1.5) + v + Vector(3,3))) toReturn.add(font.shapeFromStringBoundedCentered(kind, w=0, h=10) + (Vector(d*n*.75, -25) + v)) v += dv return toReturn
def draw_drag(self, final_x, final_y): start_x, start_y = self.drag_begin[0], self.drag_begin[1] color = self.color_pallette[self.color_selection] l, t = min(start_x, final_x) - self.canvas_area_bounds[0], self.height - min( start_y, final_y) r, b = max(start_x, final_x) - self.canvas_area_bounds[0], self.height - max( start_y, final_y) shape_types = ['Rectangle', 'Ellipse'] new_shape = Shape(l, t, r, b, shape_types[self.shape_selection], color=self.color_pallette[self.color_selection]) # print(new_shape) self.shape_col.shapes.append(new_shape) self.color_selection = (self.color_selection + 1) % len( self.color_pallette)
def register(): ghost = [ (-7, -7), # 0 (-7.0, 0.0), # 1 (-5, -5), # 22 (-6.7, 2.0), # 2 (-3, -7), # 21 (-5.9, 3.8), # 3 (-1, -7), # 20 (-4.6, 5.3), # 4 (-1, -5), # 19 (-2.9, 6.4), # 5 (1, -5), # 18 (-1.0, 6.9), # 6 (3, -7), # 16 (1.0, 6.9), # 7 (5, -5), # 15 (2.9, 6.4), # 8 (7, -7), # 14 (4.6, 5.3), # 9 (7.0, 0.0), # 13 (4.6, 5.3), # 10 (6.7, 2.0), # 12 (5.9, 3.8), # 11 ] s = Shape([ Primitive(ghost, Color.black).offset(+200, +105), Primitive(ghost, Color.orange).offset(+300, +200), Rect(100, 100, 120, 200, Color.red).offset(100, 200), Rect(100, 100, 120, 200, Color.red).rotate(10).offset(200, 600) ]) g = Actor() g.shape = s g.tick = tick # TODO : prevent identical name conflict # TODO : retiurn many return ([g])
def test(): n0 = Node(0, 6, []) n1 = Node(1, 8, []) n2 = Node(2, 4, [n0, n1]) n3 = Node(3, 8, []) n4 = Node(4, 10, []) n5 = Node(5, 6, [n3, n4]) n6 = Node(6, 12, []) n7 = Node(7, 2, [n2, n5, n6]) n8 = Node(8, 4, []) n9 = Node(9, 6, []) n10 = Node(10, 2, [n8, n9]) n11 = Node(11, 0, [n7, n10]) n11.fillStats() tree = heuristics.nodesToLeaf(n11) width = embedTree(tree) print("Width: " + str(width)) print("White: " + str(tree.stats.whitespace)) bottomRect, topRect = approximateWithTwoRects(tree.stats.leftBorder, tree.stats.rightBorder) print("BottomRect: " + str(bottomRect)) print("TopRect: " + str(topRect)) s = Shape(bottomRect, topRect, tree) print(str(s.type)) tree.printMe(0) #tree.printMe(0, lambda n : str((n.dNode, str(n))) ) #tree.printMe(0, lambda n : str((n.dNode, str(n.stats))) ) save_img(tree, "test")
def tetrisOrder(node): def shapeAndStoreIfBetter(temp, shapes): embedTree(temp) shape = Shape(temp) if not shape.type in shapes or shapes[shape.type].better(shape): newTree = copy.copy(temp) newTree.children = copy.copy(temp.children) shape.tree = newTree shapes[shape.type] = shape if node.isLeaf(): shape = Shape(node) node.shapes = {shape.type: shape} if DO_PRINT: print("Shapes of node: " + str(node)) for t, s in node.shapes.items(): print(t) s.tree.printMe(1) print("--------------------") return if len(node.children) > 2: print("SKIPPING TETRIS: More than 2 children.. " + str(len(node.children)) + " is too many") return for c in node.children: tetrisOrder(c) shapes = {} if len(node.children) == 1: childShapes = node.children[0].shapes node.children[0].shapes = None #Don't want to copy tempNode = copy.copy(node) for type, subShape in childShapes.items(): tempNode.children = [subShape.tree] #switch to shapes subtree shapeAndStoreIfBetter(tempNode, shapes) else: tempNode = copy.copy(node) leftShapes = node.children[0].shapes node.children[0].shapes = None #Don't want to copy rightShapes = node.children[1].shapes node.children[1].shapes = None #Don't want to copy for leftType, leftShape in leftShapes.items(): #flippedLeft = copy.deepcopy(leftShape.tree) #flip(flippedLeft) for rightType, rightShape in rightShapes.items(): #Left-Right tempNode.children = [leftShape.tree, rightShape.tree] shapeAndStoreIfBetter(tempNode, shapes) #Right-Left tempNode.children = [rightShape.tree, leftShape.tree] shapeAndStoreIfBetter(tempNode, shapes) #flip(Left) - Right #tempNode.children = [flippedLeft,rightShape.tree] #shapeAndStoreIfBetter(tempNode, shapes) #Right-flip(Left) #tempNode.children = [rightShape.tree,flippedLeft] #shapeAndStoreIfBetter(tempNode, shapes) node.shapes = shapes if DO_PRINT: print("Shapes of node: " + str(node)) for t, s in node.shapes.items(): print(t) s.tree.printMe(1) print("--------------------")
def parseMulti(fileName): objFile = open(fileName) shapeList = [] vertexCount = 0 shape = Shape() shape.setShapeName("ShortBox") for line in objFile: splitedLine = line.split() if (len(splitedLine) != 0 and splitedLine[0] != '#'): definition = splitedLine[0] if (definition == 'g' and splitedLine[1] == 'default'): #Start for an object creation shape = Shape() elif (definition == 'v'): shape.addVertice(float(splitedLine[1]), float(splitedLine[2]), float(splitedLine[3])) vertexCount += 1 elif (definition == 'f'): shapeFace = [] for i in splitedLine[1:]: shapeFace.append((int(i) - 1) - vertexCount) shape.addFace(shapeFace) elif (definition == 'g' and splitedLine[1] != 'default'): shape.setShapeName(splitedLine[1]) elif (len(splitedLine) == 0 and shape != None and shape.getSize() > 0): shapeList.append(shape) shapeList.append(shape) return shapeList
import random from math import log from shapes import Shape DEFAULT_SHAPE_SIZE = 4 SHAPE_EMPTY_NAME = ' ' SHAPES = { 4: { 'default': { 'I': Shape(((0, 0), (1, 0), (2, 0), (3, 0)), 'I'), 'J': Shape(((0, 1), (1, 1), (2, 1), (2, 0)), 'J'), 'L': Shape(((0, 1), (1, 1), (2, 1), (0, 0)), 'L'), 'O': Shape(((0, 0), (1, 0), (0, 1), (1, 1)), 'O'), 'S': Shape(((0, 0), (1, 0), (1, 1), (2, 1)), 'S'), 'T': Shape(((0, 1), (1, 1), (2, 1), (1, 0)), 'T'), 'Z': Shape(((0, 1), (1, 1), (1, 0), (2, 0)), 'Z') }, 'mr stark I don\'t feel so good': { 'I': Shape(((0, 0), (1, 0), (3, 0)), 'I'), 'J': Shape(((0, 0), (0, 1), (2, 0)), 'J'), 'L': Shape(((0, 0), (2, 1), (2, 0)), 'L'), 'O': Shape(((0, 0), (2, 0), (0, 2)), 'O'), 'S': Shape(((0, 0), (1, 0), (2, 1)), 'S'), 'T': Shape(((0, 2), (2, 1), (1, 0)), 'T'), 'Z': Shape(((0, 1), (1, 0)), 'Z') }, 'thonk': { 'I': Shape(((0, 0), (1, 0), (2, 0), (3, 0)), 'I'), 'O': Shape(((0, 0), (1, 0), (2, 0), (3, 0)), 'O') }
def boundingDiamond(wid=50, inner=1500, owid=250, outer=2250, left="Left", right="Right", center="Center", centeru="?"): print "boundingDiamond" toReturn = Shape([]) v = Vector(1,1) w = Vector(1,-1) oo = outer/2. oi = (outer - owid)/2. # print outer, wid, outer-wid # print oo, oi m = (Matrix(1, -1, 1, 1)/math.sqrt(2)) rect1 = Polyline([v*oo, w*oo, -v*oo, -w*oo, v*oo, v*oi, -w*oi, -v*oi, w*oi, v*oi], True, False, 3)*m; oo = inner/2. oi = (inner - wid)/2. rect2 = Polyline([v*oo, w*oo, -v*oo, -w*oo, v*oo, v*oi, -w*oi, -v*oi, w*oi, v*oi], True, False, 3) toReturn.add(rect(Vector(-inner/2, -inner/3), Vector(-inner/2 + wid, inner/3)).setMaterial(3)) toReturn.add(rect(Vector(inner/2, -inner/3), Vector(inner/2 - wid, inner/3)).setMaterial(3)) if centeru[0] != '?': toReturn.add(rect(Vector(-inner/3, inner/2-wid), Vector(inner/3, inner/2)).setMaterial(3)) toReturn.add(rect(Vector(-inner/3, -inner/2+wid), Vector(inner/3, -inner/2)).setMaterial(3)) # rect1 = (rect(v*(-oi), v*oi)).add(rect(v*(-oo), v*oo)) # print rect1 # toReturn.add(rect(v*(-oi), v*oi)); # toReturn.add(rect(v*(-oo), v*oo)); toReturn.add(rect1.setMaterial(3)) # toReturn.add(rect2) toReturn.add((font.shapeFromStringBoundedCentered(left, wid, -1) + Vector(-inner/2. - inner/4. + 3*wid, 0)).setMaterial(3)) toReturn.add((font.shapeFromStringBoundedCentered(center, wid, -1) + Vector(0, -inner/2. - inner/4. + 4*wid)).setMaterial(3)) toReturn.add((font.shapeFromStringBoundedCentered(right, wid, -1) + Vector(inner/2. + inner/4. - 3*wid, 0)).setMaterial(3)) if centeru[0] != '?' and centeru[0] != ' ': toReturn.add((font.shapeFromStringBoundedCentered(centeru, wid, -1) + Vector(0, +inner/2. + inner/4. - 4*wid)).setMaterial(3)) mark = alignmentMark(100).setMaterial(3)*m; mx = inner - 5*wid; toReturn.add(mark + Vector(0, mx)); toReturn.add(mark + Vector(0, -mx)); toReturn.add(mark + Vector(mx, 0)); toReturn.add(mark + Vector(-mx, 0)); return toReturn
# hyper params T_max = 1000 T_min = 1 T_delta = 0.05 # temperature decay temps = np.arange(T_max, T_min, -T_delta) theta = 1 all_losses = [] all_images = [] # simulated annealing print("Generating image...") for i in range(len(temps)): T = temps[i] # current temperature shape = Shape(constraints) canvas_with_shape = shape.superimpose(canvas) epsilon = nrmse(target, canvas) epsilon_shape = nrmse(target, canvas_with_shape) if epsilon_shape < epsilon < theta: # shape brings canvas closer to target # hill climbing mut_shape = mutate(shape) canvas_mut_shape = mut_shape.superimpose(canvas) epsilon_mut = nrmse(target, canvas_mut_shape) if epsilon_mut < epsilon_shape: # mutated shape is better than original shape canvas = canvas_mut_shape epsilon = epsilon_mut
def definitions(): # # define zulus #for i in range (1,160): #x=random.uniform(1,1280) #y=random.uniform(1,800) #body=Rect(20,20) #anchor=[x,y,0.0] #angle=0 # angle #r=random.uniform(0,1.0) #g=random.uniform(0,1.0) #b=random.uniform(0,1.0) #a=random.uniform(0,1.0) #color=[r,g,b,a] #z= Zulu(body,anchor,angle,color) ##Define as many rules as necessary #r1=Slide((random.uniform(-120,120),random.uniform(-80,80))) ## append zulus to rules #r1.add(z) #for i in range (1,160): #x=random.uniform(1,1200) #y=random.uniform(1,800) #shp=Rect(20,20) #pos=[x,y,0.0] #a=0 # angle #r=random.uniform(0,1.0) #g=random.uniform(0,1.0) #b=random.uniform(0,1.0) #a=random.uniform(0,1.0) #col=[r,g,b,a] #z= Zulu(shp,pos,a,col) egg_white = [ -10, -25, -20, -15, +10, -25, -20, +15, +20, -15, -10, +25, +20, +15, +10, +25, ] egg_yellow = [ -10, -10, -10, +10, +10, -10, +10, +10, ] b = Body([ Shape(egg_white, Color.white).offset(+200, +105), Shape(egg_yellow, Color.orange).offset(+300, +200), Rect(100, 100, 120, 200, Color.red).offset(100, 200), Rect(100, 100, 120, 200, Color.red).rotate(10).offset(200, 600) ]) toto = Zulu(body=b) rule1 = Slide((random.uniform(-12, 12), random.uniform(-8, 8))) engine.ruleset.add(rule1, toto)
def starkRound1(fname): gds = GDSinfo() # gds.add(capacitor(10, 10, 150, 200, 100, 5, 5, 3, 4)); # gds.add(dev2D(0) + Vector(0, 100)); # gds.add(dev2D(1) + Vector(0, 50)); xi = 0 yi = 0 P = [75, 100, 150]; CS = [7, 10, 25] #, 8, 10, 15, 20 T = [0, 2] #, -7]#, 3] N = [2] WWS = [10, 15] DS = [14, 16, 18, 20, 25, 30] for p in P: for cs in CS: for n in N: for wws in WWS: yi += 1; for t in T: for ds in DS: xi += 1; # wws = 10 # print p, cs, t chip = Shape([], []); boxwid = 1400 - 4*wws tipwid = 2 if t < 0: tipwid = -t t = 1 tipwid *= ds/12. tipwid = int(tipwid*100)/100. if t == 3: [dev, devhgt] = dev2D(T[0], padsize=p, diskspacing=ds, wirewidF=wws, wirespaceF=wws, tipwid=tipwid, gespace=30) else: [dev, devhgt] = dev2D(t, padsize=p, diskspacing=ds, wirewidF=wws, wirespaceF=wws, tipwid=tipwid, gespace=30) [bbll, bbur] = dev.getBoundingBox() wid = bbur.x - bbll.x; capwid = (boxwid - wid - 4*wws)/2. numcap = int((boxwid/devhgt) + .25) for i in range(1, numcap+1): if t == 3: if i == 1: chip.add(dev + Vector(0, -boxwid/2. + (i-1)*devhgt + p + wws*2)); else: # print T[i-1] # print dev2D(T[i-1], diskspacing=ds, padsize=p, wirewidF=wws, wirespaceF=wws, gespace=30) t2 = T[i-1] if t2 < 0: t = 1 tipwid = -t2 chip.add(dev2D(t2, diskspacing=ds, padsize=p, wirewidF=wws, wirespaceF=wws, gespace=30, tipwid=tipwid) + Vector(0, boxwid/2. - i*devhgt)); else: chip.add(dev + Vector(0, -boxwid/2. + (i-1)*devhgt + p + wws*2)); [cap, capwidtrue] = capacitor(wirewid=wws, wirespace=cs, height=boxwid, width=capwid, paddepth=p, numY=n, circlewid=5, numcirclesets=4, addBreak=5) # [bbll, bbur] = cap.getBoundingBox() # capwidtrue chip.add(cap - Vector(boxwid/2., boxwid/2.)); chip.add(cap + Vector(boxwid/2. - capwidtrue, -boxwid/2.)); height=boxwid paddepth=p numY=n l = int((height - paddepth)/float(numY) - paddepth) if t == 0: type = "SQUARE" elif t == 1: type = "TIP:" + str(tipwid) + "UM" elif t == 2: type = "CIRCLE" elif t == 3: type = "MIXED" chip.add(boundingDiamond(left="W=10um\nS=" + str(cs) + "um\nP=" + str(p) + "um\nL=" + str(l) + "um", center="T=" + type + "\nDS=" + str(ds) + "um\nP=" + str(p) + "um\n[" + str(xi) + ", " + str(yi) + "]", right="W=10um\nS=" + str(cs) + "um\nP=" + str(p) + "um\nL=" + str(l) + "um")); gds.add(chip*(Matrix(1, -1, 1, 1, xi*2250, yi*2250)/math.sqrt(2))) xi = 0; # yi += 1; xi = 0; for p in P: yi += 1; for t in T: for ds in DS: xi += 1; wws = 10 # print p, cs, t chip = Shape([], []); boxwid = 1400 - 4*wws tipwid = 2 if t < 0: tipwid = -t t = 1 tipwid *= ds/12. tipwid = int(tipwid*100)/100. lrpad = 2 if t == 3: [dev, devhgt] = dev2D(T[0], padsize=p, diskspacing=ds, wirewidF=wws, wirespaceF=wws, tipwid=tipwid, gespace=30, lrpad=2) else: [dev, devhgt] = dev2D(t, padsize=p, diskspacing=ds, wirewidF=wws, wirespaceF=wws, tipwid=tipwid, gespace=30, lrpad=2) # dev = dev - Vector(p, 0); [bbll, bbur] = dev.getBoundingBox() wid = bbur.x - bbll.x; boxwid2 = boxwid - p - 4*wws numcap = int((boxwid/devhgt) + .25) numdev = -1 while boxwid2 > 0: boxwid2 -= wid numdev += 1 for x in range(1, numdev+1): for i in range(1, numcap+1): if t == 3: if i == 1: chip.add(dev + Vector((x-(numdev+1)*.5)*wid, (i-1-numcap/2.)*devhgt + p + wws*2)); else: # print T[i-1] # print dev2D(T[i-1], diskspacing=ds, padsize=p, wirewidF=wws, wirespaceF=wws, gespace=30) t2 = T[i-1] if t2 < 0: t = 1 tipwid = -t2 chip.add(dev2D(t2, diskspacing=ds, padsize=p, wirewidF=wws, wirespaceF=wws, gespace=30, tipwid=tipwid, lrpad=lrpad) + Vector((x-numdev*.5)*wid, boxwid/2. - i*devhgt)); else: print (x-(numdev+1)*.5) chip.add(dev + Vector((x-(numdev+1)*.5)*wid, -boxwid/2. + (i-1)*devhgt + p + wws*2)); if x+1 == numdev: lrpad = 0 if t == 3: [dev, devhgt] = dev2D(T[0], padsize=p, diskspacing=ds, wirewidF=wws, wirespaceF=wws, tipwid=tipwid, gespace=30, lrpad=0) else: [dev, devhgt] = dev2D(t, padsize=p, diskspacing=ds, wirewidF=wws, wirespaceF=wws, tipwid=tipwid, gespace=30, lrpad=0) # dev += Vector(p, 0) # elif x+1 == numdev-1: # print "Bye..."; # else: # lrpad = 3 # # if t == 3: # [dev, devhgt] = dev2D(T[0], padsize=p, diskspacing=ds, wirewidF=wws, wirespaceF=wws, tipwid=tipwid, gespace=30, lrpad=3) # else: # [dev, devhgt] = dev2D(t, padsize=p, diskspacing=ds, wirewidF=wws, wirespaceF=wws, tipwid=tipwid, gespace=30, lrpad=3) if t == 0: type = "SQUARE" elif t == 1: type = "TIP:" + str(tipwid) + "UM" elif t == 2: type = "CIRCLE" elif t == 3: type = "MIXED" string = "[" + str(xi) + ", " + str(yi) + "]" chip.add(boundingDiamond(left=string, center="T=" + type + "\nDS=" + str(ds) + "um\nP=" + str(p) + "um", right=string)); gds.add(chip*(Matrix(1, -1, 1, 1, xi*2250, yi*2250)/math.sqrt(2))) xi = 0; yi += 1; boxwid = 1400 - 4*wws for xi in range(-2, len(T)*len(DS)-2): chip = Shape([], []); wid = 5*xi + 5 x = -boxwid/2. h = -boxwid/2. if xi <= 0: string = "L=.5:1:2:3:...um" wid = .5 chip.add(rect(Vector(x,-h), Vector(x+wid, h)).setMaterial(3)) x += 2*wid; chip.add(rect(Vector(x,-h), Vector(x+wid, h)).setMaterial(3)) x += 2*wid; chip.add(rect(Vector(x,-h), Vector(x+wid, h)).setMaterial(3)) x += 2*wid; wid = 1 i = 1 while x + wid < boxwid/2.: if (wid%5) == 0: chip.add(rect(Vector(x,-.95*h), Vector(x+wid, .95*h)).setMaterial(3)) else: chip.add(rect(Vector(x,-h), Vector(x+wid, h)).setMaterial(3)) x += 2*wid; if (i%3) == 0: wid += 1; i += 1; else: string = "L=" + str(wid) + "um"; while x + wid < boxwid/2.: chip.add(rect(Vector(x,-h), Vector(x+wid, h)).setMaterial(3)) x += 2*wid; string2 = "[" + str(xi+2) + ", " + str(yi) + "]"; chip.add(boundingDiamond(left=string2, center=string, right=string2, centeru=" ")); gds.add(chip*(Matrix(1, -1, 1, 1, (xi+3)*2250, yi*2250)/math.sqrt(2))) gds.add(chip*(Matrix(1, -1, 1, 1, (xi+3)*2250, (yi+1)*2250)/math.sqrt(2))) gds.add(chip*(Matrix(1, -1, 1, 1, (xi+3)*2250, (yi+2)*2250)/math.sqrt(2))) yi += 3; for xi in range(0, len(T)*len(DS)): # chip = Shape([], []); v = Vector(1,1) w = Vector(1,-1) oo = 2250/2. oi = (2100 - xi*25)/2. # print outer, wid, outer-wid # print oo, oi rect1 = Polyline([v*oo, w*oo, -v*oo, -w*oo, v*oo, v*oi, -w*oi, -v*oi, w*oi, v*oi], True, False, 3).setMaterial(3); gds.add(rect1 + Vector((xi+1)*2250, yi*2250)) gds.add((font.shapeFromStringBoundedCentered(str(2100 - xi*25) + "um", 100, -1) + Vector((xi+1)*2250, (yi+.6)*2250)).setMaterial(3)) # print "Plotting" # gds.plot() print "Exporting" gds.exportGDS(fname) print "Done"
def capacitor(wirewid=10, wirespace=10, height=1300, width=200, paddepth=100, numY=2., circlewid=5, numcirclesets=4, addBreak=0): toReturn = Shape([]); length = (height - (numY+1)*paddepth)/numY numcirclesets = int(2*math.sqrt((length-2*wirespace)/(12*circlewid))) wire = rect(Vector(0,0), Vector(wirewid, length-2*wirespace)) wire.material = 3; d = (length-4.*wirespace)/numcirclesets # print length # print -4*wirespace # print length-4*wirespace # print d # print '' # circlespacing = 1.5*circlewid # ## print range(1,numcirclesets) # # c = circle(Vector(0,0), circlewid/2) # x = circlewid/4. ## c = -rect(Vector(-x,-x), Vector(x,x)) # c.material = 3; # ## for y in range(0,numcirclesets+1): ## toReturn.add(circle(Vector(-circlewid, y*d + 2.*wirespace), circlewid/2)) # # for y in range(1,numcirclesets+1): ## print range(0,y) # # for z in range(0,y): # print y, z # # circle(Vector(-wirewid/2, (y*d - d/2 + 2*wirespace) - (y*circlespacing/2) + z*circlespacing), circlewid/2).plot() # # wire = (circle(Vector(wirewid/2, (y*d - d/2 + 2*wirespace) - (y*circlespacing/2) + z*circlespacing), circlewid/2)).intersect(wire) # wire = (c + Vector(wirewid/2., (y*d - d/2. + 2.*wirespace) - ((y-1)*circlespacing/2.) + z*circlespacing)).intersect(wire) # for # m = Matrix(math.pi, wirewid, length) # # print m wire2 = wire*Matrix(math.pi, wirewid, length) # print wire # print wire2 x = 0; wires = Shape([]); while x < width - 1*(wirewid): wires.add(wire + Vector(x, 0)) x += wirewid+wirespace if x < width - 1*(wirewid): wires.add(wire2 + Vector(x, 0)) x += wirewid+wirespace pad = rect(Vector(0, 0), Vector(x-wirespace, paddepth)); pad.material = 3; pad2 = rect(Vector(0, addBreak/2. + paddepth/2.), Vector(x-wirespace, paddepth)); pad3 = rect(Vector(0, 0), Vector(x-wirespace, -addBreak/2. + paddepth/2.)); pad2.material = 3; pad3.material = 3; toReturn.add(pad) for i in range(0, numY): toReturn.add(wires + Vector(0, i*(length + paddepth) + paddepth)) if i != numY-1 and addBreak: toReturn.add(pad2 + Vector(0, (i+1)*(length+paddepth))) toReturn.add(pad3 + Vector(0, (i+1)*(length+paddepth))) else: toReturn.add(pad + Vector(0, (i+1)*(length+paddepth))) if x-wirespace < width: print 'capacitor: Could not fit another wire in. Shrinking the pad width.' # toReturn.add(font.shapeFromStringBoundedCentered(string, w=0, h=2) + Vector(10,10)) # toReturn.plot() return [toReturn, x-wirespace]
#!/usr/bin/python3 from shapes import Shape from shapes import Rectangle s1 = Shape(4,8) print(s1) r1 = Rectangle(5,10,6,8) print(r1)
def recursive_add(tree, defines): return Shape.from_yaml(tree, defines)
def main(argv): parser = argparse.ArgumentParser( description="Generate a cuboid dataset" ) parser.add_argument( "output_directory", help="Save the dataset in this directory" ) parser.add_argument( "--n_samples", type=int, default=10, help="Number of training samples to be generated" ) parser.add_argument( "--shapes_type", default="cubes", choices=[ "cubes", "cubes_translated", "cubes_rotated_translated", "cubes_rotated", "rectangles", "rectangles_translated", "rectangles_rotated", "rectangles_rotated_translated", "ellipsoid", "random" ], help="The type of the shapes in every sample" ) parser.add_argument( "--n_shapes_per_samples", type=int, default=1, help="Number of shapes per sample" ) parser.add_argument( "--maximum", type=lambda x: tuple(map(float, x.split(","))), default="0.5,0.5,0.5", help="Maximum size along every axis" ) parser.add_argument( "--minimum", type=lambda x: tuple(map(float, x.split(","))), default="0.13,0.13,0.13", help="Maximum size along every axis" ) args = parser.parse_args(argv) # Check if output directory exists and if it doesn't create it if not os.path.exists(args.output_directory): os.makedirs(args.output_directory) # Create a directory based on the type of the shapes inside the output # directory output_directory = os.path.join( args.output_directory, args.shapes_type ) ranges = None if "cubes" in args.shapes_type: # Make sure that the maximum and minimum range are equal along each # axis assert args.maximum[0] == args.maximum[1] assert args.maximum[1] == args.maximum[2] assert args.minimum[0] == args.minimum[1] assert args.minimum[1] == args.minimum[2] ranges = np.linspace( args.minimum[0], args.maximum[0], 10, endpoint=False ) # elif "rectangles" in args.shapes_type: else: ranges = [ np.linspace(args.minimum[0], args.maximum[0], 10, endpoint=False), np.linspace(args.minimum[1], args.maximum[1], 10, endpoint=False), np.linspace(args.minimum[2], args.maximum[2], 10, endpoint=False), ] bar = Bar("Generating %d cuboids" % (args.n_samples,), max=args.n_samples) c = None for i in range(args.n_samples): if "cubes" in args.shapes_type: c = get_single_cube(args.minimum, args.maximum) if "rectangles" in args.shapes_type: c = get_single_rectangle(args.minimum, args.maximum) if "translated" in args.shapes_type: t = 0.3*np.random.random((3, 1)) c.translate(t) if "rotated" in args.shapes_type: q = Quaternion.random() R = q.rotation_matrix c.rotate(R) if "ellipsoid" in args.shapes_type: abc = np.random.random((3, 1)) c1 = Ellipsoid(abc[0], abc[1], abc[2]) c2 = Ellipsoid(abc[0], abc[1], abc[2]) c3 = Ellipsoid(abc[0], abc[1], abc[2]) q = Quaternion.random() R = q.rotation_matrix c2.rotate(R) q = Quaternion.random() R = q.rotation_matrix c3.rotate(R) # t = 0.3*np.random.random((3, 1)) # c1.translate(t) c = Shape.from_shapes([c1, c2, c3]) if "random" in args.shapes_type: #if random.choice((True, False)): #if True: # q = Quaternion.random() # c1, c2 = adjacent_cubes(q.rotation_matrix) #else: if True: q1 = Quaternion.random() q2 = Quaternion.random() c1, c2 = multiple_cubes( q1.rotation_matrix, q2.rotation_matrix, 3.5*np.random.random((3, 1)) ) # q = Quaternion.random() # c1, c2 = adjacent_cubes(q.rotation_matrix) # q1 = Quaternion.random() # x_max1, y_max1, z_max1 = tuple(np.random.rand(3)) # c3 = Cuboid(-x_max1, x_max1, -y_max1, y_max1, -z_max1, z_max1) # c3.rotate(q1.rotation_matrix) # c3.translate(np.random.random((3,1)).reshape(3, -1)) c = Shape.from_shapes([c1, c2]) # Create subdirectory to save the sample folder_name = ''.join([ random.choice(ascii_letters + digits) for n in xrange(32) ]) base_dir = os.path.join(output_directory, folder_name, "models") if not os.path.exists(base_dir): os.makedirs(base_dir) # print base_dir # Save as obj file c.save_as_mesh(os.path.join(base_dir, "model_normalized.obj"), "obj") c.save_as_mesh(os.path.join(base_dir, "model_normalized.ply"), "ply") c.save_as_pointcloud( os.path.join(base_dir, "model_normalized_pcl.obj"), "obj" ) if "translated" in args.shapes_type: print os.path.join(base_dir, "model_normalized_pcl.obj"), t.T if "rotated" in args.shapes_type: print os.path.join(base_dir, "model_normalized_pcl.obj"), q bar.next() for i in os.listdir(output_directory): x = os.path.join(output_directory, i, "models/model_normalized.obj") m = MeshFromOBJ(x) print x, m.points.max(-1)
def shapeFromGlyph(self, glyph): # Save loaded glyphs for speed toReturn = Shape([],[]) if glyph.isComposite(): print "Warning: This case is broken!, it does not transform..." # print "COMPOSITE" for component in glyph.components: print component print component.getComponentInfo() [name, transform] = component.getComponentInfo() print transform print type(transform) m = Matrix(transform) print m print self.tt['glyf'][name] toReturn.add(self.shapeFromGlyph(self.tt['glyf'][name])) # for item in self.getCMAP().cmap.items(): # if item[1] == name: # toReturn.add(self.shapeFromGlyph(self.tt[ 'glyf' ][item[0]])) # break else: # print "NOT COMPOSITE" last = 0 for i in range(glyph.numberOfContours): toAdd = Polyline([], True) prevV = None prevOn = None prevprevV = None prevprevOn = None firstV = None firstOn = None secondV = None secondOn = None for j in range(last, glyph.endPtsOfContours[i] + 1): v = Vector(glyph.coordinates[j][0], glyph.coordinates[j][1])/float(self.width) # This is a temporary fix! on = glyph.flags[j] & 0x01 if firstOn == None: firstOn = on firstV = v elif secondOn == None: secondOn = on secondV = v # print v # print prevprevOn, prevOn, on # print prevprevV, prevV, v if prevOn and on: if prevprevOn == None: toAdd.add(prevV) toAdd.add(v) elif prevOn != None and prevprevOn != None: if prevprevOn and not prevOn: if on: # 101 toAdd.add(qBezier(prevprevV, prevV, v)) elif not on: # 100 # print (prevV + v) # print (prevV + v)/2 toAdd.add(qBezier(prevprevV, prevV, (prevV + v)/2)) elif not prevprevOn and not prevOn: if on: # 001 toAdd.add(qBezier((prevprevV + prevV)/2, prevV, v)) elif not on: # 000 toAdd.add(qBezier((prevprevV + prevV)/2, prevV, (prevV + v)/2)) prevprevOn = prevOn prevprevV = prevV prevOn = on prevV = v # print "toAdd: " # print toAdd # print "First Here" # print prevOn, on, firstOn # print prevprevV, v, firstV # toAdd.add(Vector(0,0)) if not on: if firstOn != None and not firstOn: if prevprevOn: toAdd.add(qBezier(prevprevV, v, (v + firstV)/2)) else: toAdd.add(qBezier((prevprevV + v)/2, v, (v + firstV)/2)) if firstOn != None and firstOn: if prevprevOn: toAdd.add(qBezier(prevprevV, v, firstV)) else: toAdd.add(qBezier((prevprevV + v)/2, v, firstV)) # if firstOn != None and secondOn != None: # print "First Second Here" # print on, firstOn, secondOn ## if on and firstOn and secondOn: # 111 # if on and not firstOn and secondOn: # 101 # toAdd.add(qBezier(v, firstV, secondV)) # if on and not firstOn and not secondOn: # 100 # toAdd.add(qBezier(v, firstV, (firstV + secondV)/2)) # if not on and not firstOn and secondOn: # 001 # toAdd.add(qBezier((v + firstV)/2, firstV, secondV)) # if not on and not firstOn and not secondOn: # 000 # toAdd.add(qBezier((v + firstV)/2, firstV, (firstV + secondV)/2)) # toAdd.add(v) last = glyph.endPtsOfContours[i] + 1 # print toAdd.area() # toAdd.add(Vector(0,0)) toReturn.add(toAdd) # print "toReturn: " # print toReturn if len(toReturn.polylines) > 1: k = 0 for i in range(0, toReturn.size): # print toReturn.polylines[i].area() if abs(toReturn.polylines[i].area()) > abs(toReturn.polylines[k].area()): # Save area for speed k = i finList = [] for i in range(0, toReturn.size): if toReturn.polylines[i].area() < 0: # print k, i # print toReturn.polylines[i] # print toReturn.polylines[k] # toReturn.polylines[i].points.reverse() m = 0 #toReturn.polylines[i].size-1 j = 0 norm = (toReturn.polylines[k].points[0] - toReturn.polylines[i].points[m]).norm2() # Possible error if empty toReturn.polylines[k].sizeCalc() for l in range(0, toReturn.polylines[k].size): # print norm, (toReturn.polylines[k].points[l] - toReturn.polylines[i].points[m]).norm2() if (toReturn.polylines[k].points[l] - toReturn.polylines[i].points[m]).norm2() < norm: j = l norm = (toReturn.polylines[k].points[l] - toReturn.polylines[i].points[m]).norm2() # print j # toReturn.polylines[k].points[j], toReturn.polylines[k].points = toReturn.polylines[k].points[0:j+1] + toReturn.polylines[i].points + [toReturn.polylines[i].points[0]] + toReturn.polylines[k].points[j:] # toReturn.polylines[k].points = toReturn.polylines[k].points[0:j+1] + [toReturn.polylines[i].points[toReturn.polylines[i].size-1]] + toReturn.polylines[i].points + toReturn.polylines[k].points[j:] toReturn.polylines[k].sizeCalc() else: finList += [ toReturn.polylines[i] ] toReturn = Shape(finList) # toReturn.polylines.remove(i) # finList = [toReturn.polylines[k]] # # for polyline in toReturn.polylines: # print polyline # if polyline != toReturn.polylines[k]: # print polyline.area() # if polyline.area() < 0: # # highest = polyline.points[0] # print "HIGHEST: ", highest # j = 0 # # for i in range(0, polyline.size): # if polyline.points[i].y > highest.y: # highest = polyline.points[i] # j = i # # polyline.points.insert(i, highest) # polyline.points.insert(i, highest + Vector(0,2)) # polyline.points.insert(i, highest) # # else: # print "extended" # finList.extend(polyline) # # toReturn.polylines[k].union(polyline) # # return Shape(finList,[]) return toReturn
def dev2D(tip=2, tipwid=2, diskspacing=12, electspacing=5, gap=6, groundoffset=2.5, electwid=8, wirewid=6, wirespaceF=10, wirewidF=10, gespace=40, padsize=100, disks=[1.2, 1.3, 1.4, 1.5], couplinggap=.08, couplingwid=.12, couplinglen=1, lrpad=0): toReturn = Shape([]); if diskspacing < electwid: return None numdisks = len(disks) electspacing = diskspacing/3. groundoffset = diskspacing/4. electwid = 2*diskspacing/3. wirewid = diskspacing/2. wirespace = diskspacing/2. gespace = 4.5*electwid if wirespace >= wirespaceF: wirespaceF = wirespace #+.001 if wirewid >= wirewidF: wirewidF = wirewid #+.001 v1 = Vector(math.cos(math.pi/2.+couplinglen/2.), math.sin(math.pi/2.+couplinglen/2.)) v2 = Vector(math.cos(math.pi/2.-couplinglen/2.), math.sin(math.pi/2.-couplinglen/2.)) prevConnection = 0 tranlen = .75 disky = wirewidF + wirespaceF/2. + groundoffset gapStuff = Shape([]); for i in range(0, numdisks): c = Vector((i+.5-numdisks/2.)*diskspacing, disky) gapStuff.add(circle(c, disks[i]/2.).setMaterial(1)) irad = disks[i]/2. + couplinggap orad = disks[i]/2. + couplinggap + couplingwid iwid = couplingwid owid = .24 mrad = (irad + orad)/2. # pline = arc(c, c+v1, c+v2) pline = arc(c, c+v1*irad, c+v2*irad) + arc(c, c+v2*orad, c+v1*orad) pline.closed = True gapStuff.add(pline.setMaterial(1)) left = thickenPolyline(Polyline([c+v1*mrad, c+v1*mrad+v1.perp()*tranlen]), "CUBIC", [iwid, owid]).setMaterial(1) right = thickenPolyline(Polyline([c+v2*mrad, c+v2*mrad+v2.perp().perp().perp()*tranlen]), "CUBIC", [iwid, owid]).setMaterial(1) gapStuff.add(left) gapStuff.add(right) # print 'L: ', left.connections # print 'R: ', right.connections if not isinstance(prevConnection, Connection): firstConnection = Connection(c+v1*mrad+v1.perp()*tranlen, v1.perp(), owid) else: i = prevConnection f = Connection(c+v1*mrad+v1.perp()*tranlen, v1.perp(), owid) gapStuff.add(connectAndThicken(i,f).setMaterial(1)) prevConnection = Connection(c+v2*mrad+v2.perp().perp().perp()*tranlen, v2.perp().perp().perp(), owid) gratingOne = Connection(Vector(-numdisks*diskspacing/2. - diskspacing/2., disky), Vector(1,0), owid) gratingTwo = Connection(Vector(-numdisks*diskspacing/2. - diskspacing/2. - 9.5 - 5, disky - 9.5), Vector(0,-1), owid) gratingTwoA = Connection(Vector(-(numdisks+2)*diskspacing/2., wirewidF/6.), Vector(1,0), owid) gratingTwoC = Connection(Vector(numdisks*diskspacing/2., wirewidF/6.), Vector(1,0), owid) gapStuff.add(connectAndThicken(gratingOne,firstConnection).setMaterial(1)) gapStuff.add(connectAndThicken(gratingTwoC,prevConnection).setMaterial(1)) gapStuff.add(connectAndThicken(-gratingTwoC,gratingTwoA).setMaterial(1)) gapStuff.add(connectAndThicken(-gratingTwoA,gratingTwo).setMaterial(1)) gapStuff.add(gratingMike(gratingOne)) gapStuff.add(gratingMike(gratingTwo)) # gapStuff.plot(); # arc(c, c+v1, c+v2).plot() y = gespace/4. # electspacing - groundoffset + electwid/2. -wirewid/2 + tipwid/2. for i in range(0, (numdisks+2)/2): v = Vector((i-numdisks/2.)*diskspacing, electspacing - groundoffset + electwid/2. + disky) # if i == 0: # rect1 = rect(v + Vector(0, -wirewid/2. + tipwid/2.), v + Vector(-10, wirewid/2. + tipwid/2.)) # rect1 = rect(v + Vector(wirewid/2., -wirewid/2. + tipwid/2.), v + Vector(-electwid, wirewidF-wirewid/2. + tipwid/2.)) # else: rect1 = -rect(v + Vector(-wirewid/2., -wirewid/2 + tipwid/2.), v + Vector(wirewid/2, y + wirewidF - (electspacing - groundoffset + electwid/2.))) if tip == 0: # SQUARE tipobj = rect(v - Vector(electwid/2., electwid/2.), v + Vector(electwid/2., electwid/2.)).union(-rect1).setMaterial(3) elif tip == 1: # POINTY x = electwid/2. - tipwid/2. if i == 0: pline = Polyline([v, v + Vector(x,-x)]) tipobj = rect1.union(-thickenPolyline(pline, "CONSTANT", tipwid/2., "SHARP", "ROUND")).setMaterial(3) else: pline = Polyline([v + Vector(-x,-x), v, v + Vector(x,-x)]) tipobj = thickenPolyline(pline, "CONSTANT", tipwid/2., "SHARP", "ROUND").union(-rect1).setMaterial(3) elif tip == 2: # CIRCLE tipobj = circle(v, electwid/2.).union(rect1).setMaterial(3) if i != (numdisks+2)/2.: toReturn.add(tipobj) # Pads # v = Vector(-padsize-wirespaceF/2., y + 2*wirespaceF + wirewidF + padsize) # Right # toReturn.add(rect(v, v + Vector(padsize, padsize))) # toReturn.add(rect(v + Vector(padsize-wirewidF, -padsize + wirewidF + wirespaceF), v + Vector(padsize, 0))) # toReturn.add(rect(Vector((2-numdisks/2.)*diskspacing - wirewid/2., gespace/2. + wirewidF), Vector((2-numdisks/2.)*diskspacing + wirewid/2., gespace/2. + 2*wirewidF + 2*wirespaceF))) # toReturn.add(rect(Vector((2-numdisks/2.)*diskspacing + wirewid/2., gespace/2. + 2*wirewidF + 2*wirespaceF), v + Vector(padsize-wirewidF, -padsize + wirewidF + wirespaceF))) v = Vector(-padsize-wirespaceF-wirewidF/2., y + wirespaceF + wirewidF + disky) # L/R (prev Middle) toReturn.add(rect(v, v + Vector(padsize, padsize))) toReturn.add(rect(Vector((1-numdisks/2.)*diskspacing - wirewid/2., y + disky + wirewidF), Vector((1-numdisks/2.)*diskspacing + wirewid/2., y + disky + wirewidF + wirespaceF))) toReturn.add(rect(v + Vector(padsize, 0), Vector((1-numdisks/2.)*diskspacing + wirewid/2., y + disky + 2*wirewidF + wirespaceF))) toReturn.add(rect(v - Vector(wirespaceF, wirewidF + wirespaceF), Vector((0-numdisks/2.)*diskspacing - wirewid/2., y + disky + wirewidF))) # v = Vector(-2*padsize-5*wirespaceF/2.-wirewidF, y) # Left ## toReturn.add(rect(v, v + Vector(padsize, padsize))) # toReturn.add(rect(v + Vector(padsize, 0), Vector((-numdisks/2.)*diskspacing - wirewid/2., y + wirewidF))) # v = Vector(-2*padsize-5*wirespaceF/2.-wirewidF, -groundoffset) # Ground Left ## toReturn.add(rect(v, v + Vector(padsize, -padsize))) # toReturn.add(rect(v + Vector(padsize, 0), Vector((-numdisks/2.)*diskspacing - wirewid/2., -groundoffset - wirewidF))) toReturn.add(toReturn*Matrix(-1,0,0,1)) # FLIP HORIZ #toReturn.add(rect(v - Vector(wirewidF + wirespaceF, wirewidF + wirespaceF), v - Vector(wirespaceF, - padsize - wirewidF - wirespaceF))) #toReturn.add(rect(Vector(v.x - (wirewidF + wirespaceF), 0), v - Vector(wirespaceF, - padsize - wirewidF - wirespaceF))) toReturn.add(rect(Vector(v.x - (2*wirewidF + wirespaceF), 0), Vector(v.x-wirespaceF, 200))) toReturn.add(rect(Vector(7*wirewidF/2. + 3*wirespaceF + padsize, 0), Vector(11*wirewidF/2. + 3*wirespaceF + padsize, 200))) # Ground line toReturn.add(rect(v + Vector(-wirespaceF, padsize + wirespaceF), Vector(-v.x + wirespaceF, v.y + padsize + wirespaceF + wirewidF))) toReturn.add(rect(Vector(-wirewidF/2., y + disky + 3*wirespaceF + wirewidF), Vector(wirewidF/2., y + disky + 2*wirespaceF + wirewidF + padsize))) toReturn.add(rect(Vector(-wirewid/2., y + disky + wirewidF), Vector(wirewid/2., y + disky + 3*wirespaceF + wirewidF))) toReturn.add(tipobj) # if not (lrpad & 0x01): # Make left pad # v = Vector(-2*padsize-5*wirespaceF/2.-wirewidF, y) # Left # toReturn.add(rect(v, v + Vector(padsize, padsize))) # v = Vector(-2*padsize-5*wirespaceF/2.-wirewidF, -groundoffset) # Ground Left # toReturn.add(rect(v, v + Vector(padsize, -padsize))) # # if not (lrpad & 0x02): # Make right pad # v = Vector(-(-padsize-5*wirespaceF/2.-wirewidF), y) # Left # toReturn.add(rect(v, v + Vector(padsize, padsize))) # v = Vector(-(-padsize-5*wirespaceF/2.-wirewidF), -groundoffset) # Ground Left # toReturn.add(rect(v, v + Vector(padsize, -padsize))) # Ground gwid = diskspacing*numdisks/2. + electwid/2. gwid2 = diskspacing*numdisks/2. + wirewid/2. # toReturn.add(rect(Vector(-gwid, -gespace/2.), Vector(gwid, -groundoffset)).setMaterial(3)) # toReturn.add(rect(Vector(-gwid2, -gespace/2.-wirewidF), Vector(gwid2, -gespace/2.)).setMaterial(3)) toReturn.add(rect(Vector(-gwid2, wirespaceF/2.), Vector(gwid2 + wirespaceF, wirewidF + wirespaceF/2.)).setMaterial(3)) toReturn.add((rect(v - Vector(wirewidF + wirespaceF, wirewidF + wirespaceF), v - Vector(wirespaceF, - padsize - wirewidF - wirespaceF))*Matrix(-1,0,0,1)).setMaterial(3)) toReturn.setMaterial(3) toReturn.add(gapStuff) toReturn.add(toReturn*Matrix(1,0,0,-1)) # FLIP VERT toReturn.add(rect(Vector(gwid2 + wirespaceF, -wirewidF - wirespaceF/2.), Vector(gwid2 + wirespaceF + wirewidF, wirewidF + wirespaceF/2.)).setMaterial(3)) toReturn.add(rect(Vector(gwid2 + wirespaceF + wirewidF, - wirewidF), Vector(7*wirewidF/2. + 3*wirespaceF + padsize, wirewidF)).setMaterial(3)) # toReturn.add(rect(Vector(3*wirewidF/2. + 3*wirespaceF + padsize, -wirespaceF/2.), Vector(5*wirewidF/2. + 3*wirespaceF + 2*padsize, -wirespaceF/2. + padsize)).setMaterial(3)) # toReturn.add((rect(v - Vector(wirewidF + wirespaceF, wirewidF + wirespaceF), v - Vector(wirespaceF, - padsize - wirewidF - wirespaceF))*Matrix(-1,0,0,1)).setMaterial(3)) # toReturn.add((font.shapeFromStringBoundedCentered("42", -1, 7*5) + Vector(-85, 0)).setMaterial(3)) # return [toReturn.setMaterial(3), 2*padsize + 3*wirespaceF + groundoffset + gespace/2. + 3*wirewidF] return toReturn
def __init__(self): self.saved_ray = None Shape.__init__(self)
def grating(connection): wid = 1.5 wid2 = 1.5/2 base = Shape([thickenPolyline(Polyline([Vector(0,0), Vector(8,0)], False), "CUBIC", [connection.wid,wid])], [connection]) grates = [.15, .26, .25, .145, .26, .16, .245, .105, .365] mB = [[.05, .26, .26, .26], [.1, .225, .22, .21], [.15, .185, .18, .175]] spacing = .05 x = 8 i = 0 for grate in grates: if len(mB) > i: base.add(rect(Vector(x, -mB[i][1]/2), Vector(x+spacing, mB[i][1]/2))) base.add(rect(Vector(x, mB[i][1]/2 + mB[i][0]), Vector(x+spacing, mB[i][1]/2 + mB[i][0] + mB[i][2]))) base.add(rect(Vector(x, mB[i][1]/2 + mB[i][0] + mB[i][2] + mB[i][0]), Vector(x+spacing, mB[i][1]/2 + mB[i][0] + mB[i][2] + mB[i][0] + mB[i][3]))) base.add(rect(Vector(x, -mB[i][1]/2 - mB[i][0] - mB[i][2]), Vector(x+spacing,-mB[i][1]/2 - mB[i][0]))) base.add(rect(Vector(x, -mB[i][1]/2 - mB[i][0] - mB[i][2] - mB[i][0] - mB[i][3]), Vector(x+spacing,-mB[i][1]/2 - mB[i][0] - mB[i][2] - mB[i][0]))) i += 1 x += spacing base.add(rect(Vector(x, -wid2), Vector(x+grate, wid2))) x += grate base *= connection.matrix() base.plot() return base
def dev2D(tip=1, tipwid=2, diskspacing=12, electspacing=5, gap=6, groundoffset=2.5, electwid=8, wirewid=6, wirespaceF=10, wirewidF=10, gespace=40, padsize=100, disks=[1.2, 1.25, 1.3, 1.35, 1.4], couplinggap=.08, couplingwid=.12, couplinglen=1, lrpad=0): toReturn = Shape([]); if diskspacing < electwid: return None numdisks = len(disks) electspacing = diskspacing/3. groundoffset = diskspacing/4. electwid = 2*diskspacing/3. wirewid = diskspacing/2. wirespace = diskspacing/2. gespace = 4.5*electwid if wirespace >= wirespaceF: wirespaceF = wirespace #+.001 if wirewid >= wirewidF: wirewidF = wirewid #+.001 v1 = Vector(math.cos(math.pi/2.+couplinglen/2.), math.sin(math.pi/2.+couplinglen/2.)) v2 = Vector(math.cos(math.pi/2.-couplinglen/2.), math.sin(math.pi/2.-couplinglen/2.)) prevConnection = 0 tranlen = .75 # gapStuff = Shape([]); # # for i in range(0, numdisks): # c = Vector((i+.5-numdisks/2.)*diskspacing, 0) # gapStuff.add(circle(c, disks[i]/2.).setMaterial(1)) # # irad = disks[i]/2. + couplinggap # orad = disks[i]/2. + couplinggap + couplingwid # # iwid = couplingwid # owid = .24 # mrad = (irad + orad)/2. # ## pline = arc(c, c+v1, c+v2) # # pline = arc(c, c+v1*irad, c+v2*irad) + arc(c, c+v2*orad, c+v1*orad) # pline.closed = True # # gapStuff.add(pline.setMaterial(1)) # left = thickenPolyline(Polyline([c+v1*mrad, c+v1*mrad+v1.perp()*tranlen]), "CUBIC", [iwid, owid]).setMaterial(1) # right = thickenPolyline(Polyline([c+v2*mrad, c+v2*mrad+v2.perp().perp().perp()*tranlen]), "CUBIC", [iwid, owid]).setMaterial(1) # # gapStuff.add(left) # gapStuff.add(right) # ## print 'L: ', left.connections ## print 'R: ', right.connections # # if not isinstance(prevConnection, Connection): # firstConnection = Connection(c+v1*mrad+v1.perp()*tranlen, v1.perp(), owid) # else: # i = prevConnection # f = Connection(c+v1*mrad+v1.perp()*tranlen, v1.perp(), owid) # gapStuff.add(connectAndThicken(i,f).setMaterial(1)) # # prevConnection = Connection(c+v2*mrad+v2.perp().perp().perp()*tranlen, v2.perp().perp().perp(), owid) # # gapStuff.plot(); # arc(c, c+v1, c+v2).plot() y = gespace/2. # electspacing - groundoffset + electwid/2. -wirewid/2 + tipwid/2. for i in range(0, (numdisks+1)/2): v = Vector((i-numdisks/2.)*diskspacing, electspacing - groundoffset + electwid/2.) # if i == 0: # rect1 = rect(v + Vector(0, -wirewid/2. + tipwid/2.), v + Vector(-10, wirewid/2. + tipwid/2.)) # rect1 = rect(v + Vector(wirewid/2., -wirewid/2. + tipwid/2.), v + Vector(-electwid, wirewidF-wirewid/2. + tipwid/2.)) # else: rect1 = -rect(v + Vector(-wirewid/2., -wirewid/2 + tipwid/2.), v + Vector(wirewid/2, gespace/2. + wirewidF - (electspacing - groundoffset + electwid/2.))) if tip == 0: # SQUARE toReturn.add(rect(v - Vector(electwid/2., electwid/2.), v + Vector(electwid/2., electwid/2.)).union(-rect1).setMaterial(3)) elif tip == 1: # POINTY x = electwid/2. - tipwid/2. if i == 0: pline = Polyline([v, v + Vector(x,-x)]) toReturn.add(rect1.union(-thickenPolyline(pline, "CONSTANT", tipwid/2., "SHARP", "ROUND")).setMaterial(3)) # toReturn.add(rect1) # elif i == numdisks: # pline = Polyline([v + Vector(-x,-x), v]) # toReturn.add(thickenPolyline(pline, "CONSTANT", tipwid/2., "SHARP", "ROUND").setMaterial(3)) else: pline = Polyline([v + Vector(-x,-x), v, v + Vector(x,-x)]) # pline.plot() # toReturn.add(thickenPolyline(pline, "CONSTANT", tipwid/2., "SHARP", "ROUND").setMaterial(3)) # toReturn.add(rect(v + Vector(-wirewid/2., -wirewid/2 + tipwid/2.), v + Vector(wirewid/2, 10)).setMaterial(3)) toReturn.add(thickenPolyline(pline, "CONSTANT", tipwid/2., "SHARP", "ROUND").union(-rect1).setMaterial(3)) elif tip == 2: # CIRCLE toReturn.add(circle(v, electwid/2.).union(rect1).setMaterial(3)) # Pads v = Vector(-padsize-wirespaceF/2., y + 2*wirespaceF + wirewidF + padsize) # Right toReturn.add(rect(v, v + Vector(padsize, padsize))) toReturn.add(rect(v + Vector(padsize-wirewidF, -padsize + wirewidF + wirespaceF), v + Vector(padsize, 0))) toReturn.add(rect(Vector((2-numdisks/2.)*diskspacing - wirewid/2., gespace/2. + wirewidF), Vector((2-numdisks/2.)*diskspacing + wirewid/2., gespace/2. + 2*wirewidF + 2*wirespaceF))) toReturn.add(rect(Vector((2-numdisks/2.)*diskspacing + wirewid/2., gespace/2. + 2*wirewidF + 2*wirespaceF), v + Vector(padsize-wirewidF, -padsize + wirewidF + wirespaceF))) v = Vector(-padsize-3*wirespaceF/2.-wirewidF, y + wirespaceF + wirewidF) # Middle toReturn.add(rect(v, v + Vector(padsize, padsize))) toReturn.add(rect(Vector((1-numdisks/2.)*diskspacing - wirewid/2., gespace/2. + wirewidF), Vector((1-numdisks/2.)*diskspacing + wirewid/2., gespace/2. + wirewidF + wirespaceF))) toReturn.add(rect(v + Vector(padsize, 0), Vector((1-numdisks/2.)*diskspacing + wirewid/2., gespace/2. + 2*wirewidF + wirespaceF))) v = Vector(-2*padsize-5*wirespaceF/2.-wirewidF, y) # Left # toReturn.add(rect(v, v + Vector(padsize, padsize))) toReturn.add(rect(v + Vector(padsize, 0), Vector((-numdisks/2.)*diskspacing - wirewid/2., y + wirewidF))) v = Vector(-2*padsize-5*wirespaceF/2.-wirewidF, -groundoffset) # Ground Left # toReturn.add(rect(v, v + Vector(padsize, -padsize))) toReturn.add(rect(v + Vector(padsize, 0), Vector((-numdisks/2.)*diskspacing - wirewid/2., -groundoffset - wirewidF))) toReturn.add(toReturn*Matrix(-1,0,0,1)) if not (lrpad & 0x01): # Make left pad v = Vector(-2*padsize-5*wirespaceF/2.-wirewidF, y) # Left toReturn.add(rect(v, v + Vector(padsize, padsize))) v = Vector(-2*padsize-5*wirespaceF/2.-wirewidF, -groundoffset) # Ground Left toReturn.add(rect(v, v + Vector(padsize, -padsize))) if not (lrpad & 0x02): # Make right pad v = Vector(-(-padsize-5*wirespaceF/2.-wirewidF), y) # Left toReturn.add(rect(v, v + Vector(padsize, padsize))) v = Vector(-(-padsize-5*wirespaceF/2.-wirewidF), -groundoffset) # Ground Left toReturn.add(rect(v, v + Vector(padsize, -padsize))) # Ground gwid = diskspacing*numdisks/2. + electwid/2. gwid2 = diskspacing*numdisks/2. + wirewid/2. # toReturn.add(rect(Vector(-gwid, -gespace/2.), Vector(gwid, -groundoffset)).setMaterial(3)) # toReturn.add(rect(Vector(-gwid2, -gespace/2.-wirewidF), Vector(gwid2, -gespace/2.)).setMaterial(3)) toReturn.add(rect(Vector(-gwid2, -groundoffset-wirewidF), Vector(gwid2, -groundoffset)).setMaterial(3)) return [toReturn.setMaterial(3), 2*padsize + 3*wirespaceF + groundoffset + gespace/2. + 3*wirewidF]
def recursive_add(tree, defines): return Shape._recursive_helper(tree, defines)