Python turtle.Screen() Examples
The following are 21
code examples of turtle.Screen().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
turtle
, or try the search function
.
Example #1
Source File: turtle-followed-mouse.py From python-examples with MIT License | 10 votes |
def __init__(self, x=0, y=0, dest=None): self.t = turtle.Turtle() self.t.speed(0) self.t.up() self.t.goto(x, y) self.t.down() if dest is None: # use start point as destination point self.destination(x, y) else: self.destination(*dest) # it is needed by `move` to execute `ontimer` self.screen = turtle.Screen() # start moving self.move()
Example #2
Source File: wikipedia.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 7 votes |
def main(): s = Screen() s.bgcolor("black") p=Turtle() p.speed(0) p.hideturtle() p.pencolor("red") p.pensize(3) s.tracer(36,0) at = clock() mn_eck(p, 36, 19) et = clock() z1 = et-at sleep(1) at = clock() while any([t.undobufferentries() for t in s.turtles()]): for t in s.turtles(): t.undo() et = clock() return "runtime: %.3f sec" % (z1+et-at)
Example #3
Source File: Turtle_Mini_Project_KC.py From Python-first-Practice with MIT License | 6 votes |
def Turtle_Mini_Project_KC(): window = turtle.Screen() window.bgcolor("white") brad = turtle.Turtle() brad.shape("turtle") brad.color("blue") brad.speed(1) draw_K(brad) draw_C(brad) window.exitonclick()
Example #4
Source File: colormixer.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def main(): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) red = ColorTurtle(0, .5) green = ColorTurtle(1, .5) blue = ColorTurtle(2, .5) setbgcolor() writer = Turtle() writer.ht() writer.pu() writer.goto(1,1.15) writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic"))) return "EVENTLOOP"
Example #5
Source File: wikipedia.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def main(): s = Screen() s.bgcolor("black") p=Turtle() p.speed(0) p.hideturtle() p.pencolor("red") p.pensize(3) s.tracer(36,0) at = clock() mn_eck(p, 36, 19) et = clock() z1 = et-at sleep(1) at = clock() while any([t.undobufferentries() for t in s.turtles()]): for t in s.turtles(): t.undo() et = clock() return "runtime: %.3f sec" % (z1+et-at)
Example #6
Source File: turtle-moth-light.py From python-examples with MIT License | 6 votes |
def __init__(self, pos, dest=None): '''create and initiate moth''' # define turtle self.t = turtle.Turtle() self.t.speed(0) # it is needed to execute `ontimer` self.screen = turtle.Screen() # remember destination self.dest = dest # at start it is not fly self.is_flying = False # move to start position #(it will use self.dest so it has to be after `self.dest = dest`) self.move(pos) # if destination is set then fly to it # (currently it is in `move()`) #if self.dest is not None: # self.move_to_light(self.dest)
Example #7
Source File: colormixer.py From ironpython3 with Apache License 2.0 | 6 votes |
def main(): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) red = ColorTurtle(0, .5) green = ColorTurtle(1, .5) blue = ColorTurtle(2, .5) setbgcolor() writer = Turtle() writer.ht() writer.pu() writer.goto(1,1.15) writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic"))) return "EVENTLOOP"
Example #8
Source File: main.py From python-examples with MIT License | 6 votes |
def main(): myTurtle = turtle.Turtle() myTurtle.speed(0) # adjust the drawing speed here myWin = turtle.Screen() size = 300 # 3 points of the first triangle based on [x,y] coordinates myPoints = [[0, 0], [0, size], [size, size], [size, 0]] degree = 1 # Vary the degree of complexity here # first call of the recursive function sierpinski(myPoints, degree, myTurtle) myTurtle.hideturtle() # hide the turtle cursor after drawing is completed myWin.exitonclick() # Exit program when user click on window
Example #9
Source File: colormixer.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def main(): global screen, red, green, blue screen = Screen() screen.delay(0) screen.setworldcoordinates(-1, -0.3, 3, 1.3) red = ColorTurtle(0, .5) green = ColorTurtle(1, .5) blue = ColorTurtle(2, .5) setbgcolor() writer = Turtle() writer.ht() writer.pu() writer.goto(1,1.15) writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic"))) return "EVENTLOOP"
Example #10
Source File: squareTurtle.py From Beginners-Python-Examples with GNU General Public License v3.0 | 5 votes |
def square(): win = turtle.Screen() win.bgcolor("white") jack = turtle.Turtle() for x in range(1,5): jack.forward(100) jack.right(90) win.exitonclick()
Example #11
Source File: nim.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def main(): mainscreen = turtle.Screen() mainscreen.mode("standard") mainscreen.setup(SCREENWIDTH, SCREENHEIGHT) nim = Nim(mainscreen) return "EVENTLOOP"
Example #12
Source File: __main__.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def makeGraphFrame(self, root): turtle._Screen._root = root self.canvwidth = 1000 self.canvheight = 800 turtle._Screen._canvas = self._canvas = canvas = turtle.ScrolledCanvas( root, 800, 600, self.canvwidth, self.canvheight) canvas.adjustScrolls() canvas._rootwindow.bind('<Configure>', self.onResize) canvas._canvas['borderwidth'] = 0 self.screen = _s_ = turtle.Screen() turtle.TurtleScreen.__init__(_s_, _s_._canvas) self.scanvas = _s_._canvas turtle.RawTurtle.screens = [_s_] return canvas
Example #13
Source File: strokesort.py From linedraw with MIT License | 5 votes |
def visualize(lines): import turtle wn = turtle.Screen() t = turtle.Turtle() t.speed(0) t.pencolor('red') t.pd() for i in range(0,len(lines)): for p in lines[i]: t.goto(p[0]*640/1024-320,-(p[1]*640/1024-320)) t.pencolor('black') t.pencolor('red') turtle.mainloop()
Example #14
Source File: nim.py From ironpython3 with Apache License 2.0 | 5 votes |
def main(): mainscreen = turtle.Screen() mainscreen.mode("standard") mainscreen.setup(SCREENWIDTH, SCREENHEIGHT) nim = Nim(mainscreen) return "EVENTLOOP"
Example #15
Source File: wikipedia.py From ironpython3 with Apache License 2.0 | 5 votes |
def main(): s = Screen() s.bgcolor("black") p=Turtle() p.speed(0) p.hideturtle() p.pencolor("red") p.pensize(3) s.tracer(36,0) at = clock() mn_eck(p, 36, 19) et = clock() z1 = et-at sleep(1) at = clock() while any([t.undobufferentries() for t in s.turtles()]): for t in s.turtles(): t.undo() et = clock() return "runtime: %.3f sec" % (z1+et-at)
Example #16
Source File: __main__.py From ironpython3 with Apache License 2.0 | 5 votes |
def makeGraphFrame(self, root): turtle._Screen._root = root self.canvwidth = 1000 self.canvheight = 800 turtle._Screen._canvas = self._canvas = canvas = turtle.ScrolledCanvas( root, 800, 600, self.canvwidth, self.canvheight) canvas.adjustScrolls() canvas._rootwindow.bind('<Configure>', self.onResize) canvas._canvas['borderwidth'] = 0 self.screen = _s_ = turtle.Screen() turtle.TurtleScreen.__init__(_s_, _s_._canvas) self.scanvas = _s_._canvas turtle.RawTurtle.screens = [_s_] return canvas
Example #17
Source File: nim.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def main(): mainscreen = turtle.Screen() mainscreen.mode("standard") mainscreen.setup(SCREENWIDTH, SCREENHEIGHT) nim = Nim(mainscreen) return "EVENTLOOP"
Example #18
Source File: __main__.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def makeGraphFrame(self, root): turtle._Screen._root = root self.canvwidth = 1000 self.canvheight = 800 turtle._Screen._canvas = self._canvas = canvas = turtle.ScrolledCanvas( root, 800, 600, self.canvwidth, self.canvheight) canvas.adjustScrolls() canvas._rootwindow.bind('<Configure>', self.onResize) canvas._canvas['borderwidth'] = 0 self.screen = _s_ = turtle.Screen() turtle.TurtleScreen.__init__(_s_, _s_._canvas) self.scanvas = _s_._canvas turtle.RawTurtle.screens = [_s_] return canvas
Example #19
Source File: test_console_kernel.py From spyder-kernels with MIT License | 4 votes |
def test_turtle_launch(tmpdir): """Test turtle scripts running in the same kernel.""" # Command to start the kernel cmd = "from spyder_kernels.console import start; start.main()" with setup_kernel(cmd) as client: # Remove all variables client.execute("%reset -f") client.get_shell_msg(block=True, timeout=TIMEOUT) # Write turtle code to a file code = """ import turtle wn=turtle.Screen() wn.bgcolor("lightgreen") tess = turtle.Turtle() # Create tess and set some attributes tess.color("hotpink") tess.pensize(5) tess.forward(80) # Make tess draw equilateral triangle tess.left(120) tess.forward(80) tess.left(120) tess.forward(80) tess.left(120) # Complete the triangle turtle.bye() """ p = tmpdir.join("turtle-test.py") p.write(code) # Run code client.execute("runfile(r'{}')".format(to_text_string(p))) client.get_shell_msg(block=True, timeout=TIMEOUT) # Verify that the `tess` variable is defined client.inspect('tess') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] assert content['found'] # Write turtle code to a file code = code + "a = 10" p = tmpdir.join("turtle-test1.py") p.write(code) # Run code again client.execute("runfile(r'{}')".format(to_text_string(p))) client.get_shell_msg(block=True, timeout=TIMEOUT) # Verify that the `a` variable is defined client.inspect('a') msg = client.get_shell_msg(block=True, timeout=TIMEOUT) content = msg['content'] assert content['found']
Example #20
Source File: paddle.py From Orbit with MIT License | 4 votes |
def __init__(self): self.done = False self.reward = 0 self.hit, self.miss = 0, 0 # Setup Background self.win = t.Screen() self.win.title('Paddle') self.win.bgcolor('black') self.win.setup(width=600, height=600) self.win.tracer(0) # Paddle self.paddle = t.Turtle() self.paddle.speed(0) self.paddle.shape('square') self.paddle.shapesize(stretch_wid=1, stretch_len=5) self.paddle.color('white') self.paddle.penup() self.paddle.goto(0, -275) # Ball self.ball = t.Turtle() self.ball.speed(0) self.ball.shape('circle') self.ball.color('red') self.ball.penup() self.ball.goto(0, 100) self.ball.dx = 3 self.ball.dy = -3 # Score self.score = t.Turtle() self.score.speed(0) self.score.color('white') self.score.penup() self.score.hideturtle() self.score.goto(0, 250) self.score.write("Hit: {} Missed: {}".format(self.hit, self.miss), align='center', font=('Courier', 24, 'normal')) # -------------------- Keyboard control ---------------------- self.win.listen() self.win.onkey(self.paddle_right, 'Right') self.win.onkey(self.paddle_left, 'Left') # Paddle movement
Example #21
Source File: jump.py From Orbit with MIT License | 4 votes |
def __init__(self): self.screen_width = 900 self.screen_length = 400 self.done = False self.hit, self.miss = 0, 0 self.scorecount = 0 self.reward = 0 self.triggered = False self.count = 20 self.direction = 1 self.speed = 5 self.up_down_count = 20 self.t_rex_speed = 5 self.obs_size = 4 self.counter = 100 self.start = -180 self.end = -90 self.diff = (self.end - self.start) / (self.obs_size - 1) # self.color = ['orange', 'red', 'blue', 'green', 'yellow', 'cyan', 'purple', 'magenta'] self.color = ['red', 'red', 'red', 'red', 'red', 'red', 'red', 'red'] self.obs_height = [self.start + self.diff * i for i in range(self.obs_size)] self.obs = [turtle.Turtle() for i in range((self.obs_size * 3) // 2)] self.initializeObs() self.done = 0 self.reward = 0 # Set up Background self.win = turtle.Screen() self.win.title('T rex') self.win.bgcolor('black') self.win.setup(width=self.screen_width, height=self.screen_length) self.win.tracer(0) # T rex config self.t_rex = turtle.Turtle() self.inializeTrext() # Obstacle config self.obstacle_speed = -3 self.win.listen() self.win.onkey(self.triggerjump, 'space') self.score = turtle.Turtle() self.score.speed(0) self.score.color('white') self.score.penup() self.score.hideturtle() self.score.goto(0, 160) self.score.write("Score : {}".format(self.scorecount), align='center', font=('Courier', 24, 'normal'))