Skip to content

Commit bd6de14

Browse files
committed
base color multiply input color by the base color + ignore alpha
1 parent dc18fef commit bd6de14

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/components/ColorPicker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ export class ColorPicker extends InteractiveLayoutElement implements IOverlayRe
3232

3333
private hsl:HSL = {h:0, s:0, l:0};
3434

35-
constructor( private onColorChange?:(color:Color, opacity:number)=>void ) {
35+
constructor( private onColorChange?:(color:Color, opacity:number)=>void, transparent=true ) {
3636
super();
3737
this.backgroundColor = "black";
3838

3939
this.colorWheel = new ColorWheel(this.onColorWheel.bind(this));
4040
this.colorSwatch = new ColorSwatch();
4141
this.alphaSlider = new DraggableValue("Alpha", true, 0, 1, 0.01, this.onAlphaSlider.bind(this));
42+
this.alphaSlider.enabled = transparent;
4243

4344
this.RGBSliders = ["R","G","B"].map((name,i)=>new DraggableValue(name, true, 0.001, 1, 0.01, this.onRGBSlider.bind(this, i)))
4445
this.HSLSliders = ["H","S","L"].map((name,i)=>new DraggableValue(name, true, 0.001, 1, 0.01, this.onHSLSlider.bind(this, i)))
@@ -85,7 +86,7 @@ export class ColorPicker extends InteractiveLayoutElement implements IOverlayRe
8586
//
8687
this.opacity = 1;
8788
this.saturation = 1;
88-
this.color = new Color("black");
89+
this.color = new Color("white");
8990
}
9091

9192
get opacity() { return this._opacity; }

src/properties/BaseColorProperty.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class BaseColorProperty extends Input {
1313
constructor() {
1414
super(3);
1515

16-
this.colorPicker = new ColorPicker(()=>this.root.update());
16+
this.colorPicker = new ColorPicker(()=>this.root.update(), false);
1717

1818
this.layout = new Layout([
1919
new TextLabel("Base Color"),
@@ -23,25 +23,20 @@ export class BaseColorProperty extends Input {
2323
});
2424

2525
this.xPadding = 10;
26-
}
26+
}
2727

28-
protected override onConnected(to: IOutlet): void {
29-
this.colorPicker.enabled = false
30-
}
28+
override writeScript(script: Script): string {
3129

32-
protected override onDisconnected(from: IOutlet): void {
33-
this.colorPicker.enabled = true
34-
}
30+
let baseColor = `color(0x${ this.colorPicker.color.getHexString() })`;
3531

36-
override writeScript(script: Script): string {
3732
if( this.connectedTo )
3833
{
39-
return super.writeScript(script);
34+
baseColor = baseColor + `.mul(${ this.connectedTo.writeScript( script ) })`;
4035
}
4136

4237
script.importModule("color");
4338

44-
return script.define( this.outletName, `color(0x${ this.colorPicker.color.getHexString() })` )
39+
return script.define( this.outletName, baseColor )
4540
}
4641

4742
}

0 commit comments

Comments
 (0)