var canvas = activeDocument.groupItems.add();
var pt = 72 / 25.4;
var shapes = new Array();
shapes.push(new ShapeLine(0, 0, 20, 20, 0.2, MyColor().red));
shapes.push(new ShapeRect(0, 0, 20, 20, 0.2, MyColor().red, MyColor().black));
for (var i = 0; i < shapes.length; i++) {
shapes[i].draw();
}
function Shape() {
this.canvas = canvas;
this.draw = function () {
alert('这个儿子没有重写爸爸的方法');
}
}
function ShapeLine(startX, startY, endX, endY, strokeWidth, strokeColor) {
Shape.call(this)
this.startX = startX * pt;
this.startY = startY * pt;
this.endX = endX * pt;
this.endY = endY * pt;
this.strokeWidth = strokeWidth * pt;
this.strokeColor = strokeColor;
this.draw = function () {
var line = this.canvas.pathItems.add();
line.setEntirePath([[this.startX, this.startY], [this.endX, this.endY]]);
line.strokeColor = this.strokeColor;
line.fillColor = NoColor;
line.strokeWidth = this.strokeWidth;
return line;
}
}
function ShapeRect(startX, startY, width, height, strokeWidth, fillColor, strokeColor) {
Shape.call(this)
this.startX = startX * pt;
this.startY = startY * pt;
this.width = width * pt;
this.height = height * pt;
this.strokeWidth = strokeWidth * pt;
this.strokeColor = strokeColor;
this.fillColor = fillColor;
this.draw = function () {
var rect = this.canvas.pathItems.rectangle(this.startX, this.startY, this.width, this.height);
rect.strokeColor = this.strokeColor;
rect.fillColor = this.fillColor;
rect.strokeWidth = this.strokeWidth;
return rect;
}
}
function MyUtils() {
this.createCMYKColor = function (c, m, y, k) {
var color = new CMYKColor();
color.cyan = c;
color.magenta = m;
color.yellow = y;
color.black = k;
return color;
}
}
function MyColor() {
var utils = new MyUtils();
this.black = utils.createCMYKColor(0, 0, 0, 100);
this.red = utils.createCMYKColor(0, 100, 100, 0);
return this;
}