Python@TW: 會眾| IRC| Planet| 郵件列表| 聯絡我們
修訂版 46 和 47 的差異如下:
2017-12-28 20:30:53 修訂第 46 版
大小: 884
編輯者: m
說明:
2018-01-07 12:11:42 修訂第 47 版
大小: 157
編輯者: host-158
說明:
這個顏色代表刪除的 這個顏色代表增加的
行號 1: 行號 1:
import turtle
import random
from turtle import*
行號 4: 行號 3:
def drawCircle(myTurtle, x,y, radius, color):
    myTurtle.penup()
    myTurtle.goto(x,y)
    myTurtle.pendown()
    myTurtle.begin_fill()
    myTurtle.color(color)
    myTurtle.circle(radius)
    myTurtle.end_fill()
    
colors = ['red','yellow', 'blue', 'green', 'black', 'gray', 'pink']

radii = [10,20,30,40,50,60]

numCircles = int(input('Enter number of circles:'))

width = 500
height = 500
width2 = width//2
height2 = height//2
 

screen = turtle.Screen()
screen.setup(width,height)

myTurtle = turtle.Turtle()
myTurtle.speed(0)

for i in range(numCircles):
    x = random.randint(-width2,width2)
    y = random.randint(-height2,height2)
    radius = radii[random.randrange(0,len(radii))]
    color = colors[random.randrange(0,len(colors))]
    drawCircle(myTurtle,x,y,radius,color)
    
screen.exitonclick()
def square(x):
  for i in range(4):
    forward(x)
    left(90)
    x=x+20
for j in range(4):
  square(60)
  left(90)
done()

from turtle import*

def square(x):

  • for i in range(4):
    • forward(x) left(90) x=x+20

for j in range(4):

  • square(60) left(90)

done()

Python/IDE或編輯器 (上次是 61-223-106-232 在 2018-02-11 21:34:51 編輯的)