Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am working on the following python code for Step#3 and am getting an error. Do you mind helping me understand the next steps? Note

I am working on the following python code for Step#3 and am getting an error. Do you mind helping me understand the next steps? Note that we cannot use method calls.

# Step 1: Create a green RGB object, assign it to variable green, and then print it

green = introcs.RGB(0,255,0,255)

print (green)

# Step 2: Create a 50% transparent red RGB object, assign it to variable red, and print it

red = introcs.RGB(255,0,0,128)

print (red)

# Step 3: Call the function blend on red/green, assign it to variable brown, and print it

def blend(red,green)

return result

print (brown)

This is the function:

def blend(color1,color2):

"""

Returns a new color that is the alpha blend of color1 over color2.

This function assumes that the alpha values in the colors are not pre-multiplied.

Parameter color1: The color on top

Precondition: color1 is an RGB object

Parameter color2: The color underneath

Precondition: color2 is an RGB object

"""

gl1 = color1.glColor()

gl2 = color2.glColor()

gl3 = [0,0,0,0]

alpha = gl1[3]+gl2[3]*(1-gl1[3])

for pos in range(3):

gl3[pos] = (gl1[pos]*gl1[3]+gl2[pos]*gl2[3]*(1-gl1[3]))/alpha

gl3[pos] = round(gl3[pos]*255)

gl3[3] = round(alpha*255)

return introcs.RGB(*gl3)

This is the introcs file: http://cs1110.cs.cornell.edu/docs/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions