示例#1
0
def intersectionTest():
    c1 = -circle(Vector(0,0), 1)
    c2 = -circle(Vector(1,1), 1.5)
    c3 = -circle(Vector(0,0), .5)
    r1 = rect(Vector(-1,-1), Vector(1,1))
    
#    print c1.area()
#    print c2.area()
#    print c3.area()
#    
#    c1.plot()
#    c2.plot()
#    
#    (c1.union(c2) + Vector(4,0)).plot()
#    (c2.union(c1) + Vector(8,0)).plot()
#    (c1.union(-c2) + Vector(12,0)).plot()
#    (c2.union(-c1) + Vector(16,0)).plot()
#    (c3.intersect(c1) + Vector(20,0)).plot()
    (c3.intersect(r1)).plot()

#    print rect(Vector(3,3), Vector(6,6))
#    print rect(Vector(6,3), Vector(12,6))

#    (rect(Vector(3,3), Vector(6,6)).union(rect(Vector(6,3), Vector(12,6))) + Vector(12,0)).plot()
#    (rect(Vector(6,2), Vector(12,6)).union(rect(Vector(3,3), Vector(6,7))) + Vector(0,0)).plot()
    return None
示例#2
0
 def show(self, delta):
     if self.best:
         color = (0, 255, 0)
     else:
         color = (0, 0, 255)
     x = self.genes[0] * delta[1] + delta[0]
     y = self.genes[1] * delta[1] + delta[0]
     circle(x, y, radius=5, color=color)
示例#3
0
 def show(self, scale, offset):
     for x, y in self:
         if y == 1.0:
             circle(x[0] * scale + offset, x[1] * scale + offset, 5)
         else:
             circle(x[0] * scale + offset,
                    x[1] * scale + offset,
                    5,
                    color=(0, 255, 0))
 def setUp(self):
     super().setUp()
     triples = {"has_name": "circle", "has_shape": "circle"}
     self.circle_right: List[Block] = list(
         self.add_object(xyzbms=shapes.circle(bid=(42, 0)),
                         origin=(2, 63, 4),
                         relations=triples).blocks.items())
     self.set_looking_at(self.circle_right[0][0])
	def fshape(i, j) : 
		a = shapes.circle(2)
		if i in (9,10,11) and j == 10 : return None
		if i == 2 and j == 2 : 
			a.setradius(.2)
			a.position = [.1,.1]
		else : 
			a.setradius(.3)
		return a
示例#6
0
	def fshape(i, j) : 
		a = shapes.circle(2)
		if i == 2 and j == 2 : 
			a.setradius(1)
			a.position = [2, 2]
		#else : 
			#a.position = [0, 0]
		a.space = [5, 5]
		return a
示例#7
0
def on_draw():
    glPushMatrix()
    glViewport(0, 0, window.width, window.height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0, dim, 0, dim, -1, 1)
    glMatrixMode(GL_MODELVIEW)
    #
    window.clear()
    shapes.cartesian(dim, dim, delta)
    shapes.grid(dim, dim, delta)
    pop.show()
    #prints the optimal point
    shapes.circle(x=optimal[0] * dim / delta + dim / 2,
                  y=optimal[1] * dim / delta + dim / 2,
                  radius=5,
                  color=(255, 0, 0))
    #
    glPopMatrix()
