コード例 #1
0
def rysuj():
    turtle.tracer(0, 0)  # wylaczenie animacji co KROK, w celu przyspieszenia
    turtle.hideturtle()  # ukrycie glowki zolwika
    turtle.penup() # podnosimy zolwia, zeby nie mazal nam linii podczas ruchu

    ostatnie_rysowanie = 0  # ile kropek temu zostal odrysowany rysunek

    for i in xrange(ILE_KROPEK):
        # losujemy wierzcholek do ktorego bedziemy zmierzac	
        do = random.choice(WIERZCHOLKI)
        # bierzemy nasza aktualna pozycje 
        teraz = turtle.position()
        # ustawiamy sie w polowie drogi do wierzcholka, ktorego wczesniej obralismy
        turtle.setpos(w_polowie_drogi(teraz, do))
        # stawiamy kropke w nowym miejscu
        turtle.dot(1)
        ostatnie_rysowanie += 1
        if ostatnie_rysowanie == OKRES_ODSWIEZENIA:
            # postawilismy na tyle duzo kropek, zeby odswiezyc rysunek
            turtle.update()
            ostatnie_rysowanie = 0

    pozdrowienia()

    turtle.update()
コード例 #2
0
ファイル: grelha.py プロジェクト: ernestojfcosta/IPRP
def passeio(dim, lado, passos):    
    # Prepara grelha
    turtle.speed(0)
    grelha_2(dim,lado)
    turtle.color('red')
    turtle.home()
    turtle.pendown()
    # Passeio
    turtle.speed(6)
    turtle.dot()
    turtle.showturtle()
    lim_x = lim_y = (dim*lado)//2
    cor_x = 0
    cor_y = 0
    for i in range(passos):
        vai_para = random.choice(['N','E','S','W'])
        if (vai_para == 'N') and (cor_y < lim_y):
            cor_y += lado
            turtle.setheading(90)
            turtle.fd(lado)
        elif (vai_para == 'E') and (cor_x < lim_x):
            cor_x += lado
            turtle.setheading(0)
            turtle.fd(lado)
        elif (vai_para == 'S') and (cor_y > -lim_y):
            cor_y -= lado
            turtle.setheading(270)
            turtle.fd(lado)
        elif (vai_para == 'W') and (cor_x > -lim_x):
            cor_x -= lado
            turtle.setheading(180)
            turtle.fd(lado) 
        else:
            print((vai_para,turtle.xcor(),turtle.ycor()))
            continue
コード例 #3
0
ファイル: clock.py プロジェクト: sfilata/gitskills
def SetupClock(radius):  
    # 建立表的外框  
    turtle.reset()  
    turtle.pensize(7)  
    for i in range(60):  
        Skip(radius)  
        if i % 5 == 0:  
            turtle.forward(20)  
            Skip(-radius - 20)  
             
            Skip(radius + 20)  
            if i == 0:  
                turtle.write(int(12), align="center", font=("Courier", 14, "bold"))  
            elif i == 30:  
                Skip(25)  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
                Skip(-25)  
            elif (i == 25 or i == 35):  
                Skip(20)  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
                Skip(-20)  
            else:  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
            Skip(-radius - 20)  
        else:  
            turtle.dot(5)  
            Skip(-radius)  
        turtle.right(6)  
コード例 #4
0
ファイル: sootsprite.py プロジェクト: circulocity/tp10
def drawSootSprite(N, R):
    # reset direction
    turtle.reset()
    # draw star
    drawStar(N, R)
    # draw body
    turtle.dot(0.8*2*R)
    # draw right eyeball
    turtle.fd(0.2*R)
    turtle.dot(0.3*R, 'white')
    # draw right pupil
    turtle.pu()
    turtle.bk(0.1*R)
    turtle.pd()
    turtle.dot(0.05*R)
    turtle.pu()
    # centre
    turtle.setpos(0, 0)
    # draw left eyeball
    turtle.bk(0.2*R)
    turtle.pd()
    turtle.dot(0.3*R, 'white')
    # draw left pupil
    turtle.pu()
    turtle.fd(0.1*R)
    turtle.pd()
    turtle.dot(0.05*R)

    turtle.hideturtle()
コード例 #5
0
ファイル: missile.py プロジェクト: sbihel/retrogames
def draw_stars():
	for i in range(NSTARS):
		x = random.randint(MINX, MAXX)
		y = random.randint(GROUNDY, MAXY)
		turtle.goto(x, y)
		turtle.color('white')
		turtle.dot(1)
コード例 #6
0
def render(tree, length, width):
    "Draws a given phylogenetic tree constrained by dimensions of" 
    "length and width."
    root = tree[0]
    leftTree = tree[1]
    rightTree = tree[2]
    if leftTree == (): 
        turtle.dot(10)
        turtle.write(root , font=("Arial", 20, "normal"))
        return
    else:
        turtle.dot(10)
        turtle.write(root, font=("Arial", 20, "normal"))
        turtle.left(90)
        turtle.forward(width)
        turtle.right(90)
        turtle.forward(length)
        render(leftTree, 0.5*length, 0.5*width) 
        turtle.back(length)
        turtle.left(90)
        turtle.backward(2*width)
        turtle.right(90)
        turtle.forward(length)
        render(rightTree, 0.5*length, 0.5*width)
        turtle.back(length)
        turtle.right(90)
        turtle.back(width)
        turtle.left(90)
        return
コード例 #7
0
ファイル: util.py プロジェクト: siddhi/playful_python
def draw_dot(x, y):
    goto(x, y)
    turtle.color("blue")
    if x % 2 == 1 and y % 2 == 1:
        turtle.dot(5)
    else:
        turtle.dot(3)
