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);
}
如何随机更改线条的颜色?
答案 0 :(得分: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
,r3
和{我假设{1}}。
答案 1 :(得分: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;