示例#8
0
def scene():

    s = shapes.Square()
    s.setColor( (0.3, 0.5, 0.3) )
    s.draw(-400, -1000, scale=8, orientation=90)

    s = shapes.Square()
    s.setColor( (0.3, 0.5, 0.3) )
    s.draw(0, -100, scale=0.8, orientation=90)


    s = shapes.Square()
    s.setColor( (0.5, 0.6, 0.6) )
    s.draw(-100, -100, scale=2, orientation=90)

    t = shapes.Triangle()
    t.setColor( (0.5, 0.4, 0.4) )
    t.draw(100, 100, scale=2, orientation=180)


    #create the first shape hexagon
    h = shapes.circle()
    h.setColor( (0.4, 0.4, 0.2) )
    h.draw( -300, 350, scale=0.5, orientation=12 )

    # #create the first shape hexagon
    # h = shapes.circle()
    # h.setColor( (0.6, 0.5, 0.1) )
    # h.draw( 0, 300, scale=0.5, orientation=12 )

    # tr = tree.Tree( distance=5, angle=22.5, color=(0.5, 0.4, 0.3), iterations=3, filename=None )
    tr = tree.Tree( filename='systemH.txt') # asign tr to the tree object 
    tr.setColor( (0.5, 0.3, 0.4) )
    tr.draw(-300, -200, scale=2, orientation=90)

    # tr = tree.Tree( distance=5, angle=22.5, color=(0.5, 0.4, 0.3), iterations=3, filename=None )
    tr = tree.Tree( filename='systemH.txt') # asign tr to the tree object 
    tr.setColor( (0.5, 0.3, 0.4) )
    tr.draw(300, -200, scale=2, orientation=90)

    # # tr = tree.Tree( distance=5, angle=22.5, color=(0.5, 0.4, 0.3), iterations=3, filename=None )
    # tr = tree.Tree( filename='systemJ.txt') # asign tr to the tree object 
    # tr.setColor( (0.5, 0.3, 0.4) )
    # tr.draw(100, -75, scale=2, orientation=90)

    # # tr = tree.Tree( distance=5, angle=22.5, color=(0.5, 0.4, 0.3), iterations=3, filename=None )
    # tr = tree.Tree( filename='systemH.txt') # asign tr to the tree object 
    # tr.setColor( (0.5, 0.3, 0.4) )
    # tr.draw(-80, -75, scale=2, orientation=90)
  

      # wait
    ti.TurtleInterpreter().hold()
示例#9
0
def plot(kalman_dict, title='single navigator in flight', ax=None):
    if ax is None:
        fig, ax = plt.subplots()
    else:
        fig = ax.figure

    num_it = len(kalman_dict)
    # graphic function - shows only kalman trajectories, saves as file
    color_wheel = ['-b', '-r']
    for i in range(num_it):  #present the different kalman trajectories
        kzip = list(zip(*kalman_dict["Kalman_list{0}".format(i)]))
        kx, ky = kzip[0], kzip[1]
        slice_list = [0]  #a list of indexes of where to slice the list
        #the different lists will be presented with different colors (red/blue)
        #creating a single multicolor trajectory
        for tup in kalman_dict["Kalman_list{0}".format(i)]:
            if tup[3] == 'odor found' or tup[3] == 'odor lost':
                index = kalman_dict["Kalman_list{0}".format(i)].index(tup)
                slice_list.append(index)

        flag = False  #a marker to see if any odor was detected throughout the simulation
        for j in range(len(slice_list) - 1):
            flag = True  #in the case where len(slice_list)==1, the flag will remain flase
            xslice = kx[slice_list[j]:slice_list[j + 1] + 1]
            yslice = ky[slice_list[j]:slice_list[j + 1] + 1]
            ax.plot(xslice, yslice,
                    color_wheel[j % 2])  #choose a color from the color wheel

        #draw the final stretch of the trajectory after the last odor event
        if flag == True:
            xslice = kx[slice_list[j + 1]:]
            yslice = ky[slice_list[j + 1]:]
            ax.plot(xslice, yslice, color_wheel[(j + 1) % 2])
        else:
            ax.plot(kx, ky, '-b')

    marker = circle(500, 20, 30)
    ax.plot(marker[0], marker[1], '-r')  #add a red circle for the odor source
    ax.set_ylim(0, 1000)
    ax.set_xlim(0, 1000)
    ax.set_xlabel('X position')
    ax.set_ylabel('Y position')
    ax.set_title(title)
    plt.legend(loc='upper left')
    #plt.show()
    fig.savefig(title + '.png')
示例#10
0
def main():

    #create the first shape hexagon
    h = shapes.Hexagon()
    h.setColor((0.6, 0.8, 0.9))
    h.draw(-200, 200, scale=0.6, orientation=12)

    #create the first shape hexagon
    h = shapes.Star()
    h.setColor((0.3, 0.9, 0.9))
    h.draw(0, 200, scale=0.6, orientation=12)

    #create the first shape hexagon
    h = shapes.circle()
    h.setColor((0.3, 0.2, 0.2))
    h.draw(200, 200, scale=0.6, orientation=12)

    # wait
    turtle_interpreter.TurtleInterpreter().hold()
                            f.write(shapes.overlap_triangle(line2, num, fill, stroke))
                    elif sublist[1] == 0:
                        fill = '#c8ff72'  # green
                        stroke = '#5d8c15'
                    if overlaps == 0:
                        f.write(shapes.triangle(line1, num, fill, stroke))
                        f.write(shapes.line(line1, num, stroke))
                    elif len(edits_list) != 0:
                        line1 = 170 - (overlaps * 9)
                        f.write(shapes.overlap_triangle(line1, num, fill, stroke))
                    else:
                        line1 = 178 - (overlaps * 9)
                        f.write(shapes.overlap_triangle(line1, num, fill, stroke))

                # editable bases
                for sublist in edits_list:
                    mid1 = str(int(sublist) * 3 - 1)
                    f.write(shapes.circle(165, mid1))

                f.write('</svg>')
                print "Finished"