コード例 #8
0
def main():
  ap = ArgumentParser()
  ap.add_argument('--speed', type=int, default=10,
                  help='Number 1-10 for drawing speed, or 0 for no added delay')
  ap.add_argument('program')
  args = ap.parse_args()

  for kind, number, path in parse_images(args.program):
    title = '%s #%d, path length %d' % (kind, number, path.shape[0])
    print(title)
    if not path.size:
      continue
    pen_up = (path==0).all(axis=1)
    # convert from path (0 to 65536) to turtle coords (0 to 655.36)
    path = path / 100.
    turtle.title(title)
    turtle.speed(args.speed)
    turtle.setworldcoordinates(0, 655.36, 655.36, 0)
    turtle.pen(shown=False, pendown=False, pensize=10)
    for i,pos in enumerate(path):
      if pen_up[i]:
        turtle.penup()
      else:
        turtle.setpos(pos)
        turtle.pendown()
        turtle.dot(size=10)
    _input('Press enter to continue')
    turtle.clear()
  turtle.bye()
コード例 #9
0
ファイル: each.py プロジェクト: nadirs/pychallenge
def ex_good():
    return 9, "bull"
    # using turtle these coordinates draw a bull
    import turtle
    first = [146,399,163,403,170,393,169,391,166,386,170,381,170,371,170,355,169,346,167,335,170,329,170,320,170,
        310,171,301,173,290,178,289,182,287,188,286,190,286,192,291,194,296,195,305,194,307,191,312,190,316,
        190,321,192,331,193,338,196,341,197,346,199,352,198,360,197,366,197,373,196,380,197,383,196,387,192,
        389,191,392,190,396,189,400,194,401,201,402,208,403,213,402,216,401,219,397,219,393,216,390,215,385,
        215,379,213,373,213,365,212,360,210,353,210,347,212,338,213,329,214,319,215,311,215,306,216,296,218,
        290,221,283,225,282,233,284,238,287,243,290,250,291,255,294,261,293,265,291,271,291,273,289,278,287,
        279,285,281,280,284,278,284,276,287,277,289,283,291,286,294,291,296,295,299,300,301,304,304,320,305,
        327,306,332,307,341,306,349,303,354,301,364,301,371,297,375,292,384,291,386,302,393,324,391,333,387,
        328,375,329,367,329,353,330,341,331,328,336,319,338,310,341,304,341,285,341,278,343,269,344,262,346,
        259,346,251,349,259,349,264,349,273,349,280,349,288,349,295,349,298,354,293,356,286,354,279,352,268,
        352,257,351,249,350,234,351,211,352,197,354,185,353,171,351,154,348,147,342,137,339,132,330,122,327,
        120,314,116,304,117,293,118,284,118,281,122,275,128,265,129,257,131,244,133,239,134,228,136,221,137,
        214,138,209,135,201,132,192,130,184,131,175,129,170,131,159,134,157,134,160,130,170,125,176,114,176,
        102,173,103,172,108,171,111,163,115,156,116,149,117,142,116,136,115,129,115,124,115,120,115,115,117,
        113,120,109,122,102,122,100,121,95,121,89,115,87,110,82,109,84,118,89,123,93,129,100,130,108,132,110,
        133,110,136,107,138,105,140,95,138,86,141,79,149,77,155,81,162,90,165,97,167,99,171,109,171,107,161,
        111,156,113,170,115,185,118,208,117,223,121,239,128,251,133,259,136,266,139,276,143,290,148,310,151,
        332,155,348,156,353,153,366,149,379,147,394,146,399]
    second = [156,141,165,135,169,131,176,130,187,134,191,140,191,146,186,150,179,155,175,157,168,157,163,157,159,
        157,158,164,159,175,159,181,157,191,154,197,153,205,153,210,152,212,147,215,146,218,143,220,132,220,
        125,217,119,209,116,196,115,185,114,172,114,167,112,161,109,165,107,170,99,171,97,167,89,164,81,162,
        77,155,81,148,87,140,96,138,105,141,110,136,111,126,113,129,118,117,128,114,137,115,146,114,155,115,
        158,121,157,128,156,134,157,136,156,136]
    def pairify(l):
        return zip(l[::2], l[1::2])
    pairs = pairify(first) + pairify(second)
    for pair in pairs:
        turtle.setpos(pair)
        turtle.dot()
コード例 #10
0
def f1(x):
	turtle.penup()
	thex = x
	they = 
	turtle.goto(thex,they)
	turtle.pendown()
	turtle.dot()
	turtle.penup()
コード例 #11
0
def graphFunctionB(userFloat) :
    x = 0
    turtle.up()
    while(x <= 3) :
        y = functionB(x, userFloat)
        turtle.goto(x, y)
        turtle.dot(10, "red")
        x = x + .2
コード例 #12
0
ファイル: graphkit.py プロジェクト: Cacharani/Graph-Kit
def plotPoints(points):
	if type(points) == list:
		for x,y in points:
			toXY(x,y)
			turtle.dot(5)
	elif type(points) == tuple:
		toXY(points[0],points[1])
		turtle.dot(5)
コード例 #13
0
ファイル: radar_chart.py プロジェクト: aadeshnpn/timepass
def radar_chart(data):
    # Some "typical" test data
    #print "Hello"
    length=len(data) # stores the length of the data provided
    turtle.home()   # Sets the turtle to position (0,0)
    division=360/length #what angle is needed for invidual lines
    poslist=[] #list to store current position
    valpos=[]   #list to store position
    j=0
    turtle.hideturtle() #hides the arrow
        #Draw the foundation of the Radar Chart
    for i in range(length): # Loop until all the given data is plotted
        turtle.forward(200) #move turtle forward
        turtle.dot(10,"black") # Draw the black dot at the end of each data
        nowpos=turtle.pos() # store the current position
        poslist.append(nowpos) #append the current position to list
        #turtle.hideturtle()
        turtle.setpos(nowpos[0]+10,nowpos[1]) #get the turtle to new postion to write data
        turtle.write(data[i], True, align="center") # Write the label of data
        turtle.setpos(nowpos[0],nowpos[1]) #return to the previous position
        turtle.back(200) #return home
        turtle.left(division) # rotate by the specific angle
    turtle.home()    # return to turtle home
    #Connect the ends points of the radar chart
    for i in poslist: #
        turtle.setpos(i[0],i[1])
        #turtle.setpos(i[j],i[j+1])
        #turtle.forward(100)
        #turtle.home()
        #turtle.degree(division)
        #turtle.heading()
        #turtle.forward(100)
    turtle.setpos(poslist[0][0],poslist[0][1])
    turtle.home()
    #Draw green Dots 
    for i in range(length):
        incval=data[i]
        turtle.forward(incval*2)
        turtle.dot(15,"green")
        nowpos=turtle.pos()
        valpos.append(nowpos) 
        turtle.back(incval*2)
        turtle.left(division)
    turtle.begin_poly()
    turtle.fill(True)
    #Fill the green Dots
    for i in valpos:
        turtle.setpos(int(i[0]),int(i[1]))
    turtle.setpos(valpos[0][0],valpos[0][1])
    turtle.end_poly()
    p = turtle.get_poly()
    turtle.register_shape("jpt", p)
    turtle.color("Green", "Green")
    turtle.begin_fill()
    #turtle.p(80)
    turtle.end_fill()
    turtle.fill(False)
