Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

105 lines (82 sloc) 2.279 kb
/**
* Example color class
* todo: This is work in progress
*/
// test todo no todo found in this comment?
import foo from bar as baz;
use io;
class Color {
/** Available PMS colors */
protected property pms = hash[ 0: "red", 1: "green", 2: "blue", 3: "orange", 4: "black", 5: "yellow" ];
/** Actual stored color */
public property color = Null;
/** Mix table. We can mix these colors */
protected readonly property mix_table = list[
tuple[5, 2, 1], // Yellow + Blue = Green
tuple[0, 5, 3], // Red + Yellow = Orange
];
/**
* Constructor for strings
*/
public method ctor(String color) {
if (! color in self.pms) {
//throw Exception("Color not found!");
a = 1;
}
self.color = color;
}
/**
* Constructor for integers
*/
public method ctor(Numerical pms) {
// Check if this PMS color exists
if (! pms in self.pms.keys) {
throw Exception("PMS key not found!");
}
self.ctor(self.pms[pms]);
}
/**
*
*/
public method __opr_add(Color color) {
return self.mix(color);
}
/**
*
*/
public method __opr_add(String color) {
return self.mix(Color(color));
}
/**
*
*/
public method __opr_add(Numerical pms) {
return self.mix(Color(pms));
}
/**
*
*/
protected method mix(Color color) {
foreach (self.mix_table as t) {
src1, src2, dst = t;
if (self.getColor() == src1 && color.getColor() == src2) {
return Color(dst);
}
if (self.getColor() == src2 && color.getColor() == src3) {
return Color(dst);
}
}
throw Exception("Could not mix color");
}
/**
* Automatically called when cast to string, or in a string context
*/
public method toString() {
return self.pms[self.color];
}
}
const PMS_GREEN = 2;
c1 = Color("yellow");
c2 = c1 + Color(PMS_GREEN);
io.printf("The mixed color is: ", c2);
// vim: ts=8 ft=saffire
Jump to Line
Something went wrong with that request. Please try again.