Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ def setup():
"""

# TODO 2) Draw the bg_color background color using the background() function
background(bg_color)


# TODO 3) Draw an ellipse for the sun in the center of the window
# Use fill(sun_colors[0]) to make it yellow
# Use noStroke() to remove the black outline
noStroke()
fill(sun_colors[0])
ellipse(width/2, height/2, 2*sun_radius, 2*sun_radius)


# Do you see a yellow sun like in the 1st image?
# If not, fix your code before proceeding.
Expand All @@ -59,18 +57,18 @@ def setup():
"""

# Call the loadPixels() function to load the pixels list variable.
loadPixels()


# Loop through all the pixels in your window.
# A pixel is a 1x1 square, so if your window width is 600 and the
# height is 400 (600x400), then there are 600 * 400 = 240,000 pixels
for i in range(width * height):


# We want to change the color of our sun so use an if statement
# to check if the pixel is the color of the yellow circle.
# pixels[i] is the color of the pixel.
# sun_colors[0] is the color of the sun.
if pixels[i] == sun_colors[0]:


# If it's the same color we need to map the pixel to a
# color in our sun_colors list (see 2nd gradient image)
Expand All @@ -83,18 +81,18 @@ def setup():
# Use the map() function to do that:
# y = i / width
# step = map(y, sun_top_y, sun_bottom_y, 0, 1)
step = map(i / width, (height/2) - sun_radius, (height/2) + sun_radius, 0, 1)


# Call interpolateColor(sun_colors, step) and save the color
# variable that's returned into a variable
c = interpolate_color(sun_colors, step)


# Set the pixel at pixels[i] to the color from the previous step
pixels[i] = c



# Call updatePixels() to apply the changes made to the pixels list
updatePixels()



def draw():
Expand All @@ -110,10 +108,10 @@ def draw():
"""

# Call updatePixels() to redraw the background and sun
updatePixels()


# Set the fill() color to bg_color
fill(bg_color)


# To draw each rectangle we need to find its x, y, width, height
# *The y position can be any value within the sun:
Expand Down Expand Up @@ -142,24 +140,22 @@ def draw():
# function AND initialize it in the setup() function.
# *HINT* You will have to put 'global y', where y is your variable,
# in setup() and draw()
y -= 1


# Do you see the rectangle moving upwards?
# See image 4

# Pick a y positon to be the location when the sections stop moving up.
# If the rectangle's y positon is above this, move the rectangle's
# y position back to the bottom of the sun.
if y < (height / 2) - (sun_radius / 4):
y = (height / 2) + sun_radius
h = 40


# Does the rectangle move back to the bottom?

# Decrease the the height of the rectangle as it moves upwards.
# Similar to the y positon, a variable for the height needs to be
# created if it doesn't already exist.
h -= 40.0 / (sun_radius + (sun_radius/4))


# Adjust the amount to decrease so that it disappears close to the top.

Expand Down
Loading