コード例 #14
0
def pox(turtle, x, y, n=10):
    origx = turtle.xcor()
    origy = turtle.ycor()
    turtle.penup()
    for i in range(n):
        random_location(turtle, x, y, True)
        turtle.dot(random.randint(3, 10), random_color())
        turtle.setpos(origx, origy)
    turtle.pendown()
コード例 #15
0
ファイル: hangman.py プロジェクト: erxix94/Hangman
 def drawPoint(self):
     '''
         Draw a point with initial property
     '''
     turtle.speed(0)
     turtle.penup()
     turtle.goto(self.x,self.y)
     turtle.dot(size,color)
     turtle.penup()    
コード例 #16
0
def serpinski(length, depth):
    if depth > 1:
        t.dot()

    if depth == 0:
        t.stamp()
    else:
        serpinski_draw(length, depth)
        serpinski_draw(length, depth)
        serpinski_draw(length, depth)
コード例 #17
0
ファイル: pylsys.py プロジェクト: masterzu/pylsys
    def draw_root(self):
        """
        draw at the origin a dot

        Returns: 
            self
        """
        import turtle
        turtle.dot()
        return self
コード例 #18
0
def printGrid(g):
    window=turtle.Screen()
    window.screensize(MAX,MAX)
    turtle.hideturtle()
    turtle.penup()
    
    for i in range(MAX):
       for j in range(MAX):
           if g[i][j]==ALIVE:
                turtle.goto(i,j)
                turtle.dot()
コード例 #19
0
ファイル: nightdriver.py プロジェクト: sbihel/retrogames
def draw_score():
	turtle.goto(-50, MAXY-25)
	turtle.dot(50, 'black')
	turtle.color('white')
	turtle.write(str(s.score), align='center', font=('Arial', 14, 'normal'))

	curTime = round(time.time() - s.time, 0)
	scoreTime = GAMETIME - curTime

	turtle.goto(150, MAXY-25)
	turtle.dot(50, 'black')
	turtle.color('white')
	turtle.write(scoreTime, align='center', font=('Arial', 14, 'normal'))
コード例 #20
0
def TurtlePainting(Image,filtervalue):
    pix=Image.load()
    #turtle.speed(0)
    turtle.tracer(0)
    turtle.penup()
    width=Image.size[0]
    height=Image.size[1]
    turtle.setup(width,height+30,-turtle.window_width(),-turtle.window_height())
    for i in range(height):
        for j in range(width):
            if pix[j,i][0]<=filtervalue:
                turtle.setpos(j-turtle.window_width()/2,-i+turtle.window_height()/2-10)
                turtle.dot(8)
コード例 #21
0
ファイル: charts_app.py プロジェクト: eppel81/education
def text_drawer(text, x, y, **colors):
    """

    Функция пишет текст легенды в нужных координатах и заданным цветом.
    """
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.pencolor(colors['r'], colors['g'], colors['b'])
    turtle.dot(20)
    turtle.penup()
    turtle.goto(x + 25, y-10)
    turtle.write(text, True, font=('Arial', 12, 'normal'))
コード例 #22
0
ファイル: triangle_new.py プロジェクト: eppel81/education
def haos_mode(coords=0, numIter=1000):

    startPoint = (100,75)
    turtle.dot(2)
    for i in range(numIter):
        randCorner = coords[random.randint(0, 2)]
        newPoint =    (subtr_coord(startPoint[0], randCorner[0]),
                        subtr_coord(startPoint[1], randCorner[1]))
        startPoint = newPoint
        turtle.penup()
        turtle.setpos(startPoint[0], startPoint[1])
        turtle.pendown()
        turtle.dot(2)
コード例 #23
0
ファイル: interface.py プロジェクト: etiennedub/battleship
    def drawCircle(self,position,color):
        """
        Dessine un cercle de la couleur et à la position choisie

        :param position: position de la grille en (i,j,"joueur")
        :param color: couleur du cercle en str ou code hex RGB
        """ 
        i,j,player = position
        if player == "you":
            turtle.goto(38+j*25,88-25*i)
            turtle.dot(20,color)
        if player == "enemy":
            turtle.goto(-262+(25*j),88-25*i)
            turtle.dot(20,color)
コード例 #24
0
def drawPoints(row):
	turtle.seth(270)
	turtle.color("grey")
	for i in range(len(row)):
		tempX = row[i][0]
		temp = 1.414 * ((tempX * 212.1) / 300)
		turtlex = row[i][1] - temp
		turtley = row[i][2] - temp
		turtle.pu()
		turtle.goto(turtlex,turtley)
		turtle.pd()
		turtle.dot(4,"blue")
		turtle.write("p"+format(i,"2d"))
		turtle.fd(row[i][2])
コード例 #25
0
ファイル: lego_piece.py プロジェクト: pennal/USI10YearPython
def dots(width, height, color, colors, newX, newY, unit = unit): #draws the dots of the lego
    turtle.penup()
    turtle.color(colors[color])
    turtle.pensize(unit/4)
    for j in range(height):
        turtle.left(90)
        turtle.forward(unit/2+unit*j)
        turtle.right(90)
        turtle.forward(unit/2)          #turtle is on first dot of the row
        turtle.dot()
        for i in range(1,width):
            turtle.forward(unit)
            turtle.dot()
        turtle.goto(newX,newY)
