def offset_curve(self, amount, quality=None): """ +ve dilation -ve erosion """ if amount == 0.0: return self.copy() elif amount > 0.0: return self.minkowski_sum(shape.circle(amount*2.0, quality).shape_2()) else: return self.erosion(shape.circle(amount*-2.0, quality).shape_2())
def offset_curve(self, amount, quality=None): """ +ve dilation -ve erosion """ if amount == 0.0: return self.copy() elif amount > 0.0: return self.minkowski_sum( shape.circle(amount * 2.0, quality).shape_2()) else: return self.erosion(shape.circle(amount * -2.0, quality).shape_2())
def draw_house(): arena.clear("blue", show=False) #sky # Note the order of drawing! (Some shapes overlap) shape.plot(shape.rectangle(24,15,72,15,72,7,24,7), colour="orange") #main house shape.plot(shape.rectangle(20,7,24,3,72,3,76,7), colour="red") #roof shape.plot(shape.rectangle(58,15,58,10,64,10,64,15), colour="magenta") #door arena.set_pixel(63,12,"red") #doorknob shape.plot(shape.rectangle(32,9,44,9,44,12,32,12), colour="cyan") #window shape.plot(shape.rectangle(98,11,100,11,100,15,98,15), colour="magenta") #tree trunk shape.plot(shape.circle(99,6,5), colour="green") #tree foliage shape.plot(shape.circle(122,3,2), colour="yellow") #sun shape.plot(shape.line(0,15,127,15), colour="green") #grass arena.render()
def render(self, bit_diameter, bit_pad): xsize = self.xsize ysize = self.ysize a = bit_pad b = bit_pad + self.zsize/10.0 pad_cone = shape.extrude_profile(profile.Profile([0,self.zsize],[a*2,b*2],[a*2,b*2]), cross_section=lambda d: shape.circle(d,16)) pad_cylinder = shape.extrude_profile(profile.Profile([0,self.zsize+bit_diameter],[a*2,a*2],[a*2,a*2]), cross_section=lambda d: shape.circle(d,16)) pad = 0.5 + self.zsize/10.0 upper = shape.block(-pad,xsize+pad,-pad,ysize+pad,0,self.zsize) print 'Cut holes' for i,(x,y,packable) in enumerate(self.items): if packable.use_upper: flat = packable.mask.to_3() flat.move(x,y,0) minsum = flat.minkowski_sum(pad_cone) upper.remove( minsum ) print 'Put things in them' for x,y,packable in self.items: if packable.use_upper: temp = packable.shapes[0].copy() temp.move(x,y,0) upper.add(temp) bol = int(self.xsize / 10.0) bol_width = 1.0 # 0.5 seemed to allow shifting on a sop flute bol_height = 1.0 # 0.5 was too low, middle piece tore loose in final pass of # contour finishing (x-scan of horizontal-like surfaces) xmins = [ x for x,y,packable in self.items ] xmaxs = [ x+packable.extent.xmax for x,y,packable in self.items ] margin = bol_width+bit_diameter+0.25 potential_bols = [ ((i+0.5)*xsize/bol, 0,ysize) for i in xrange(bol) ] bols = [ ] while potential_bols: pos, y_low, y_high = potential_bols.pop() for i, (x,y,packable) in enumerate(self.items): if pos-margin <= xmins[i] <= pos+margin or \ pos-margin <= xmaxs[i] <= pos+margin: low = y-bit_diameter high = y+packable.extent.ymax+bit_diameter if low <= y_low and y_high <= high: break elif y_low < low and high < y_high: potential_bols.append((pos, y_low, low)) potential_bols.append((pos, high, y_high)) break elif y_low < low < y_high <= high: potential_bols.append((pos, y_low, low)) break elif low < y_low < high <= y_high: potential_bols.append((pos, high, y_high)) break else: bols.append((pos,y_low,y_high)) for pos, y_low, y_high in bols: upper.add(shape.block( pos-bol_width*0.5, pos+bol_width*0.5, y_low, y_high, #0,ysize, #-bit_diameter*0.6, bol_height, 0,bol_height, )) print 'Underside' # Cut the bottom of upper with lower, to depth bit_diameter lower = shape.block(-pad,xsize+pad,-pad,ysize+pad,bit_diameter,self.zsize) lower.add(upper) print 'Remove bores' for x,y,packable in self.items: temp = packable.shapes[1].copy() temp.move(x,y,0) flat = packable.mask.to_3() flat.move(x,y,0) minsum = flat.minkowski_sum(pad_cylinder) temp.clip(minsum) lower.remove(temp) lower.rotate(0,1,0, 180) return lower, upper
def run(self): zsize = self.thickness pad = self.wall diameter = zsize - pad*2 self.log.log('Thickness: %.1fmm\n' % zsize) self.log.log('Min wall thickness: %.1fmm\n' % pad) self.log.log('Hole diameter: %.1fmm\n' % diameter) negatives = [ ] lengths = [ ] xs = [ ] for i, note in enumerate(SCALE): print 'Make hole %d / %d' % (i+1,len(SCALE)) length = design.wavelength(note,self.transpose)*0.25 + LENGTH_CORRECTION*diameter x = i*(diameter+pad) lengths.append(length) xs.append(x) hole = make_hole(diameter, length) hole.move(x,0,0) negatives.append(hole) string_hole_diameter = diameter*1.5 string_hole_loop = shape.circle(string_hole_diameter) string_hole = shape.extrusion([-zsize,zsize],[string_hole_loop,string_hole_loop]) string_hole.rotate(1,0,0, 90) xlow = xs[0]-zsize #xmid = xs[-1]*0.5 xhigh = xs[-1]+zsize zhigh = lengths[0]+zsize*0.5 #zmid = max(lengths[-1]+zsize*0.5, zhigh-(xhigh-xmid)) trim = min(xhigh-xlow,zhigh) * 0.5 #string_x = (xmid+xhigh)*0.5 - diameter #string_z = (zmid+zhigh)*0.5 - diameter #string_z = lengths[3] + diameter*2 #string_x = xhigh-trim*0.5-diameter #string_z = zhigh-trim*0.5-diameter a = math.pi*-5/8 d = diameter * 1.5 string_x = xhigh-trim + math.cos(a)*d string_z = zhigh + math.sin(a)*d string_hole.move(string_x,0,string_z) #p = pad*0.5 #loop = shape.Loop([(0,p),(p*2,-p),(-p*2,p)]) #r = diameter-pad #stick = shape.extrusion([-r,r],[loop,loop]) # #for i in xrange(-1,len(SCALE)+2): # for j in xrange(int(zhigh / (diameter+pad))+1): # x = (i-0.5)*(diameter+pad) # z = r + j*(diameter+pad) # c = stick.copy() # if (i^j)&1: # c.rotate(0,1,0,90) # c.move(x,-diameter*0.5-pad,z) # negatives.append(c) loop = shape.Loop([ (xlow,0), (xhigh,0), (xhigh,zhigh-trim), (xhigh-trim,zhigh), (xlow,zhigh) ]) bev = zsize / 4.0 loop_bevel = shape.Loop([ (xlow,bev), (xhigh,bev), (xhigh,zhigh-trim), (xhigh-trim,zhigh), (xlow,zhigh) ]) #mask = loop.mask(RES) #amount = diameter * 0.5 #op = shape.circle(amount).mask(RES) #mask = mask.open(op) #loop = mask.trace(RES)[0] #sloop = mask.erode(op).trace(RES)[0] #z1 = zsize*0.5-amount z2 = zsize*0.5 #positive = shape.extrusion([-z2,z2],[loop,loop]) positive = shape.extrusion([-z2,-z2+bev,z2-bev,z2],[loop_bevel,loop,loop,loop_bevel]) positive.rotate(1,0,0,90) negative = string_hole.copy() for i, item in enumerate(negatives): print 'Merge %d / %d' % (i+1,len(negatives)) negative.add(item) del negatives instrument = positive.copy() print 'Remove holes from instrument' instrument.remove(negative) del positive del negative instrument.rotate(1,0,0,90) extent = instrument.extent() copy = instrument.copy() copy.rotate(0,0,1,-45) cextent = copy.extent() copy.move(-(cextent.xmin+cextent.xmax)*0.5, -(cextent.ymin+cextent.ymax)*0.5, -cextent.zmin) self.save(copy,'instrument') del copy top = shape.block( extent.xmin-1,extent.xmax+1, extent.ymin-1,extent.ymax+1, 0,extent.zmax+1 ) bottom = shape.block( extent.xmin-1,extent.xmax+1, extent.ymin-1,extent.ymax+1, extent.zmin-1,0 ) top.clip(instrument) bottom.clip(instrument) top.rotate(1,0,0,180) top.move(0,4,0) bottom.add(top) pattern = bottom del top del bottom pattern.move(0,0,z2) pattern.rotate(0,0,1, -90) bit_pad = 4.0 extra_depth = 3.0 a = bit_pad b = bit_pad + z2/10.0 pad_cone = shape.extrude_profile(profile.Profile( [-extra_depth,0,z2],[a*2,a*2,b*2] ), cross_section=lambda d: shape.circle(d,16)) extra = b + 0.5 extent = pattern.extent() mill = shape.block( extent.xmin-extra, extent.xmax+extra, extent.ymin-extra, extent.ymax+extra, -extra_depth, z2, ) mill.remove( pattern.polygon_mask().to_3().minkowski_sum(pad_cone) ) mill.add( pattern ) del pad_cone del pattern self.save(mill, 'mill')
def nanowire_binary(number, width, pitch, length, n, m, is_interrupt, device_shape, pals_length, itr, elec_width, pin_length=60): """ 用于绘制任意大小,并联根数的纳米线版图,python版本:2.7.14,3.3,只画方形器件 长度单位:μm width 单根纳米线宽度 length 纳米线长度,同时是纳米线区域的半径 pitch 纳米线周期宽度 itr 计数纳米线根数 n:并联纳米线根数 m:二级并联根数 pals_length:二级并联长度 elec_width MA6光刻电极宽度 """ length = float(length) width = float(width) pitch = float(pitch) n = int(n) is_interrupt = int(is_interrupt) device_shape = int(device_shape) pals_length = float(pals_length) elec_width = int(elec_width) pin_length = float(pin_length) minedge = 10 maxdiameter = length + 2 * minedge #外围结构为5um,设置纳米线电子束曝光尺寸大小 Cellname = "nanowire" + str(itr) single_cell = gdspy.Cell(Cellname, exclude_from_current=True) mark = itr #gdspy.GdsLibrary.add(single_cell,overwrite_duplication = True) if is_interrupt == 1 and pals_length < pitch - width: print("并联长度过小") return single_cell if length + minedge > maxdiameter: print("纳米线长度设置应小于等于50μm") return single_cell #返回空的cell if is_interrupt == 1 and pals_length > length: print("纳米线并联长度应小于直径") return single_cell #返回空的cell total = int(length / pitch) """ #根据并联纳米线根数和纳米线间距来微调纳米线直径 """ if n < 1 or m < 1: print("纳米线小于1,n应该>=1") return single_cell elif type(n) == float: print('纳米线并联数应为>=1的整数') return single_cell unnece = total % (n * m) #多余的纳米线根数 itr = int(total / n / m) #纳米线周期 if unnece > int(n / 2): total = (itr + 1) * n * m else: total = itr * n * m a = (elec_width - length) / pin_length / 2 if a - int(a) > 0.8: a = int(a) + 2 else: a = int(a) + 1 oldl = length length = total * pitch print("对纳米线" + Cellname + "长度进行了微调:原始值{},微调后值{},".format(oldl, total * pitch)) # length = total*pitch # total1 = total half = total / 2 """ 绘制纳米线核心区域 两步绘制: 计算调整圆的直径,确定圆的刻蚀线终点 1 绘制中心圆区域 2,绘制隔离线 """ #步骤一1 if device_shape == 0: edge = shape.circle(pitch * total, width, pitch, total, half) # iso = shape.circleiso(length,width,n) # equ_area = shape.circle_equ(length,maxdiameter,width,pitch,total,half) elif device_shape == 1: edge = shape.squire(pitch * total, width, pitch, total, half) # iso = shape.squireiso(length,width,n) # equ_area = shape.squire_equ(length,maxdiameter,width,pitch,total,half) # single_cell.add(iso[0]) # single_cell.add(iso[1]) # # #绘制外围等效曝光区 # for i in equ_area: # for j in i: # single_cell.add(gdspy.Rectangle(*j,layer = 1,datatype = 1)) # #纳米线核心区域点阵 startpoint = edge[0] finalpoint = edge[1] i = 0 location = numpy.linspace(0, total, int(total / n) + 1) #二级并联线位置 location1 = numpy.linspace(0, total, int(total / n / m) + 1) #隔离线位置 j = 1.0 #direction max_length = 0 m1 = m while i < len(startpoint) - n * 2: #调整并联单元长度相等 m = 0 while m < n and i < len(startpoint): if i == 0: #保证0点的线存在 startpoint[i] = (startpoint[i - m + 1][0], startpoint[i][1]) finalpoint[i] = (finalpoint[i - m + 1][0], finalpoint[i][1]) startpoint[i] = (startpoint[i - m][0], startpoint[i][1]) finalpoint[i] = (finalpoint[i - m][0], finalpoint[i][1]) m = m + 1 i = i + 1 i = 0 while i < len(startpoint): #计算最大圆直径 if is_interrupt == 1 and n > 1: step = pals_length # single_length = abs(finalpoint[i][0] - startpoint[i][0]) if (int(single_length / step) + 1) * step - length < n * pitch: single_length = int(single_length / step + 1) * step else: single_length = int(single_length / step) * step if numpy.sqrt(single_length**2 / 4 + startpoint[i][1]**2 ) > max_length and device_shape == 0: #圆形的隔离圆大小需要修改 max_length = numpy.sqrt( (single_length**2 / 4 + startpoint[i][1]**2)) startpoint[i] = (-single_length / 2, startpoint[i][1]) finalpoint[i] = (single_length / 2, finalpoint[i][1]) i = i + 1 max_length = 2 * max_length if max_length < pitch * total: max_length = pitch * total #保证外切圆直径为离散值后的最大直径 maxdiameter = max_length + 2 * minedge #调整最大曝光区域 if maxdiameter <= pin_length: maxdiameter = pin_length i = 0 while i < len(startpoint): #i=0,和total对应在x=0位置 if 0 == 1: j = -j else: #每隔30um绘制一个断点 if is_interrupt == 1 and n > 1: step = pals_length # k = 0 if i not in location: while (k + 1) * step < finalpoint[i][0] - startpoint[i][0]: steppoint1 = (startpoint[i][0] + k * step, startpoint[i][1]) steppoint2 = (startpoint[i][0] + (k + 1) * step - width * (n - 1), finalpoint[i][1]) polym = gdspy.Rectangle(steppoint1, steppoint2, layer=1, datatype=1) polym.fillet(pitch - width, points_per_2pi=20) single_cell.add(polym) k = k + 1 else: steppoint1 = (startpoint[i][0] + k * step, startpoint[i][1]) steppoint2 = finalpoint[i] polym = gdspy.Rectangle(steppoint1, steppoint2, layer=1, datatype=1) polym.fillet(pitch - width, points_per_2pi=20) single_cell.add(polym) else: if i not in location: polym = gdspy.Rectangle(startpoint[i], finalpoint[i], layer=1, datatype=1) polym.fillet((pitch - width) / 2, points_per_2pi=20) single_cell.add(polym) if i in location: if i in location1: startpoint[i] = (j * startpoint[i][0], startpoint[i][1]) if device_shape == 0: finalpoint[i] = (j * numpy.sqrt((max_length / 2 + 3)**2 - ((half - i) * pitch)**2), finalpoint[i][1]) elif device_shape == 1: finalpoint[i] = (j * (max_length / 2 + 3), finalpoint[i][1]) j = -j polym = gdspy.Rectangle(startpoint[i], finalpoint[i], layer=1, datatype=1) polym.fillet((pitch - width) / 2, points_per_2pi=20) single_cell.add(polym) i = i + 1 if device_shape == 0: iso = shape.circleiso(max_length, width, n) equ_area = shape.circle_equ(max_length, maxdiameter, width, pitch, total, half) elif device_shape == 1: iso = shape.squireiso(max_length, width, n) equ_area = shape.squire_equ(max_length, maxdiameter, width, pitch, total, half) single_cell.add(iso[0]) single_cell.add(iso[1]) #绘制外围等效曝光区 layer = {'layer': 1, 'datatype': 1} #定义图层 for i in equ_area: for j in i: single_cell.add(gdspy.Rectangle(*j, **layer)) #纳米线核心区域点阵 startpoint = edge[0] finalpoint = edge[1] """ 电极线结构 pitch 纳米线间距,即周期 width:纳米线宽度 length 纳米线长度,电极宽度设置为2um,在并联纳米线总宽宽度>1μm后, 电极宽度调整为(n+4)*width 预曝光区域,宽度设置为5μm 曝光长度设置为length/2+5,pitch与纳米线一致 """ length = max_length #将length改为划出纳米线调整后的最大直径 total = int((maxdiameter / 2 - length / 2 - 1) / pitch) i = 0 m = m1 if n * m * width >= 1: half_elecwidth = (n * m + 4) * width else: half_elecwidth = 1 old = half_elecwidth while i <= total - 1: if i <= int(n * m * width / pitch) + 1: half_elecwidth = max_length / 2 + 3 else: half_elecwidth = old elec1 = gdspy.Rectangle( (half_elecwidth, i * pitch + length / 2), (maxdiameter / 2, i * pitch + length / 2 + pitch - width), **layer) single_cell.add(elec1) elec2 = gdspy.Rectangle( (-half_elecwidth, i * pitch + length / 2), (-maxdiameter / 2, i * pitch + length / 2 + pitch - width), **layer) single_cell.add(elec2) elec3 = gdspy.Rectangle( (-half_elecwidth, (-i - 1) * pitch - length / 2), (-maxdiameter / 2, -i * pitch - length / 2 - (pitch - width)), **layer) single_cell.add(elec3) elec4 = gdspy.Rectangle( (half_elecwidth, (-i - 1) * pitch - length / 2), (maxdiameter / 2, -i * pitch - length / 2 - (pitch - width)), **layer) single_cell.add(elec4) i = i + 1 """ 隔离线,宽度1um,伸出纳米线区域elec_width/2+pin_ength """ # length = oldl #需要原始直径值 if elec_width / 2 > length / 2 + pin_length - 10: a = (elec_width / 2 - length / 2 - pin_length) / pin_length if a - int(a) > 0.9: a = int(a) + 2 else: a = int(a) + 1 halflen = pin_length * (a + 1) + length / 2 else: halflen = length / 2 + pin_length edgelen = maxdiameter / 2 #纳米线区域边界 insulate1 = gdspy.Rectangle((half_elecwidth, edgelen - 1), (halflen, edgelen), **layer) single_cell.add(insulate1) insulate2 = gdspy.Rectangle((-half_elecwidth, edgelen - 1), (-halflen, edgelen), **layer) single_cell.add(insulate2) insulate3 = gdspy.Rectangle((-half_elecwidth, -edgelen + 1), (-halflen, -edgelen), **layer) single_cell.add(insulate3) insulate4 = gdspy.Rectangle((half_elecwidth, -edgelen + 1), (halflen, -edgelen), **layer) single_cell.add(insulate4) insulate5 = gdspy.Rectangle((edgelen - 1, halflen), (edgelen, -halflen), **layer) single_cell.add(insulate5) insulate6 = gdspy.Rectangle((-edgelen + 1, halflen), (-edgelen, -halflen), **layer) single_cell.add(insulate6) """ 绘制拼接场外围尺寸,固定等效曝光区域宽10μm 位置在边界处:pin_length-minedge """ """ length = oldl # oldl=原始length,保证被整场分割而不滑移。允许出现边界处拼接场存在。 layer_useless = {'layer': 3, 'datatype': 3} out = gdspy.Rectangle((-length / 2 - pin_length, -maxdiameter / 2), # 左边 (-length / 2 - pin_length + 1, maxdiameter / 2), **layer_useless ) single_cell.add(out) out = gdspy.Rectangle((length / 2 + pin_length, -maxdiameter / 2), # 右边 (length / 2 + pin_length - 1, maxdiameter / 2), **layer_useless ) single_cell.add(out) out = gdspy.Rectangle((-maxdiameter / 2, length / 2 + pin_length), # 上左 (-half_elecwidth, length / 2 + pin_length - 1), **layer_useless ) single_cell.add(out) out = gdspy.Rectangle((maxdiameter / 2, length / 2 + pin_length), # 上右 (half_elecwidth, length / 2 + pin_length - 1), **layer_useless ) single_cell.add(out) out = gdspy.Rectangle((-maxdiameter / 2, -length / 2 - pin_length), # 下左 (-half_elecwidth, -length / 2 - pin_length + 1), **layer_useless ) single_cell.add(out) out = gdspy.Rectangle((maxdiameter / 2, -length / 2 - pin_length), # 下右 (half_elecwidth, -length / 2 - pin_length + 1), **layer_useless ) single_cell.add(out) """ """ 对准标记 4umX100μm大小十字 位置,-500um,500um """ markers = [1, 9, 41, 73, 81] if mark in markers: cross = gdspy.Rectangle((-450, 498), (-550, 502), **layer) single_cell.add(cross) cross = gdspy.Rectangle((-498, 450), (-502, 550), **layer) single_cell.add(cross) """ 编号 """ text = gdspy.Text(str(number), 20, (1000, 300), **layer) single_cell.add(text) merged = gdspy.fast_boolean(gdspy.Rectangle( (-maxdiameter / 2, -maxdiameter / 2), (maxdiameter / 2, maxdiameter / 2)), gdspy.CellReference(single_cell), 'not', max_points=190) # Offset the path shape by 0.5 and add it to the cell. single_cell.add(merged) return single_cell
#loops = [ loop ] #for line in process.stdout: # parts = line.rstrip().split() # if parts[0] != 'TYPE:': continue # assert parts[2] == 'X:' and parts[4] == 'Y:' # if parts[1] == '2': continue # if parts[1] == '3': # loop = [ ] # loops.append(loop) # loop.append( (0.5+mask.x+int(parts[3])*0.01,0.5+mask.y+int(parts[5])*0.01) ) #return [ shape.Loop(item[::-1]) for item in loops ] if __name__ == '__main__': import shape loop = shape.Loop(shape.circle(50.0)[:50]) with open('/tmp/test.pbm', 'wt') as f: write_pbm(f, loop.mask(1.0).data) print(max(x for x, y in loop) - min(x for x, y in loop)) for i in range(10): mask = loop.mask(1.0) with open('/tmp/test2.pbm', 'wt') as f: write_pbm(f, mask.data) [loop] = trace(mask) print(max(x for x, y in loop), min(x for x, y in loop)) print(max(y for x, y in loop), min(y for x, y in loop)) print() #print( min(x for x,y in loop) ) #mask[5,5] = 0 with open('/tmp/test2.pbm', 'wt') as f: write_pbm(f, mask.data)
def run(self): zsize = self.thickness pad = self.wall diameter = zsize - pad * 2 self.log.log('Thickness: %.1fmm\n' % zsize) self.log.log('Min wall thickness: %.1fmm\n' % pad) self.log.log('Hole diameter: %.1fmm\n' % diameter) negatives = [] lengths = [] xs = [] for i, note in enumerate(SCALE): print 'Make hole %d / %d' % (i + 1, len(SCALE)) length = design.wavelength( note, self.transpose) * 0.25 + LENGTH_CORRECTION * diameter x = i * (diameter + pad) lengths.append(length) xs.append(x) hole = make_hole(diameter, length) hole.move(x, 0, 0) negatives.append(hole) string_hole_diameter = diameter * 1.5 string_hole_loop = shape.circle(string_hole_diameter) string_hole = shape.extrusion([-zsize, zsize], [string_hole_loop, string_hole_loop]) string_hole.rotate(1, 0, 0, 90) xlow = xs[0] - zsize #xmid = xs[-1]*0.5 xhigh = xs[-1] + zsize zhigh = lengths[0] + zsize * 0.5 #zmid = max(lengths[-1]+zsize*0.5, zhigh-(xhigh-xmid)) trim = min(xhigh - xlow, zhigh) * 0.5 #string_x = (xmid+xhigh)*0.5 - diameter #string_z = (zmid+zhigh)*0.5 - diameter #string_z = lengths[3] + diameter*2 #string_x = xhigh-trim*0.5-diameter #string_z = zhigh-trim*0.5-diameter a = math.pi * -5 / 8 d = diameter * 1.5 string_x = xhigh - trim + math.cos(a) * d string_z = zhigh + math.sin(a) * d string_hole.move(string_x, 0, string_z) #p = pad*0.5 #loop = shape.Loop([(0,p),(p*2,-p),(-p*2,p)]) #r = diameter-pad #stick = shape.extrusion([-r,r],[loop,loop]) # #for i in xrange(-1,len(SCALE)+2): # for j in xrange(int(zhigh / (diameter+pad))+1): # x = (i-0.5)*(diameter+pad) # z = r + j*(diameter+pad) # c = stick.copy() # if (i^j)&1: # c.rotate(0,1,0,90) # c.move(x,-diameter*0.5-pad,z) # negatives.append(c) loop = shape.Loop([(xlow, 0), (xhigh, 0), (xhigh, zhigh - trim), (xhigh - trim, zhigh), (xlow, zhigh)]) bev = zsize / 4.0 loop_bevel = shape.Loop([(xlow, bev), (xhigh, bev), (xhigh, zhigh - trim), (xhigh - trim, zhigh), (xlow, zhigh)]) #mask = loop.mask(RES) #amount = diameter * 0.5 #op = shape.circle(amount).mask(RES) #mask = mask.open(op) #loop = mask.trace(RES)[0] #sloop = mask.erode(op).trace(RES)[0] #z1 = zsize*0.5-amount z2 = zsize * 0.5 #positive = shape.extrusion([-z2,z2],[loop,loop]) positive = shape.extrusion([-z2, -z2 + bev, z2 - bev, z2], [loop_bevel, loop, loop, loop_bevel]) positive.rotate(1, 0, 0, 90) negative = string_hole.copy() for i, item in enumerate(negatives): print 'Merge %d / %d' % (i + 1, len(negatives)) negative.add(item) del negatives instrument = positive.copy() print 'Remove holes from instrument' instrument.remove(negative) del positive del negative instrument.rotate(1, 0, 0, 90) extent = instrument.extent() copy = instrument.copy() copy.rotate(0, 0, 1, -45) cextent = copy.extent() copy.move(-(cextent.xmin + cextent.xmax) * 0.5, -(cextent.ymin + cextent.ymax) * 0.5, -cextent.zmin) self.save(copy, 'instrument') del copy top = shape.block(extent.xmin - 1, extent.xmax + 1, extent.ymin - 1, extent.ymax + 1, 0, extent.zmax + 1) bottom = shape.block(extent.xmin - 1, extent.xmax + 1, extent.ymin - 1, extent.ymax + 1, extent.zmin - 1, 0) top.clip(instrument) bottom.clip(instrument) top.rotate(1, 0, 0, 180) top.move(0, 4, 0) bottom.add(top) pattern = bottom del top del bottom pattern.move(0, 0, z2) pattern.rotate(0, 0, 1, -90) bit_pad = 4.0 extra_depth = 3.0 a = bit_pad b = bit_pad + z2 / 10.0 pad_cone = shape.extrude_profile( profile.Profile([-extra_depth, 0, z2], [a * 2, a * 2, b * 2]), cross_section=lambda d: shape.circle(d, 16)) extra = b + 0.5 extent = pattern.extent() mill = shape.block( extent.xmin - extra, extent.xmax + extra, extent.ymin - extra, extent.ymax + extra, -extra_depth, z2, ) mill.remove(pattern.polygon_mask().to_3().minkowski_sum(pad_cone)) mill.add(pattern) del pad_cone del pattern self.save(mill, 'mill')
pygame.display.set_caption('Hex') # Set display size = width, height = (601,301) screen = pygame.display.set_mode(size,pygame.RESIZABLE) pygame.event.post( pygame.event.Event(pygame.VIDEORESIZE, {'size': size})) while exit != True: event = pygame.event.wait() if (event.type == pygame.QUIT) or ((event.type == pygame.KEYDOWN) and (event.key == pygame.K_q)): exit = True elif event.type == pygame.VIDEORESIZE: screen = pygame.display.set_mode(event.size,pygame.RESIZABLE) size = width, height = event.size elif event.type == pygame.MOUSEBUTTONDOWN: pass else: continue # Load background size = width, height = screen.get_size() background = pygame.Surface(size) background = background.convert() background.fill((0,0,50)) mygrid = newgrid(shape.circle(3), (width - 20, height - 20)) screen.blit(background, (0,0)) screen.blit(mygrid.surface, (10,10)) pygame.display.flip() sys.exit()
#!usr/bin/python3 import shape a = shape.Point() print(repr(a)) b = shape.Point(3,4) print(str(b)) print("{0}".format(b.distance_from_origin())) b.x = -19 print(str(b)) p = shape.Point(28, 45) c = shape.circle(5, 28, 45) print(p.distance_from_origin()) print(c.distance_from_origin())
# for line in process.stdout: # parts = line.rstrip().split() # if parts[0] != 'TYPE:': continue # assert parts[2] == 'X:' and parts[4] == 'Y:' # if parts[1] == '2': continue # if parts[1] == '3': # loop = [ ] # loops.append(loop) # loop.append( (0.5+mask.x+int(parts[3])*0.01,0.5+mask.y+int(parts[5])*0.01) ) # return [ shape.Loop(item[::-1]) for item in loops ] if __name__ == "__main__": import shape loop = shape.Loop(shape.circle(50.0)[:50]) with open("/tmp/test.pbm", "wt") as f: write_pbm(f, loop.mask(1.0).data) print(max(x for x, y in loop) - min(x for x, y in loop)) for i in range(10): mask = loop.mask(1.0) with open("/tmp/test2.pbm", "wt") as f: write_pbm(f, mask.data) [loop] = trace(mask) print(max(x for x, y in loop), min(x for x, y in loop)) print(max(y for x, y in loop), min(y for x, y in loop)) print() # print( min(x for x,y in loop) ) # mask[5,5] = 0 with open("/tmp/test2.pbm", "wt") as f: write_pbm(f, mask.data)
import shape r = (int(input("enter radious:"))) obj = shape.circle(r) obj.area(r)
import shape if __name__ == '__main__': cerchio = shape.circle(10) pentagono = shape.pentagons(5) rettangolo = shape.rectangle(5,2) quadrato = shape.square(2) triangolo = shape.triangoloeq(3) listOfShapes = [cerchio, pentagono, rettangolo, quadrato, triangolo] print(listOfShapes) print(cerchio.calculate_area(), pentagono.calculate_area(), rettangolo.calculate_area(), quadrato.calculate_area(), triangolo.calculate_area()) print([x.calculate_area() for x in shape.shape.sortarea(listOfShapes)])
def render(self, bit_diameter, bit_pad): xsize = self.xsize ysize = self.ysize a = bit_pad b = bit_pad + self.zsize / 10.0 pad_cone = shape.extrude_profile( profile.Profile([0, self.zsize], [a * 2, b * 2], [a * 2, b * 2]), cross_section=lambda d: shape.circle(d, 16)) pad_cylinder = shape.extrude_profile( profile.Profile([0, self.zsize + bit_diameter], [a * 2, a * 2], [a * 2, a * 2]), cross_section=lambda d: shape.circle(d, 16)) pad = 0.5 + self.zsize / 10.0 upper = shape.block(-pad, xsize + pad, -pad, ysize + pad, 0, self.zsize) print 'Cut holes' for i, (x, y, packable) in enumerate(self.items): if packable.use_upper: flat = packable.mask.to_3() flat.move(x, y, 0) minsum = flat.minkowski_sum(pad_cone) upper.remove(minsum) print 'Put things in them' for x, y, packable in self.items: if packable.use_upper: temp = packable.shapes[0].copy() temp.move(x, y, 0) upper.add(temp) bol = int(self.xsize / 10.0) bol_width = 1.0 # 0.5 seemed to allow shifting on a sop flute bol_height = 1.0 # 0.5 was too low, middle piece tore loose in final pass of # contour finishing (x-scan of horizontal-like surfaces) xmins = [x for x, y, packable in self.items] xmaxs = [x + packable.extent.xmax for x, y, packable in self.items] margin = bol_width + bit_diameter + 0.25 potential_bols = [((i + 0.5) * xsize / bol, 0, ysize) for i in xrange(bol)] bols = [] while potential_bols: pos, y_low, y_high = potential_bols.pop() for i, (x, y, packable) in enumerate(self.items): if pos-margin <= xmins[i] <= pos+margin or \ pos-margin <= xmaxs[i] <= pos+margin: low = y - bit_diameter high = y + packable.extent.ymax + bit_diameter if low <= y_low and y_high <= high: break elif y_low < low and high < y_high: potential_bols.append((pos, y_low, low)) potential_bols.append((pos, high, y_high)) break elif y_low < low < y_high <= high: potential_bols.append((pos, y_low, low)) break elif low < y_low < high <= y_high: potential_bols.append((pos, high, y_high)) break else: bols.append((pos, y_low, y_high)) for pos, y_low, y_high in bols: upper.add( shape.block( pos - bol_width * 0.5, pos + bol_width * 0.5, y_low, y_high, #0,ysize, #-bit_diameter*0.6, bol_height, 0, bol_height, )) print 'Underside' # Cut the bottom of upper with lower, to depth bit_diameter lower = shape.block(-pad, xsize + pad, -pad, ysize + pad, bit_diameter, self.zsize) lower.add(upper) print 'Remove bores' for x, y, packable in self.items: temp = packable.shapes[1].copy() temp.move(x, y, 0) flat = packable.mask.to_3() flat.move(x, y, 0) minsum = flat.minkowski_sum(pad_cylinder) temp.clip(minsum) lower.remove(temp) lower.rotate(0, 1, 0, 180) return lower, upper