[Grace-core] Transparent Colours - Family Polymorphism in Grace?
Andrew P. Black
black at cs.pdx.edu
Thu Jan 26 07:23:45 PST 2012
Here is what I was thinking of while we were on the conference call. Not very different, I think. Does this compile?
Andrew
def Colour = object {
method r(red) g(green) b(blue) {
return object {
def r = red
def g = green
def b = blue
method asString {"Colour r:{r} g:{g} b:{b}"}
method renderOn(c) {…}
}
}
method red { r 1 g 0 b 0 }
method green { r 0 g 1 b 0 }
method blue { r 0 g 0 b 1 }
method yellow { r 0 g 1 b 1 }
method white { r 1 g 1 b 1 }
method black { r 0 g 0 b 0 }
method midGrey { r 0.5 g 0.5 b 0.5)
}
def TransparentColour = object {
inherits Colour
method r (red) g (green) b (blue) {
return self.r(red) g(green) b(blue) alpha 1
}
}
method r(red) g(green) b(blue) alpha(t) {
return object {
inherits super.r(red) g(green) b(blue)
def alpha = t
method asString {"Transparent {super.asString} alpha:{alpha}"}
method renderOn(c) {
if alpha = 1 then
{super.renderOn:(c)}
else
{…}
}
}
}
}
print (Colour.yellow)
print (TransparentColour.yellow)
_______________________________________________
Grace-core mailing list
Grace-core at cecs.pdx.edu
https://mailhost.cecs.pdx.edu/mailman/listinfo/grace-core
More information about the Grace-core
mailing list