コード例 #26
0
ファイル: A_Star.py プロジェクト: mrton/A_Star
def turtlePrint(board, width, height):
    turtle.hideturtle()
    turtle.speed(0)
    turtle.penup()
    turtle.goto(-210, -60)
    turtle.pendown()
    turtle.goto(20*width-210, -60)
    turtle.goto(20*width-210, 20*height-60)
    turtle.goto(-210, 20*height-60)
    turtle.goto(-210, -60)
    turtle.penup()

    for y in xrange(height):
        for x in xrange(width):
            turtle.penup()
            turtle.goto(20*x-200,20*y-50)
            turtle.pendown()
            if board[x][y] is 1:
                turtle.pencolor("green")
                turtle.dot(10)
                turtle.pencolor("black")
            elif board[x][y] is 2:
                turtle.dot(20)
            elif board[x][y] is 3:
                turtle.pencolor("red")
                turtle.dot(10)
                turtle.pencolor("black")
            elif board[x][y] is 8:
                turtle.pencolor("blue")
                turtle.dot()
                turtle.pencolor("black")

    turtle.exitonclick()
コード例 #27
0
 def placeO(self,x,y):
     turtle.up()
     tx=x*harsha
     ty=y*harsha
     turtle.goto(tx,ty)
     x2=tx-harsha
     y2=ty-harsha
     turtle.up()
     turtle.goto(float(tx+x2)/2,float(ty+y2)/2)
     turtle.down()
     turtle.dot(harsha)
     turtle.up()
     turtle.goto(-harsha,-harsha)
     turtle.down()
     return
コード例 #28
0
ファイル: figuras.py プロジェクト: joenco/compiladorg
def punto(simbolos,identificador,linea):
  x = obtener_x(identificador,simbolos)
  y = obtener_y(identificador,simbolos)  

  tx = obtener_tx(identificador, simbolos,linea)
  ty = obtener_ty(identificador, simbolos,linea)
  relleno = obtener_color(obtener_relleno(identificador,simbolos,linea))

  x = x*44 + tx*44
  y = y*44 + ty*44

  turtle.penup() #levantar lapiz
  turtle.setposition(x,y) #ir a posicion
  turtle.pendown() #bajar lapiz
  turtle.dot(20,relleno) #dibujar punto
コード例 #29
0
def grafico(funcao,inicio,num,cor):
    """
    Faz o gráfico da função a partir do ponto inic.
    """
    x = inicio
    turtle.pencolor(cor)
    turtle.up()
    turtle.goto(x,0)
    turtle.down()
    turtle.dot(6)
    
    for i in range(1,num):
        x = funcao(x)
        turtle.goto(i,x)
        turtle.dot(6)
コード例 #30
0
def point(position):
    init_geometrie()
    turtle.goto(position.x, position.y)
    turtle.dot()
コード例 #31
0
import turtle as tr
import random
tr.colormode(255)
tr.hideturtle()
tr.penup()
tr.setheading(230)
tr.forward(280)
tr.setheading(0)
tr.speed("fastest")
rgb_color = [(251, 251, 248), (254, 240, 252), (212, 251, 242), (198, 12, 32),
             (250, 237, 17), (39, 76, 189), (38, 217, 68), (238, 227, 5),
             (229, 159, 46), (27, 40, 157)]
scr = tr.Screen()
for i in range(0, 10):
    for j in range(0, 10):
        tr.pendown()
        tr.dot(20, random.choice(rgb_color))
        tr.penup()
        tr.forward(50)
    tr.setheading(90)
    tr.forward(50)
    tr.setheading(180)
    tr.forward(500)
    tr.setheading(0)
scr.exitonclick()
コード例 #32
0
def drawDot():
    """Draw a dot of the turtle's pen size"""
    t.forward(10)
    t.dot()
    t.forward(20)
コード例 #33
0
 def Draw(self):
     turtle.penup()
     turtle.goto(self.x, self.y)
     turtle.dot()
     turtle.write(self.__str__())
     turtle.hideturtle()
コード例 #34
0
def alternateBlackAndRed(j):
    if j % 2 == 0:
        turtle.dot(40, 'black')
    else:
        turtle.dot(40, 'red')
コード例 #35
0
# 利用while循环绘制矩形
import turtle
x1, y1, x2, y2, x3, y3, x4, y4 = eval(input("x1,y1,x2,y2,x3,y3,x4,y4:"))
count = 0
turtle.showturtle()
turtle.dot(10, "black")
while count < 4:
    count += 1
    turtle.penup()
    turtle.goto(x1, y1)
    turtle.pendown()
    turtle.goto(x2 * -1, y2)
    turtle.goto(x3 * -1, y3 * -1)
    turtle.goto(x4, y4 * -1)
    turtle.goto(x1, y1)
    x1 += 50
    y1 += 50
    x2 += 50
    y2 += 50
    x3 += 50
    y3 += 50
    x4 += 50
    y4 += 50
turtle.done()
コード例 #36
0
def draw_point(p):
    turtle.goto(p)
    turtle.dot(5, random.random(), random.random(), random.random())
コード例 #37
0
def draw_big_point(p):
    turtle.goto(p)
    turtle.color(0.8, 0.9, 0)
    turtle.dot(15)
    turtle.write('     ' + str(p))