else:
    print "error"


# VUS strip
# path
# editable
# founder mutations for gne
# dysf -- mutations we have fibroblasts for
示例#12
0
import shapes
from turtle import mainloop

shapes.startPoint()

shapes.star(100, True, 'red')

shapes.square(100, False, 'blue')

shapes.hexagon(100, True, 'beige')

shapes.circle(100, True, 'purple')

shapes.pentagon(100, False, 'white')

shapes.octagon(100, True, 'Green')

shapes.triangle(100, True, 'yellow')

mainloop()
示例#13
0
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
示例#14
0
    shapes.cell(image, [0, x], e, 0.1)
for x in range(7, 0, -1):
    shapes.cell(
        image, [0, x],
        [randint(0, 255), randint(0, 255),
         randint(0, 255)], 0.1)
    shapes.cell(image, [0, x], e, 0.1)

# triangles
shapes.triangle(image, [0, 0], [3, 3], [0, 6], [0, 0, 255], 1)
shapes.triangle(image, [6, 0], [3, 3], [6, 6], [0, 0, 255], 1)
image = shapes.clear(image)

# moving circles
for y in range(5):
    shapes.circle(image, (3, 4), 2, w, .1)
    shapes.circle(image, (3, 4), 2, e, 0)
    shapes.circle(image, (4, 5), 3, w, .1)
    shapes.circle(image, (4, 5), 3, e, 0)
    shapes.circle(image, (5, 6), 3, w, .1)
    shapes.circle(image, (5, 6), 3, e, 0)
    shapes.circle(image, (6, 7), 3, w, .1)
    shapes.circle(image, (6, 7), 3, e, 0)
    shapes.circle(image, (7, 8), 3, w, .1)
    shapes.circle(image, (7, 8), 3, e, 0)
    shapes.circle(image, (8, 9), 3, w, .1)
    shapes.circle(image, (8, 9), 3, e, 0)
    shapes.circle(image, (1, 2), 2, w, .1)
    shapes.circle(image, (1, 2), 2, e, 0)

# colorful squares
示例#15
0
#!/opt/local/bin/python3.3
#kverdey1:ex_5_4.py:excercise 5, problem 4:python
import shapes
import sys
circle=shapes.circle(sys.argv[1])
print("area: ",circle[1])
cube=shapes.cuboid(sys.argv[2],sys.argv[3],sys.argv[4])
print("the volume is: ",cube)
示例#16
0
	myshape.addline([5, 5, 5])

	#Then we write the shape to a file. If we do not call this, the shape will
	#not be written.
	myshape.write(mydcfile)

	#Now we write something a little easier. A polyline can have any number of
	#straight edges. We can use this to write arbtitrary polygons. In this example
	#we write a triangle. Note how we use the color argument to make it blue.
	mypolyline=shapes.polyline(color=[0, 0, 1])
	mypolyline.addline([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 0, 0])
	mypolyline.write(mydcfile)

	#Circles are even easier to write. All we need to do is specify the radius.
	#If we want to change the position, we have to set the position variable.
	mycircle=shapes.circle(2,position=[-5, 0, 0])
	mycircle.setcolor([0,1,0])
	mycircle.write(mydcfile)

	#We can also write a rectangle. This is a simpler form of a polyline.
	#Again, we use position to change its location. Offset must be an array of
	#length 2 or 3. Also, this time I set the color after defining the shape.
	myrect=shapes.rectangle([3,4],position=[-5,0,0])
	myrect.setcolor([0,0,1])
	myrect.write(mydcfile)

	#To write a lattice: we define a function that returns a shape. This 
	#function must accept two arguments, which represent the row number and the 
	#column number. So if we want to change the properties of one of the 
	#circles, we can add an if statement to change it. This will change the 
	#position and the radius of the circle.
