Skip to content

Commit

Permalink
Merge pull request #815 from tidalcycles/color-hsl
Browse files Browse the repository at this point in the history
Color hsl
  • Loading branch information
felixroos authored Nov 18, 2023
2 parents dd8be65 + f759999 commit 3e02f0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 8 additions & 0 deletions packages/core/pattern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,14 @@ export const duration = register('duration', function (value, pat) {
return pat.withHapSpan((span) => new TimeSpan(span.begin, span.begin.add(value)));
});

export const hsla = register('hsla', (h, s, l, a, pat) => {
return pat.color(`hsla(${h}turn,${s * 100}%,${l * 100}%,${a})`);
});

export const hsl = register('hsl', (h, s, l, pat) => {
return pat.color(`hsl(${h}turn,${s * 100}%,${l * 100}%)`);
});

/**
* Sets the color of the hap in visualizations like pianoroll or highlighting.
* @name color
Expand Down
15 changes: 11 additions & 4 deletions packages/core/pianoroll.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ export function pianoroll({
barThickness = fold ? valueAxis / foldValues.length : valueAxis / valueExtent;
ctx.fillStyle = background;
ctx.globalAlpha = 1; // reset!
if (!smear) {
ctx.clearRect(0, 0, w, h);
ctx.fillRect(0, 0, w, h);
}
clearScreen(smear);
haps.forEach((event) => {
const isActive = event.whole.begin <= time && event.endClipped > time;
let strokeCurrent = stroke ?? (strokeActive && isActive);
Expand Down Expand Up @@ -282,3 +279,13 @@ export function drawPianoroll(options) {
const { drawTime, ...rest } = options;
pianoroll({ ...getDrawOptions(drawTime), ...rest });
}

function clearScreen(smear = 0, smearRGB = `0,0,0`) {
const ctx = getDrawContext();
if (!smear) {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
} else {
ctx.fillStyle = `rgba(${smearRGB},${1 - smear})`;
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}
}

0 comments on commit 3e02f0a

Please sign in to comment.