首页 > > 详细

辅导python graphics 程序、辅导GraphWin python 调试C/C++编程|辅导Database

#### ======= HW4 template ======= ####

from graphics import *
from time import *
import math
import random


# draw cloud on the left and right side of the sky based on the points using function. this function should return alist of circles.
def draw_cloud(win, x1,x2,y1,y2):
cloud_list = []
for i in range(11):
x = random.randint(x1, x2)
y = random.randint(y1, y2)
p = Point(x,y)

cloud = Circle(p,2)
cloud.setFill("white")
cloud.setOutline("white")
cloud.draw(win)
cloud_list.append(cloud)
return cloud_list


# draw the trunk of the tree with two points as a rectangle, calculate the circle above the tree trunk.
def draw_tree(win, p1, p2):
# drawing rectangle as trunk of the tree.

# finding width and height of the rectangle.

# finding the center point of the circle.

# drawing the circle on top of the tree trunk



def main():

# creating the graphic window
win = GraphWin("Blue sky and green field!", 800, 600)
win.setCoords(0, 0, 40, 30)

# set the background color (width is 40, height is 30)
BackGround = Rectangle(Point(0,15), Point(40, 30))
BackGround.setFill("light blue")
BackGround.draw(win)

# set the Ground color
Ground = Rectangle(Point(0,0) , Point(40, 15))
Ground.setFill("light Green")
Ground.draw(win)

# draw the sun
sun = Circle(Point(20,25), 2)
sun.setFill("Yellow")
sun.setOutline("Yellow")
sun.draw(win)

# draw the mountain1
Mountain1 = Polygon(Point(0,15), Point(15, 28), Point(30,15))
Mountain1.setFill("dark green")
Mountain1.draw(win)

# draw the mountain2
Mountain2 = Polygon(Point(10,15), Point(23,26), Point(40,15))
Mountain2.setFill("dark green")
Mountain2.draw(win)

# === call draw_cloud function for the left side of the sky ===
m1 = draw_cloud(win, 5,10,20,21)

# === call draw_cloud function for the right side of the sky ===
m2 = draw_cloud(win, 24,29,22,23)

# === set text for asking user to click a point ===
pntMsg = Point(20, 29)
txtMsg = Text(pntMsg, "Please click the left bottom point of the tree trunk.")
txtMsg.setStyle("bold")
txtMsg.setTextColor("red")
txtMsg.draw(win)

# === get the lower point from user ===

# TODO: get point p1

# === change the text to ask user to click another point ===
txtMsg.setText("Now click the upper right point of the tree trunk.")

# === get the upper point from user ===

# TODO: get point P2

# === call function to draw the tree ===
draw_tree(win, p1, p2)

# === change the text inside text box ===
txtMsg.setText("Please click a button to change views.")

# === View button ===
button_1 = Rectangle(Point(2,3), Point(6, 5))
button_1.setFill("yellow")
button_1.draw(win)
ViewMsg = Text(Point(4, 4), "Views")
ViewMsg.setStyle("bold")
ViewMsg.setTextColor("black")
ViewMsg.draw(win)

# === Wind buttton ===
button_2 = Rectangle(Point(7,3), Point(11, 5))

# TODO: details of button 2

# === Exit Button ===
button_3 = Rectangle(Point(12,3), Point(16, 5))

# TODO: details of button 3

# check if user clicks any of the three buttons
while True:
pClick = win.getMouse()

if ... : # conditions for pClick on button 3
break

elif ... : # conditions for pClick on button 1

# TODO: Change scenes

elif ... : # conditions for pClick on button 2

# TODO: Move clouds

txtMsg.setText("Good Bye!")
win.close()

main()
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!