コード例 #38
0
ファイル: turtle_graphics.py プロジェクト: LCarnovale/Orbits5
def draw_all(x,
             y,
             z,
             major,
             minor,
             angle,
             fill=[0, 0, 0],
             box=None,
             intensity=None,
             screen_radius=None):
    global ellipsePoints
    global drawStars
    global lowestApparentMag
    global totalIncidentIntensity
    global FLARE_POLY_POINTS

    mask = (z > 0)
    mask = np.logical_and(mask, np.isnan(major) == False)
    mask = np.logical_and(mask, np.abs(x) < screen_width() / 2 + major)
    mask = np.logical_and(mask, np.abs(y) < screen_height() / 2 + major)
    sort_mask = np.argsort(z)[::-1]
    mask = mask[sort_mask]
    sort_and_mask = sort_mask[mask]

    if box:
        if mask[box]:
            box_x = x[box]
            box_y = y[box]
            box_maj = major[box]
            # box_min = minor[box]
        else:
            box = None

    x = x[sort_and_mask]
    y = y[sort_and_mask]
    major = major[sort_and_mask]
    minor = minor[sort_and_mask]
    angle = angle[sort_and_mask]
    # mask_map = np.flatnonzero(mask) # Indexes of True's in mask
    if _is_array(fill):
        fill = fill[sort_and_mask]

    if SMART_DRAW:
        perimApprox = 2 * np.pi * np.sqrt((major**2 + minor**2) / 2)
        points = np.int32(perimApprox / SMART_DRAW_PARAMETER)
    else:
        points = np.full(len(x), ellipsePoints)

    points[points > MAX_POINTS] = MAX_POINTS

    flareWidth = 5  # So it doesn't break later, normally this is 0
    centre_array = np.array([x, y]).transpose()

    if box:
        # box 'inner' radius, ie half the width of a side
        boxRadius = max(MIN_BOX_WIDTH, box_maj * 1.4 + flareWidth) / 2
        turtle.up()
        turtle.pencolor([1, 1, 1])
        turtle.goto(box_x - boxRadius, box_y - boxRadius)
        turtle.down()
        turtle.goto(box_x - boxRadius, box_y + boxRadius)
        turtle.goto(box_x + boxRadius, box_y + boxRadius)
        turtle.goto(box_x + boxRadius, box_y - boxRadius)
        turtle.goto(box_x - boxRadius, box_y - boxRadius)
        turtle.up()  #Draw the box

    if flareWidth < 0: return False

    if False and (points > 2) and screen_radius:
        # screenRadius
        # Assuming that the angle puts the major axs through
        # the screen centre we can clip points that are outside
        # of the screen:
        centreRadius = (x**2 + y**2)**(1 / 2)
        X = centreRadius - screenRadius
        if (X <= -major or points < 10):
            # The whole ellipse is on screen.
            # or the thing is small anyway
            clipAngle = -np.pi / 2
        elif (X >= major):
            # The whole ellipse is probably off the screen
            return
        else:
            # Do some quik mafs:
            Y = minor / major * sqrt(major**2 - X**2)
            cosTheta = Y / sqrt(X**2 + Y**2)
            clipAngle = -acos(cosTheta)
            # 'clipAngle' gives the angle from the minor axis
            # that the perimeter clips the screens radius
            # +np.pi/2 ==> the centre end of the perimeter is
            #        just touching the screen radius
            #        (so the whole thing is probably out of view)
            # -np.pi/2 ==> the outer end is just touching,
            #        ie, almost all of it will be in view.
    turtle.up()
    if np.any(points > 2) or True:
        clipAngle = np.full(len(x), -np.pi / 2)

        # Shifts an xy pair relative to major-minor axes
        # to the x-y axes of the screen, returns the new xy pair relative
        # to the centre of the oval and the screen x-y plane
        def localShift(local_angle, index=slice(None)):
            # coordAngle -= pi
            locX = major[index] / 2 * np.cos(local_angle)
            locY = minor[index] / 2 * np.sin(local_angle)
            shiftX = locX * np.cos(angle[index] -
                                   np.pi) - locY * np.sin(angle[index] - np.pi)
            shiftY = locY * np.cos(angle[index] -
                                   np.pi) + locX * np.sin(angle[index] - np.pi)
            return np.array([shiftX, shiftY]).transpose()

        # onScreen = True
        # Drawn = False
        # draw between <angle> and <np.pi - angle>
        clipAngle = np.pi / 2 - clipAngle
        start = centre_array + localShift(clipAngle)

        ### NUMPY TAKING OVER FROM HERE
        # print(start)
        try:
            fill = fill.tolist()
        except:
            pass
        for j in range(len(x)):
            try:
                fill[0][0]
            except:
                fill_ = fill
            else:
                try:
                    fill_ = fill[j]
                except:
                    # print(fill)
                    raise KeyError

            turtle.fillcolor(fill_)
            turtle.pencolor(fill_)
            s = start[j]
            c = centre_array[j]
            c_a = clipAngle[j]

            # print(s)

            turtle.goto(*s)

            start_i = 0
            end_i = points[j]
            if end_i <= 2:
                turtle.dot(2)
            else:
                turtle.begin_fill()
                for i in range(start_i, end_i):
                    tempAngle = 2 * ((end_i / 2) - i) / end_i * c_a
                    point = c + localShift(tempAngle, j)
                    turtle.goto(*point)
                turtle.end_fill()  # Draw the oval
            # if not j % 10:
            #     turtle.write(f'fill: {fill_}')

            turtle.up()
    # else:
    #     turtle.up()
    #     turtle.goto()

    return True
コード例 #39
0
ファイル: test1.py プロジェクト: nir04m/myschoolfile
def draw_score():
    turtle.goto(0, GROUNDY - 25)
    turtle.dot(50, GROUNDCOLOR)
    turtle.color('red')
    turtle.write(score, align='center', font=('Arial', 14, 'normal'))
