# Import libraries from turtle import Turtle, Screen # Turtle turty = Turtle() turty.shape('turtle') turty.color('blue') turty.forward(100) turty.tiltangle(90) # Screen my_screen = Screen() my_screen.screensize(300, 300) my_screen.exitonclick() my_screen.title("Ashutosh' Turtle Show")
from turtle import Turtle, Screen screen = Screen() screen.bgcolor('black') screen.setup(width=800, height=600) screen.title("Pong") screen.tracer(0) right_paddle = Turtle('square') right_paddle.color('white') right_paddle.shapesize(stretch_wid=5, stretch_len=1) right_paddle.penup() right_paddle.goto(350, 0) def go_up(): x = right_paddle.xcor() y = right_paddle.ycor() + 20 right_paddle.goto(x, y) def go_down(): x = right_paddle.xcor() y = right_paddle.ycor() - 20 right_paddle.goto(x, y) screen.listen() screen.onkey(go_up, 'Up') screen.onkey(go_down, 'Down')
import turtle from turtle import Turtle, Screen from random import randint, choice tl = Turtle() screen = Screen() tl.speed(10) tl.pensize(20) tl.shape("arrow") def choose_color(): r = randint(0, 255) g = randint(0, 255) b = randint(0, 255) return (r, g, b) directions = [90, 180, 270, 360] turtle.colormode(255) colours = [ "CornflowerBlue", "DarkOrchid", "IndianRed", "DeepSkyBlue", "LightSeaGreen", "wheat", "SlateGray", "SeaGreen" ] for i in range(500): tl.color(choose_color()) tl.setheading(choice(directions)) tl.forward(40)
import random is_race_on = False colors = ['red', 'blue', 'orange', 'yellow', 'green', 'purple'] # Screen Methods screen = Screen() screen.setup(width=500, height=400) user_bet = screen.textinput( title="Make your bet", prompt="Which turtle will win the race? Enter a color: ") y_positions = [-40, -20, 0, 20, 40, 60] all_turtles = [] # create turtles for turtle_index in range(len(colors)): new_turtle = Turtle(shape='turtle') new_turtle.color(colors[turtle_index]) new_turtle.pu() new_turtle.goto(x=-230, y=y_positions[turtle_index]) all_turtles.append(new_turtle) # turtles moving if user_bet: is_race_on = True while is_race_on: for turtle in all_turtles: if turtle.xcor() > 230: is_race_on = False winning_color = turtle.pencolor() if winning_color == user_bet:
import turtle from turtle import Turtle, Screen screen = Screen() screen.bgcolor("green") f = Turtle("turtle") f.turtlesize(3) f.width(20) f.speed(-5) #inti terpentingnya def dragging(x, y): f.ondrag(None) f.setheading(f.towards(x, y)) f.goto(x, y) f.ondrag(dragging) #menghapus tulisanya def clickRight(x, y): f.clear() #memulai program def main(): turtle.listen() f.ondrag(dragging) turtle.onscreenclick(clickRight, 3) screen.mainloop()
def add_segment(self, position): segment = Turtle(shape="square") segment.color("white") segment.penup() segment.goto(position) self.segments.append(segment)
# for i in range(4): # turtle.forward(100) # turtle.left(90) # Modules that aren't packaged with python standard library # use pip (python packages) See: https://pypi.org # terminal: 'pip install heroes' # import heroes # print(heroes.gen()) # Assignment "Draw a dashed line for 50 paces" from turtle import Turtle, Screen a = Turtle() # for i in range(25): # a.pd() # a.pensize(2) # a.forward(5) # for j in range(25): # a.pu() # a.forward(0.5) # or for _ in range(15): a.pd() a.pensize(1) a.forward(5) a.pu()
from turtle import Screen, Turtle screen = Screen() t = Turtle() def ola(): t.pensize(3) t.pencolor('yellow') t.circle(20) t.pu() screen.mainloop() ola()
import turtle from turtle import Turtle, Screen import random import colorgram baby = Turtle() turtle.colormode(255) baby.speed(0) baby.hideturtle() baby.pu() color_list = [(240, 245, 241), (236, 239, 243), (149, 75, 50), (222, 201, 136), (53, 93, 123), (170, 154, 41), (138, 31, 20), (134, 163, 184), (197, 92, 73), (47, 121, 86), (73, 43, 35), (145, 178, 149), (14, 98, 70), (232, 176, 165), (160, 142, 158), (54, 45, 50), (101, 75, 77), (183, 205, 171), (36, 60, 74), (19, 86, 89), (82, 148, 129), (147, 17, 19), (27, 68, 102), (12, 70, 64), (107, 127, 153), (176, 192, 208), (168, 99, 102)] baby.setheading(220) baby.forward(350) baby.setheading(0) num_of_dots = 100 for dots in range(1, num_of_dots + 1): baby.dot(20, random.choice(color_list)) baby.forward(50) if dots % 10 == 0: baby.setheading(90) baby.forward(50) baby.setheading(180)
from turtle import Turtle, Screen avi = Turtle() screen = Screen() def forward(): avi.forward(10) def backward(): avi.backward(10) def left(): avi.left(10) def right(): avi.right(10) def clear(): avi.clear() avi.penup() avi.home() avi.pendown() screen.listen()
from turtle import Turtle, Screen sedge = Turtle() screen = Screen() def march(): sedge.forward(10) def right(): sedge.right(10) def left(): sedge.left(10) def reverse(): sedge.right(180) def clear(): sedge.clear() sedge.penup() sedge.home() sedge.pendown() screen.listen() screen.onkey(key="Up", fun=march)
# L-5 MCS 260 Fri 22 January 2016 : spiral1.py """ The instructions below illustrate some very basic turtle operations to draw the start of a spiral on canvas, using primarily goto commands. """ from turtle import Turtle # import the Turtle class SAM = Turtle() # sam is the name of a Turtle object SAM.up() # put the pen up SAM.goto(0, 0) # goto center SAM.down() # put the pen down POS = SAM.pos() # get the current position SAM.goto(POS[0], POS[1] - 10) # go 10 pixels down POS = SAM.pos() SAM.goto(POS[0] - 10, POS[1]) # go 10 pixels to the left POS = SAM.pos() SAM.goto(POS[0], POS[1] + 20) # go 20 pixels up POS = SAM.pos() SAM.goto(POS[0] + 20, POS[1]) # go 20 pixels to the right POS = SAM.pos() SAM.goto(POS[0], POS[1] - 30) # go 30 pixels down POS = SAM.pos() SAM.goto(POS[0] - 30, POS[1]) # go 30 pixels to the left POS = SAM.pos() SAM.goto(POS[0], POS[1] + 40) # go 40 pixels up POS = SAM.pos() SAM.goto(POS[0] + 40, POS[1]) # go 40 pixels to the right ANS = input('hit enter to quit') # else window disappears
from turtle import Turtle, Screen from question import QuestionBoard import pandas question = QuestionBoard() my_screen = Screen() my_screen.title("Name a US state") image = "blank_states_img.gif" my_screen.addshape(image) my_turtle = Turtle() my_turtle.shape(image) state_turtle = Turtle() state_turtle.hideturtle() state_turtle.pu() answered_list = [] # continues asking for user input until all states have been gotten while question.score <= question.total_states: answered_question = question.ask_question() # if the user inputs exit, create a csv file of the remaining states of which the user did not answer if answered_question == "Exit": remaining_list = [states for states in question.STATES_READ if states not in answered_list] remaining_states = pandas.DataFrame(remaining_list) remaining_states.to_csv("remaining-states.csv") break elif question.check_answer(answered_question): if answered_question not in answered_list: question.add_score() state_turtle.goto(question.set_position(answered_question)) state_turtle.write(answered_question)
# This is a sample Python script. # Press Shift+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. #Draw a Dashed Line #from turtle import Turtle,Screen from turtle import Turtle tur = Turtle() def drawdot(x): for i in range(x): tur.dot("blue") # turtle.dot(20, "blue"); tur.forward(x) tur.penup() drawdot(10) #tur.hideturtle()
from turtle import Turtle, Screen TURTLE_SIZE = 20 screen = Screen() yertle = Turtle(shape="turtle", visible=False) yertle.penup() yertle.goto(TURTLE_SIZE / 2 - screen.window_width() / 2, screen.window_height() / 2 - TURTLE_SIZE / 2) yertle.pendown() yertle.showturtle() screen.mainloop()
#import colorgram as cg from turtle import Turtle, Screen from random import choice #colors = cg.extract('image.jpg', 10) painting_colors = [(247, 238, 242), (239, 246, 243), (131, 166, 205), (222, 148, 106), (31, 42, 61), (199, 134, 147), (165, 59, 48), (140, 184, 162)] # for color in colors: # r = color.rgb.r # g = color.rgb.g # b = color.rgb.b # painting_colors.append((r, g, b)) don = Turtle() don.hideturtle() don.speed('fastest') don.penup() screen = Screen() screen.colormode(255) y = 260.00 x = -260.00 def create_dots(x, y): don.setpos(x, y) for _ in range(10): don.dot(20, choice(painting_colors)) don.forward(50)
from turtle import Turtle, Screen # создадим черепаху и поместим ее в переменную, это поможет нам управлять этой черепахой t = Turtle() # можно создать несколько черепах например создадим ещё одну, и также присвоем её переменной t2 = Turtle() # библиотека содержит функцию `Screen` которая создаёт объект экрана # этот оъект позволяет нам общаться с окном которое открыло наша программа а так же с экраном компьютера. # это как мы увидим далее очень полезно. screen = Screen() # каждая черепаха оснащена пером которое будет оставлять след за ней если его не поднять t.penup() # можно поменять размер и цвет пера t.forward(30) t.dot(30) t.forward(30) t.dot(30, 'red') t.forward(30) t.dot(30, '#ff6600') t.forward(30) t.dot(30, (0.2, 0.2, 0.2)) step = 60 radius = 30 t.home() t.sety(step)
from turtle import Turtle, Screen, bgcolor from random import choice John = Turtle() John.shape("turtle") screen = Screen() screen.bgcolor("black") colours = [ "red", "blue", "yellow", "orange", "grey", "pink", "purple", "green", "cyan", "AliceBlue", "chocolate", "brown", "cornsilk", "DarkOrange" ] # Square """ for _ range(4): john.forward(100) john.right(90) i += 1 """ # Sqaure Dashed Lines and solid lines """ i = 0 while i < 4: for _ in range(10): John.forward(10) John.pendown() John.forward(10) John.penup()
from turtle import Turtle, Screen tim = Turtle() screen = Screen() def move_forwards(): tim.forward(5) def move_backwards(): tim.backward(5) def counter_clockwise(): heading = tim.heading() tim.seth(heading + 10) def clockwise(): heading = tim.heading() tim.seth(heading - 10) def clear(): tim.clear() tim.penup() tim.home() tim.pendown()
def add_segment(self, position): new_segment = Turtle(shape='square') new_segment.color('white') new_segment.penup() new_segment.goto(position) self.segments.append(new_segment)
from math import sqrt from turtle import Turtle, mainloop, tracer, update p = Turtle() def kwadracik(bok): p.begin_fill() p.color("black", "orange") przek1 = bok / 2 * sqrt(2) bok1 = int(przek1 / 5) przek2 = bok1 * sqrt(2) for i in range(4): d = int(bok1 * 2) p.forward(d) p.rt(90) p.fd(bok1) p.rt(90) p.fd(bok1) p.lt(135) p.fd(przek2) p.lt(45) p.fd(bok1) p.lt(45) p.fd(przek2) p.lt(135) p.fd(bok1) p.rt(90) p.fd(bok1) p.rt(90) p.fd(bok1 * 2)
from turtle import Turtle, Screen francis = Turtle() screen = Screen() turtle_shape = ((0, 16), (-2, 14), (-1, 10), (-4, 7), (-7, 9), (-9, 8), (-6, 5), (-7, 1), (-5, -3), (-8, -6), (-6, -8), (-4, -5), (0, -7), (4, -5), (6, -8), (8, -6), (5, -3), (7, 1), (6, 5), (9, 8), (7, 9), (4, 7), (1, 10), (2, 14), (0, 16)) bigger_shape = [n*5 for n in turtle_shape] new_turtle = francis.turtlesize(5, 5) def turtle_size(amount): li = [] for a, b in turtle_shape: num_1 = a * amount num_2 = b * amount if a == 0: num_1 += amount if b == 0: num_2 += amount print(a, b, num_1, num_2)
from turtle import Turtle from random import random def random_color(): return(random(),random(),random()) nibles = Turtle() nibles.pensize(7) nibles.speed(1000000000000) for counter in range(1,200): nibles.pencolor(random_color()) nibles.right(10) nibles.forward(150) nibles.right(100) nibles.left(200) nibles.forward(20) nibles.left(100) nibles.right(20)
def main(self): rospy.init_node('coordinator', anonymous=False) # subscribe to requests task_status_publisher = rospy.Publisher('/taskStatus', taskStatus, queue_size=1) #create Proxy to placeActionServer of arm client = actionlib.SimpleActionClient('PlaceObject', PlaceObjectAction) client.wait_for_server() rospy.loginfo("Waiting for a turtle...") # TODO: callback to register new turtles instead of waiting for exactly one robotmsg = rospy.wait_for_message("/turtles", OnlineTurtle, timeout=None) t = Turtle(robotmsg.name, 2.466515241951, 5.809623560960491) self.addTurtleBot(t) # -1.23849964142, 4.34559011459)) rate = rospy.Rate(2) while not rospy.is_shutdown(): self.assignTask() for task in self.tasksAssigned[:]: if task.state is TASK_STATE_FETCH_TURTLE: if task.turtle.go_to_loading(): task.state = TASK_STATE_POSITION_TURTLE if task.state is TASK_STATE_POSITION_TURTLE: # TODO: mutually lock docking bay if task.turtle.dock(): rospy.loginfo(task.turtle.name + ": docked") task.state = TASK_STATE_GET_ITEM goal = PlaceObjectGoal(obj=task.item) client.send_goal(goal, self.doneCB) self.armState = ARM_LOADING rospy.loginfo(task.turtle.name + ": waiting for item to be loaded") if task.state is TASK_STATE_GET_ITEM: if self.armState is ARM_PLACED: task.state = TASK_STATE_DELIVER self.armState = ARM_WAITING rospy.loginfo(task.turtle.name + ": deliviering") elif self.armState is ARM_PLACE_FAILED: goal = PlaceObjectGoal(obj=task.item) client.send_goal(goal, self.doneCB) self.armState = ARM_LOADING if task.state is TASK_STATE_DELIVER: if task.turtle.goto_goal(task.getGoal().position.x, task.getGoal().position.y): task.state = TASK_STATE_GOAL rospy.loginfo(task.turtle.name + ": delivered") rospy.loginfo(task.turtle.name + ": wait at goal") if task.state is TASK_STATE_GOAL: if task.turtle.wait_at_goal(): rospy.loginfo(task.turtle.name + ": successfully completed task") task.free_turtle() self.tasksAssigned.remove(task) for turtle in self.turtleBots: if turtle.docked == False and turtle.has_task == False: turtle.go_to_waiting() # send task status task_status = taskStatus() for a_task in self.tasksAssigned: t = task_msg() t.pose = a_task.position t.item = a_task.item t.id = a_task.id t.status = a_task.state t.num = a_task.taskID task_status.tasks.append(t) for a_task in self.tasks: t = task_msg() t.pose = a_task.position t.item = a_task.item t.id = a_task.id t.status = a_task.state t.num = a_task.taskID task_status.tasks.append(t) task_status_publisher.publish(task_status) rate.sleep()
pSpace = 160. # Defines the region where the moons may be found time = 500 # Number of time steps subtime = 20 # Number of time sub-steps between steps n = 5 # Number of planetoids (Jupiter + 4 moons) rFactor = 2 # Converts mass to planetoid radius mass = [10., 0.3, 4.1, 2.6, 3.3] # masses of the planetoids radius = [rFactor * i for i in mass] # This will create the planetoid list p[] p = [] SetPlanets() # This will draw the planetoids s = Turtle() s.up() s.speed(0) s.down() s.dot(1) s.up() DrawPlanets() s.hideturtle() # b is Stargirl's spaceship b = Turtle() b.speed(0) b.up() b.color('red') # This determines the various arrival locations for the spaceship
from turtle import Turtle, Screen from state_data import StateData from state_locator import StateLocator from scorecard import ScoreCard import pandas as pd if __name__ == "__main__": image = "blank_states_img.gif" screen = Screen() screen.addshape(image) states_guessed = [] turtle = Turtle(shape=image) state_info = StateData() point_manager = ScoreCard() state_database = state_info.state_data game_on = True while game_on: state_input = screen.textinput(prompt="Enter the State name", title="US State Game").title() if point_manager.score <= 50 and state_input in state_database.values and state_input not in states_guessed: state_pointer = StateLocator( float(state_database[state_database['state'] == state_input] ['x'].item()), float(state_database[state_database['state'] == state_input] ['y'].values[0]), state_input) point_manager.increase_score() states_guessed.append(state_input) elif point_manager.score > 50: game_on = False print("YOU have GUESSED all the 50 STATES correctly") elif state_input.lower() == "exit":
def add_segment(self,position): new_segment=Turtle("square") new_segment.color("white") new_segment.penup() new_segment.goto(position) self.segments.append(new_segment)
########################################################################################## #Turtle Race import random from turtle import Turtle, Screen is_race_on = False turtle_color = ["blue", "green", "red", "yellow", "orange"] screen = Screen() screen.setup(width=500, height=400) user_bet = screen.textinput(title="Make your bet.", prompt="Who will win the race? Enter a color: ") y_axis = [-70, -40, -10, 20, 50, 80] all_turtles = [] for turtle_number in range(0, 5): new_turtle = Turtle(shape="turtle") new_turtle.color(turtle_color[turtle_number]) new_turtle.penup() new_turtle.goto(x=-230, y=y_axis[turtle_number]) new_turtle.pendown() new_turtle.speed("fastest") all_turtles.append(new_turtle) if user_bet: is_race_on = True while is_race_on: for turtle in all_turtles: if turtle.xcor() > 230: is_race_on = False
# import turtleee from turtle import Screen, Turtle screen = Screen() turtle = Turtle() turtle.speed(5) turtle.shape("turtle") num_sides = 12 side_size = 40 angle = 360 / 12 for side in range(num_sides): turtle.forward(side_size) turtle.clone() turtle.left(180) turtle.forward(side_size) turtle.left(180 - angle) screen.mainloop()
from turtle import Turtle root = Turtle() root.forward(60) root.left(120) root.forward(60) root.left(120) root.forward(60) root.right(170) root.forward(88) root.right(140) root.forward(95) root.getscreen()._root.mainloop()