如何随意改变颜色? Dart和StageXL

时间:2016-05-08 19:13:12

标签: dart stagexl

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);
 }

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

2 个答案:

答案 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个实例(就像您拥有r1r2r3和{我假设{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;