コード例 #40
0
def focalLength(obj, img):
    print("Welcome to the Focal Length Calculator!!")
    object_distance = (input("Enter an object distance, in mm: ")
                       )  #input object distance
    image_distance = (input("Enter an image distance, in mm: ")
                      )  #input image distance
    focal_length = 1 / (float(image_distance)) + 1 / (float(object_distance))
    print("Focal Length of your lens is: ", 1 / float((focal_length)), "mm")
    line = (1 / float((focal_length)) / 2)
    print("Lens:", line, "mm")  #distance between f points, placed at origin
    turtle.speed(1)  #speed to see the turtle in motion
    turtle.showturtle()
    turtle.screensize(2000, 2000)

    #object
    turtle.forward(
        -float(object_distance))  #to left if positive, to right if negative
    turtle.color(str("#bc1818"))
    turtle.begin_fill()
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.end_fill()
    turtle.color("black")
    turtle.penup()
    turtle.goto(-float(object_distance), 20)
    turtle.write("Object", True, align="center",
                 font=("Ariel", 10, "normal"))  #label above lens axis
    turtle.goto(-float(object_distance), 0)
    turtle.pendown()

    #focalpoint1 -- -120 #have to go to origin for it to be the right distance
    turtle.goto(0, 0)  #go to origin; "reset"
    turtle.forward(-float(1 / focal_length))
    turtle.begin_fill()
    turtle.dot(9, str("#176825"))
    turtle.end_fill()
    turtle.penup()
    turtle.goto(-float(1 / focal_length), -30)
    turtle.write("Focal Point",
                 True,
                 align="center",
                 font=("Ariel", 10, "normal"))  #label below lens axis
    turtle.color("black")
    turtle.goto(-float(1 / focal_length), 0)
    turtle.pendown()

    #focalpoint2 -- 120 #have to go to the origin for it to be the right distance
    turtle.goto(0, 0)  #go to origin; "reset"
    turtle.goto(float(1 / focal_length), 0)
    turtle.begin_fill()
    turtle.dot(9, str("#176825"))
    turtle.end_fill()
    turtle.penup()
    turtle.goto(float(1 / focal_length), -30)
    turtle.write("Focal Point",
                 True,
                 align="center",
                 font=("Ariel", 10, "normal"))
    turtle.color("black")
    turtle.goto(float(1 / focal_length), 0)
    turtle.pendown()
    turtle.goto(0, 0)  #go to origin; "reset"

    #image
    turtle.forward(
        float(image_distance))  #to right if positive, to left if negative
    turtle.color(str("#183870"))
    turtle.begin_fill()
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.end_fill()
    turtle.color("black")
    turtle.penup()
    turtle.goto(float(image_distance), 20)
    turtle.write("Image", True, align="center",
                 font=("Ariel", 10, "normal"))  #label above lens axis
    turtle.goto(float(image_distance), 0)
    turtle.pendown()
    turtle.goto(0, 0)

    #lens
    turtle.color(str("#5e5e5e"))
    turtle.goto(0, 100)  #to make the vertical line
    turtle.goto(0, -100)  #to make the vertical line
コード例 #41
0
ファイル: main.py プロジェクト: DiegoC386/Python_Turtle-2.0
turtle.forward(480)
turtle.left(90)

#ESPACIO
turtle.up()
turtle.goto(-300, 0)
turtle.down()

#LETRA I
turtle.speed()
turtle.left(90)
turtle.forward(300)
turtle.up()
turtle.goto(-300, 400)
turtle.down()
turtle.dot(15, 'red')
turtle.up()
turtle.goto(-300, 0)
turtle.down()

#ESPACIO
turtle.up()
turtle.goto(0, 0)
turtle.down()

#LETRA E
turtle.shape('turtle')
turtle.pencolor('red')
turtle.left(-60)
turtle.forward(250)
turtle.left(180)
コード例 #42
0
'''
CSC101 Lab 9
Part 4: Points in circle 
Idrissa Jalloh
Franklin Nuth
March 31 2017
'''

import turtle
import random
import mytools

turtle.bgcolor('darkgray')  # set background color

# PROGRAM STARTS HERE
xc, yc = eval(input("Please enter the x and y of your center circle!: "))
r = eval(input("Please enter the radius of your circle!: "))

turtle.tracer(False)  # Animation Off

for i in range(2000):
    x, y = mytools.random_location()
    mytools.move(x, y)  # make turtle jump to location (x,y)
    if mytools.is_point_in_circle(xc, yc, r, x, y):
        turtle.dot(10, 'blue')
    else:
        turtle.dot(5, 'orange')

turtle.update()  # Show all points at once
turtle.done()
コード例 #43
0
 def draw(self):
     tt.up()
     tt.setpos(Graphics.shifted(self.center))
     tt.dot(2 * self.radius, self.color)
コード例 #44
0
        toadd *= points[i][index]
        value += toadd

    return value


#Get ready to put the points
turtle.pencolor((1.0, 0.0, 0.0))
turtle.width(10)

#Put the points
for j in points:
    turtle.up()
    turtle.setpos(j[0], j[1])
    turtle.down()
    turtle.dot()

#Put back the original settings
turtle.width(1)
turtle.pencolor((0.0, 0.0, 0.0))
turtle.up()
turtle.setpos(points[0][0], points[0][1])
turtle.down()
turtle.speed(0)

#Finally, draw the curve!
t = 0.000
while t < 1.00:
    t += 0.01
    turtle.setpos(int(B(points, t, 0)), int(B(points, t, 1)))
