Color.mix(colorA, colorB, fraction, limit, model)
Blend two colors together, optionally based on user input. The fraction defines the distribution between the two colors, and is set to 0.5 by default.
译:将任意两个用户定义的颜色进行混合。参数fraction定义了两种颜色之间的分配比例,默认是0.5。
Arguments(参数)
colorA— A color, the first one
译:一个色值,第一个颜色。colorB— A color, the second one
译:一个色值,第二个颜色。fraction— A number, from 0 to 1. (Optional)
译:一个数字,从0到1。(可选)limit— A boolean, set to false by default. (Optional)
译:一个布尔值,默认为false。(可选)model— A string, the color model used to mix. (Optional)
译:一个字符串,混合时使用的颜色模式。(可选)
# Mix red with yellow
orange = Color.mix("red", "yellow", 0.5)
The limit defines if the color can transition beyond its range. This is applicable when transitioning between colors, using Utils.modulate. Below, the limit is set to true, so the transition cannot extend beyond the second color.
译:limit代表在颜色变换时是否可以超出范围。在使用Utils.modulate来控制颜色变换范围时这个值就可以派上用场了。如下,设置limit为true,在颜色变换过程中就不会超过第二个颜色。
# Create new Layer
layerA = new Layer
backgroundColor: "red"
# Enable dragging
layerA.draggable.enabled = true
# On move, transition its color to yellow
layerA.on Events.Move, (offset) ->
# Map the dragging distance to a number between 0 and 1
fraction = Utils.modulate(offset.x, [0, Screen.width], [0,1], true)
# Mix the colors, enable the limit, transition in HUSL
layerA.backgroundColor =
Color.mix("red", "yellow", fraction, true, "husl")