Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
from processing import * from random import randint # the angles for rotation rotating_sun = 0 rotating_earth = 0 rotating_moon = 0 # the center of the canvas that everything will rotate around center_x = 250 center_y = 250 # for drawing stars star_count = 150 stars = [] def setup(): size(540, 500) # generate random star points for i in range(star_count): x = randint(10, 530) y = randint(10, 490) width = randint(2, 8) height = randint(2, 8) color = randint(10, 100) stars.append({ "x": x, "y": y, "width": width, "height": height, "color": color }) # this function is called once per frame, several times per second # to draw everything def draw(): global rotating_sun, rotating_earth, rotating_moon background(0, 0, 0) # draw stars as the universe background for star in stars: fill(star["color"]) ellipse(star["x"], star["y"], star["width"], star["height"]) # earth orbits noFill() stroke(60, 60, 60) arc(center_x, center_y, 140, 140, 0, 2*PI) # change planets' rotation angle rotating_sun += -0.0001 rotating_earth += -0.005 rotating_moon += -0.06 noStroke() # Sun translate(center_x, center_y) rotate(rotating_sun) fill(250, 0, 0) ellipse(0, 0, 30, 30) # Earth rotate(rotating_earth) fill(100, 200, 250) ellipse(70, 0, 13, 13) # Moon, translate its rotation center to earth translate(70, 0) rotate(rotating_moon) fill(250, 250, 0) ellipse(10, 0, 4, 4) run()
earthmoonstars.py
( around 61 lines python code )
Published By:
bill nye
Published on
2017-07-14T15:05:03Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here