コード例 #45
0
 def display(self,y_max=200):
     #Sets the x xcalar for later use (not really needed)
     xscalar = 110
     #Sets the scaling for the Y axis so the graph is spaced relative to the high population, rather than being a set scaling
     self.yscalar = (y_max+300)/self.highestPopulation
     #Basically just finds the highest population and rounds it to 1 sig fig so it can display the spacing increments on the graph.
     #If the turtle is at the origin (so bassically if this is the first time the turtle has run) set up the graph
     if(turtle.xcor() == 0 and turtle.ycor() == 0):
         #Setting up turtle settings
         turtle.color("black")
         turtle.hideturtle()
         turtle.speed(0)
         #Drwa the y axis
         turtle.penup()
         turtle.goto(-300,-300)
         turtle.pendown()
         turtle.goto(-300,y_max)
         #Draw the X axis
         turtle.penup()
         turtle.goto(250,-300)
         turtle.pendown()
         turtle.goto(-300,-300)
         turtle.penup()
         #Write titles for the Axes
         turtle.goto(-450,0)
         turtle.write("Population (people)")
         turtle.goto(0,-350)
         turtle.write("Date (years)")
         #Draw each increment on the X axis
         for x in range(1,6):
             turtle.penup()
             turtle.goto(-310+xscalar*x,-320)
             turtle.write("201{}".format(x))
             turtle.goto(-300+xscalar*x,-300)
             turtle.pendown()
             turtle.goto(-300+xscalar*x,-285)
         #Draw each increment on the Y axis
         for x in range(1,5):
             turtle.penup()
             turtle.goto(-300,-300+(300+y_max)/4*x)
             turtle.pendown()
             turtle.goto(turtle.xcor()+20,turtle.ycor())
             turtle.penup()
             turtle.goto(turtle.xcor()-70,turtle.ycor()-10)
             turtle.write(self.highestPopulation/4*x)
     #Change the color based on what it initialized as
     turtle.color(self.color)
     turtle.penup()
     for x in range(0,6):
         #Draww all 6 points, moving over 110 every time, and placing the y Axis spot relative to the Y scalar (so highest is on top)
         turtle.goto(x*xscalar-300,self.population[x]*self.yscalar-300)
         turtle.dot(6,self.color)
     #Draw the Line Based on the equation
     turtle.goto(-300,self.b*self.yscalar-300)
     turtle.pendown()
     turtle.goto(250,(self.b+5*self.m)*self.yscalar-300)
     turtle.penup()
     #Actually displays the Equation
     turtle.goto(turtle.xcor()+10,turtle.ycor())
     turtle.write("y={0}x+{1}".format(float(self.m),float(self.b)))
     #Displays the name either at the set height or a bit above it so the state and county doesn't overlap
     turtle.goto(-300,240+20*self.extraDist)
     turtle.write(self.name)
コード例 #46
0
ファイル: T04_dot.py プロジェクト: luomeng007/turtle
def drawDot():
    tt.reset()
    # hide turtle
    tt.ht()
    tt.dot(20, 'Green')
コード例 #47
0
a = 0.2
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.02
        t.speed(0)
        t.lt(3)  # 向左转3度
        t.fd(a)  # 向前走a的步长
    else:
        a = a - 0.02
        t.speed(0)
        t.lt(3)
        t.fd(a)
t.end_fill()
t.pu()
t.goto(-20, 121)
t.dot(5, 'white')

t.pu()
t.goto(21, 108)
# t.dot(5, 'red')
t.color('black', 'black')
t.begin_fill()
a = 0.2
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.02
        t.speed(0)
        t.lt(3)  # 向左转3度
        t.fd(a)  # 向前走a的步长
    else:
        a = a - 0.02
コード例 #48
0
def pickRandomDot(colors):
    turtle.dot(40, colors[random.randrange(0, len(colors))])
コード例 #49
0
ファイル: dot_test.py プロジェクト: Linuxea/hello_python
# coding=utf-8

import turtle

i = 0
while True:
    turtle.circle(i + 50)
    i += 10
    turtle.dot(5, "green")
コード例 #50
0
def decision_five_left(turtle, direction):
    correct_decision_four(turtle)
    turtle.color("purple")
    turtle.dot()
    turtle.right(90)
    turtle.forward(30)
    turtle.dot()
    turtle.width(3)
    turtle.penup()
    turtle.right(90)
    turtle.forward(50)
    turtle.left(180)

    for i in range(10):
        turtle.color("pink")
        turtle.pendown()
        turtle.forward(2)
        turtle.penup()
        turtle.forward(10)

    turtle.goto(40, 220)
    turtle.color("purple")
    turtle.width(10)
    turtle.pendown()
    turtle.dot()


    if direction == "left":
        turtle.dot()
        turtle.color("purple")
        turtle.forward(55)
        turtle.dot()
        good_choice(turtle)
        #turtle now at 40, 165

    elif direction == "right":
        turtle.color("red")
        turtle.right(180)
        turtle.forward(55)
        turtle.dot()
        yikes(turtle)
コード例 #51
0
ファイル: draw_image.py プロジェクト: tonetheman/pymem_201704
from PIL import Image

img = Image.open("ball_image_32x32.png")

import turtle
turtle.colormode(255)

# trying to speed it up
turtle.hideturtle()

turtle.speed("fastest")

for i in range(img.width):
    for j in range(img.height):
        t = (i, j)
        color = img.getpixel(t)
        turtle.setpos(t)
        turtle.dot(2, color)
コード例 #52
0
ts = datetime.utcfromtimestamp(ts).strftime('%H:%M:%S on %Y-%m-%d')
iss_lat = iss_now['iss_position']['latitude']
iss_lon = iss_now['iss_position']['longitude']
print('As of ' + ts + ', the ISS is at (' + str(iss_lat) + ', ' +
      str(iss_lon) + ')')

# Part D
payload = {'lat': 39.768518, 'lon': -86.158092}
iss_pass = requests.get('http://api.open-notify.org/iss-pass.json',
                        params=payload).json()
ts2 = iss_pass['response'][0]['risetime']
ts2 = datetime.utcfromtimestamp(ts2).strftime('%H:%M:%S on %Y-%m-%d')
print('The next time the ISS will pass over Indianapolis, IN is ' + ts2)

# Part C
screen = turtle.Screen()
screen.setup(720, 360)
screen.bgpic('map.gif')
screen.addshape('iss.gif')
turtle.color('white')
turtle.penup()
turtle.setposition(-86.158092 * 2, 39.768518 * 2)
turtle.dot()
turtle.dot(5, "yellow")
turtle.setheading(45)
turtle.forward(5)
turtle.write(ts2, True, align="left")
turtle.setposition(float(iss_lon) * 2, float(iss_lat) * 2)
turtle.shape('iss.gif')
turtle.done()
コード例 #53
0
ファイル: asgmt03test3.py プロジェクト: joshyaya92/CS-160
def clickFn(x, y):
    t.goto(x, y)
    t.dot(20, 'Purple')
    print([x, y])
    coords.append([x, y])
    print([coords])
コード例 #54
0
import turtle

positionHuman = (0.00, 86.00)
positionLion1 = (-150.00, 0.00)
positionLion2 = (150.00, 0.00)
positionLion3 = (0.00, 260.00)
escapeDregree = 240

