Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am working on the following python code for Step#4 and am getting an error. Need help understanding the next steps? https://ecpyfac.ecornell.com/docs/introcs/ For #4: green

I am working on the following python code for Step#4 and am getting an error. Need help understanding the next steps?

https://ecpyfac.ecornell.com/docs/introcs/

For #4: green is called first then red

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

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

print (green)

# Step 2: Create 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(color1, color2):

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)

brown = blend(red, green)

print(brown)

# Step 4: Call the function blendUnder on green/red, and then print variable green

def blendUnder(color1,color2):

gl1 = color2.glColor()

gl2 = color1.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)

color1.red = gl3[0]

color1.green = gl3[1]

color1.blue= gl3[2]

color1.alpha = gl3[3]

green()

red()

print(green)

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

\f\f\f

Answered: 1 week ago

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago