Turtle
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from turtle import *
|
||||
from turtle import Turtle
|
||||
|
||||
sophia = Turtle()
|
||||
sophia.forward(100)
|
||||
|
||||
sophia.screen.mainloop()
|
||||
|
||||
|
||||
shape('turtle')
|
||||
forward(100)
|
||||
done()
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
from turtle import *
|
||||
from turtle import Turtle
|
||||
|
||||
sophia = Turtle()
|
||||
sophia.hideturtle()
|
||||
|
||||
for _ in range(10):
|
||||
penup();
|
||||
forward(5);
|
||||
pendown();
|
||||
forward(5);
|
||||
sophia.penup()
|
||||
sophia.forward(5)
|
||||
sophia.pendown()
|
||||
sophia.forward(5)
|
||||
|
||||
done()
|
||||
sophia.screen.mainloop()
|
||||
|
||||
@@ -2,15 +2,19 @@ from turtle import *
|
||||
|
||||
pensize(5)
|
||||
|
||||
pencolor('Green')
|
||||
pencolor('green')
|
||||
forward(30)
|
||||
pencolor('Blue')
|
||||
pencolor('blue')
|
||||
forward(30)
|
||||
pencolor('Red')
|
||||
pencolor('red')
|
||||
forward(30)
|
||||
pencolor('White')
|
||||
pencolor('white')
|
||||
forward(30)
|
||||
pencolor('Black')
|
||||
pencolor('black')
|
||||
print(pencolor())
|
||||
forward(30)
|
||||
pencolor('#c72426')
|
||||
forward(30)
|
||||
print(pencolor())
|
||||
|
||||
done()
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from turtle import *
|
||||
from turtle import Turtle
|
||||
|
||||
sophia = Turtle()
|
||||
|
||||
def draw_square():
|
||||
for _ in range(4):
|
||||
forward(100)
|
||||
right(90)
|
||||
sophia.forward(100)
|
||||
sophia.right(90)
|
||||
|
||||
draw_square()
|
||||
|
||||
done()
|
||||
sophia.screen.mainloop()
|
||||
@@ -1,16 +1,12 @@
|
||||
from turtle import *
|
||||
from turtle import Turtle
|
||||
|
||||
def draw_square(length):
|
||||
sophia = Turtle()
|
||||
|
||||
def draw_square(turtle, length):
|
||||
for _ in range(4):
|
||||
forward(length)
|
||||
right(90)
|
||||
turtle.forward(length)
|
||||
turtle.right(90)
|
||||
|
||||
draw_square(sophia, 100)
|
||||
|
||||
draw_square(50)
|
||||
penup()
|
||||
forward(100)
|
||||
pendown()
|
||||
draw_square(40)
|
||||
hideturtle()
|
||||
|
||||
done()
|
||||
sophia.screen.mainloop()
|
||||
@@ -1,18 +1,18 @@
|
||||
from turtle import *
|
||||
from turtle import Turtle
|
||||
|
||||
def draw_square(length):
|
||||
begin_fill()
|
||||
def draw_square(turtle, length):
|
||||
for _ in range(4):
|
||||
forward(length)
|
||||
right(90)
|
||||
end_fill()
|
||||
turtle.forward(length)
|
||||
turtle.right(90)
|
||||
|
||||
draw_square(50)
|
||||
penup()
|
||||
forward(100)
|
||||
pendown()
|
||||
draw_square(40)
|
||||
def draw_filled_square(turtle, length):
|
||||
turtle.begin_fill()
|
||||
draw_square(turtle, length)
|
||||
turtle.end_fill()
|
||||
|
||||
hideturtle()
|
||||
|
||||
done()
|
||||
sophia = Turtle()
|
||||
sophia.fillcolor('red')
|
||||
draw_filled_square(sophia, 100)
|
||||
|
||||
sophia.screen.mainloop()
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
from turtle import Turtle
|
||||
|
||||
def draw_square(turtle, length):
|
||||
for _ in range(4):
|
||||
turtle.forward(length)
|
||||
turtle.right(90)
|
||||
|
||||
def draw_filled_square(turtle, length):
|
||||
turtle.begin_fill()
|
||||
draw_square(turtle, length)
|
||||
turtle.end_fill()
|
||||
|
||||
Turtle.draw_filled_square = draw_filled_square
|
||||
sophia = Turtle()
|
||||
sophia.fillcolor('red')
|
||||
sophia.draw_filled_square(100)
|
||||
|
||||
sophia.screen.mainloop()
|
||||
Reference in New Issue
Block a user