turtle.pensize(3)
for x in range(100):
    turtle.color("black")
    turtle.penup()
    turtle.goto(positionHuman)
    turtle.dot(2, "yellow")
    turtle.pendown()
    turtle.setheading(escapeDregree)

    lenthLion1 = turtle.distance(positionLion1)
    lenthLion2 = turtle.distance(positionLion2)
    if (x >= 2):
        if (lenthLion1 > lenthLion2):
            escapeDregree = escapeDregree - 20
            turtle.fd(10)
            print("1", escapeDregree)
        else:
            escapeDregree = escapeDregree + 20
            turtle.fd(10)
            print("2", escapeDregree)
    else:
        turtle.fd(10)
        print("3", escapeDregree)
コード例 #55
0
 def draw_offline(center, color):
     tt.up()
     tt.setpos(Graphics.shifted(center))
     tt.dot(2 * GlobalSetup.BALL_RADIUS, color)
#May 24, 2019

# This program draws the constellation for Orion

import turtle
turtle.setup(500,500)

# prevents turtle fom drawing lines until specified to draw lines
turtle.penup()
turtle.hideturtle()

# Defining the star coordinates for Betelgeuese
bet_X = -70
bet_Y = 200
turtle.goto(bet_X, bet_Y)
turtle.dot(5) #Draws the dot for the star
turtle.write('Betegeuse') #Writes the star name

# Defining the star coordinates for Meissa
mei_X = 80
mei_Y = 180
turtle.goto(mei_X, mei_Y)
turtle.dot(5) #Draws the dot for the star
turtle.write('Meissa') #Writes the star name

# Defining the star coordinates for Alnitak
aln_X = -40
aln_Y = -20
turtle.goto(aln_X, aln_Y)
turtle.dot(5) #Draws the dot for the star
turtle.write('Alnitak') #Writes the star name
コード例 #57
0
ファイル: ch.py プロジェクト: Christasen/CSCI1133_FALL2017
# web1 = "https://www.google.com/fiance/historical?output=csv&q="
# var2 = "etsy"
# web3 = web1 + var2
# page1 = urllib.request.urlopen(web3)
turtle.hideturtle()
turtle.setworldcoordinates(0, 0, 500, 500)  #####this is significant!!!!
filename = open('all_day.csv', 'r')
list1 = filename.readlines()
close = []
date = []
i = 1
while i < len(list1):
    a = list1[i]
    alist = a.split(",")
    close.append(alist[4])
    date.append(alist[0])
    i = i + 1

i = len(close)
pointOneX = 0
pointOneY = 0

while i >= 0:
    pointOneX = pointOneX + 10
    pointOneY = 10 * (float(close[i - 1]))
    turtle.goto(pointOneX, pointOneY)
    turtle.dot(2)
    i = i - 1

turtle.exitonclick()
コード例 #58
0
turtle.goto(0, 200)
turtle.right(90)
turtle.pendown()
turtle.forward(400)
turtle.home()

# #print x axis
turtle.penup()
turtle.goto(-200, 0)
turtle.pendown()
turtle.forward(400)
turtle.home()
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.dot("red")
turtle.write(str(turtle.position()) + " " + str(radius) + " (c1)")

turtle.penup()
turtle.goto(x, y - radius)
turtle.pendown()
turtle.circle(radius)

# print circle 2

turtle.penup()
turtle.goto(x2, y2)
turtle.pendown()
turtle.dot("red")
turtle.write(str(turtle.position()) + " " + str(radius2) + " (c2)")
turtle.penup()
コード例 #59
0
ファイル: shelly.py プロジェクト: FelicityPictures/CS-UY-1134
import turtle

turtle.dot(30)
turtle.up()
turtle.right(90)
turtle.forward(200)
turtle.left(90)
turtle.down()
turtle.circle(200)
turtle.up()
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.down()
turtle.circle(100, 180)
turtle.up()
turtle.forward(100)
turtle.dot(30)
turtle.left(90)
turtle.forward(200)
turtle.dot(30)
コード例 #60
-1
ファイル: quakeplot.py プロジェクト: jmxdbx/cs210
def visualizeQuakes(k, r):
    """(int, int) -> None

    Top level function for accessing and analyzing earthquake data from USGS
    website.

    Calls readeqf, createCentroids, and createClusters, using parameter
    k number of clusters and r number of repetitions to run the k-means cluster
    analysis algorithm. Uses turtle module to graphically plot the M5 or
    greater earthquakes within the past month on a world map.
    Different queries can be plotted by altering the url in readeqf as per the
    USGS API. Color list currently permits only k values less than or equal
    to 30.

    Note 2: Map supplied in the original spec is a Mercator and plots
    incorrectly. Use the included Equirectangular Projection instead.

    Returns None.

    > visualizeQuakes(6, 50)
    <Draws Turtle Graphics map with 6 clusters.>
    """
    eq_dict = readeqf()
    centroids = createCentroids(k, eq_dict)
    clusters = createClusters(k, centroids, eq_dict, r)

    w = 1800 #Window width.
    h = 900 #Window height.
    bg_pic = "better_worldmap1800_900.gif"

    t.setup(width=w, height=h)
    t.bgpic(bg_pic)
    t.speed("fastest")
    t.hideturtle()
    t.up()

    w_factor = ((w / 2) / 180)
    h_factor = ((h / 2) / 90)

    color_list = ["dark red", "dark green", "dark blue", "dark orange",
                  "dark orchid", "dark goldenrod", "dark violet",
                  "pink", "magenta", "sky blue", "plum", "dark salmon",
                  "goldenrod", "chartreuse", "dark sea green", "cornsilk",
                  "dark olive green", "bisque", "blanched almond",
                  "dark cyan", "royal blue", "papaya whip", "peach puff",
                  "misty rose", "mint cream", "lavender blush", "hot pink",
                  "dark khaki", "cornflower blue", "chocolate"]

    for cluster_index in range(k):
        t.color(color_list[cluster_index])
        for akey in clusters[cluster_index]:
            lon = (eq_dict[akey][0]) * w_factor
            lat = (eq_dict[akey][1]) * h_factor
            t.goto(lon, lat)
            t.dot()
    return None