مدار عطارد را نشان دهید
مدار عطارد را نشان دهید
یک فرهنگ لغت عطارد ایجاد کنید و از آن برای کشیدن یک حلقه سفید مدار به دور خورشید استفاده کنید.
نکته
میتوانید با استفاده از کروشههای مربع، مقداری را از فرهنگ لغت دریافت کنید mercury['orbit'].
from p5 import *
from make_planet import make_planet
def draw_sun():
fill(255, 255, 0) # Yellow
ellipse(width / 2, height / 2, 100, 100)
# draw_orbits function
def draw_orbits():
no_fill()
stroke(255) # Make it white
ellipse(width / 2, height / 2, mercury['orbit'], mercury['orbit']) # Draw Mercury's orbit ring using its orbit size
# draw_planets function
# load_planets function
def load_planets():
global mercury # Make mercury accessible outside this function
mercury = { # Store Mercury's data in a dictionary
'name': 'Mercury',
'colour': Color(165, 42, 42),
'size': 15,
'orbit': 150,
'speed': 1,
'info': 'The smallest, and fastest, planet.'
}
def setup():
# Put code to run once here
size(400, 400)
load_planets() # Load Mercury before the first frame is drawn
def draw():
# Put code to run every frame here
background(0)
no_stroke()
draw_sun()
draw_orbits() # Draw Mercury's orbit ring each frame
def mouse_pressed():
# Put code to run when the mouse is pressed here
# Here the RGB value is converted to Hex so it can be used in a string comparison later
pixel_colour = Color(get(mouse_x, mouse_y)).hex # Read the colour of the pixel you clicked
run(frame_rate=60)
اشکال زدایی
اگر دریافت کنید NameError: name 'mercury' is not defined، بررسی کنید که هر دو را اضافه کرده اید global mercury در load_planets() و load_planets() خط در setup().
حالا کد خود را اجرا کنید
چک کنید می توانید ببینید یک حلقه مدار سفید اطراف خورشید
هلیو کیددنیای برنامهنویسی نوجوانان