0
for(int i = 1; i < 10; i++) {
var shape = new Shape();

shape.graphics.beginPath();
shape.graphics.moveTo(r1.nextInt(1500), r2.nextInt(1500));
shape.graphics.lineTo(r3.nextInt(1500), r4.nextInt(1500));
shape.graphics.strokeColor(Color.Green);
shape.graphics.closePath();
stage.addChild(shape);
 }

如何随机更改线条的颜色?

4

2 回答 2

1

在 StageXL 中,颜色实际上只是整数。所以,正如@bp74 所说,你可以这样做:

var a = 255; // Assuming you want full opacity every time.
var r = random.nextInt(256); // red = 0..255
var g = random.nextInt(256); // green = 0..255
var b = random.nextInt(256); // blue = 0..255
var color = (a << 24) + (r << 16) + (g << 8) + b;
shape.graphics.strokeColor(color);

这是假设您在random上面的某个地方定义了:

var random = new Random();

请注意,您很可能不需要多个Random实例(就像您使用r1,和r2,我假设的那样)。r3r4

于 2016-05-24T16:36:43.647 回答
0

StageXL(和 Flash)中的颜色是 32 ARGB 值。您将 4x8 位用于 alpha、红色、绿色和蓝色颜色通道。以下示例显示了白色的颜色 0xFFFFFFFF:

var a = 255; // alpha = 0..255
var r = 255; // red = 0..255
var g = 255; // green = 0..255
var b = 255; // blue = 0..255
var color = (a << 24) + (r << 16) + (g << 8) + b;
于 2016-05-08T20:12:16.040 回答