示例#17
0
        return f'{start}{points}]\n{"triangles=[":>{offset}}{triangles}]>'

    def add_static_point(self, x, y, z):
        self.static_points = np.concatenate((self.static_points, [[x, y, z]]))


def pretty_string(strings, offset=0, max_line_length=79, sep=' '):
    current_line_len = offset
    margin = ' ' * (offset)
    sep_len = len(sep)

    lines = [[]]
    current_line = lines[0]

    for string in strings:
        current_line_len += len(string)
        if current_line_len > max_line_length:
            current_line_len = offset + len(string)
            current_line = []
            lines.append(current_line)
        current_line_len += sep_len
        current_line.append(string)

    return ('\n' + margin).join(sep.join(line) for line in lines)


s = Scene(shapes.circle(1, 3))
print(s)
s.add_static_point(3, -2, 0)
print(s)
示例#18
0
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]
示例#19
0
import shapes as sh

print(sh.circle(10))
print(sh.rectangle(10, 5))
print(sh.triangle(10, 5))

print('główny - wartość zmiennnej __name__:', __name__)
示例#20
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# This source file is part of the Phogo project
# https://github.com/CRM-UAM/Phogo
# Released under the GNU General Public License Version 3
# Club de Robotica-Mecatronica, Universidad Autonoma de Madrid, Spain

from crmphogo import *

from shapes import circle, star, koch_flake

##################################################

#pen_down()
#forward()
#back()
#right()
#left()
#d = obstacle()
#print(d)
#pen_up()


#star(5, 3, 30)

circle(10.5)
#right()
forward(21)
示例#21
0
#!/opt/local/bin/python3.3
#kverdey1:ex_5_3.py:excercise 5, problem 3:python
#ex.5.3.a
import shapes
circle=shapes.circle(5)
print("area: ",circle[1])
cube=shapes.cuboid(8,8,8)
print("the volume is: ",cube)
示例#22
0
 def show(self, scale, offset):
     for x, y in self:
         circle(x * scale + offset, y * scale + offset, 5)
示例#23
0
#!usr/bin/env python3

import shapes as s

# use all of shapes' functions to print everything ontop of each other
# all parameters have defaults
# paramater order size, "color", fill, wait
s.equilateral_triangle(200, "red", True)
s.square(200, "black")
s.pentagon(120, "purple", True)
s.hexagon(120)
s.octagon(color="blue")
s.star(300, "yellow")
s.circle(wait=True)
示例#24
0
#!/opt/local/bin/python3.3
#kverdey1:ex_5_3.py:excercise 5, problem 3:python
#ex.5.3.a
import shapes
circle = shapes.circle(5)
print("area: ", circle[1])
cube = shapes.cuboid(8, 8, 8)
print("the volume is: ", cube)
示例#25
0
import shapes as sh

print(sh.circle(4))
print(sh.rectangle(4, 5))
print(sh.triangle(4, 6))
示例#26
0
def init_constructions():
    # construction lines
    circle(radout, color=DULL)
    circle(radin, color=DULL)
示例#27
0
import fields as fld
from perimeter import generate_print_path
from printer import standard_print
import shapes as shp
import math
import time

# if True:
#     for j in range(5):
#         for i in [0.005]:
#             standard_print.accuracy = i
#             start_time = time.time()
#             generate_print_path(standard_print, shp.circle(15), fld.normalized_spiral(math.pi * j/10),
#                                 min_line_separation=0.4, sorting="consecutive")
#             times = time.time() - start_time
#             print(f"Accuracy: {i} \tTime: {times:.2f}s")

for i in range(5):
    standard_print.accuracy = 0.005
    start_time = time.time()
    generate_print_path(standard_print,
                        shp.circle(25),
                        fld.normalized_spiral(math.pi * 0.4),
                        min_line_separation=0.05 * i,
                        sorting="consecutive")
    times = time.time() - start_time
    print(f"Accuracy: {i} \tTime: {times:.2f}s")
示例#28
0
import shapes


def move_pen1():
    up()
    backward(25)
    left(10)
    down()


def move_pen2():
    up()
    forward(25)
    right(10)
    down()


shapes.equilateral_triangle()
move_pen1()
shapes.square()
move_pen2()
shapes.pentagon()
move_pen1()
shapes.hexagon()
move_pen2()
shapes.octagon()
move_pen1()
shapes.star()
move_pen2()
shapes.circle()