Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started