mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
Merge pull request #1112 from Enelg52/mouseXY
Add the mousex and mousey signal
This commit is contained in:
commit
d86a183194
@ -86,6 +86,38 @@ export const tri2 = fastcat(isaw2, saw2);
|
|||||||
|
|
||||||
export const time = signal(id);
|
export const time = signal(id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mouse's x position value ranges from 0 to 1.
|
||||||
|
* @name mousex
|
||||||
|
* @return {Pattern}
|
||||||
|
* @example
|
||||||
|
* n(mousex.segment(4).range(0,7)).scale("C:minor")
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mouse's y position value ranges from 0 to 1.
|
||||||
|
* @name mousey
|
||||||
|
* @return {Pattern}
|
||||||
|
* @example
|
||||||
|
* n(mousey.segment(4).range(0,7)).scale("C:minor")
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
let _mouseY = 0,
|
||||||
|
_mouseX = 0;
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
//document.onmousemove = (e) => {
|
||||||
|
document.addEventListener('mousemove', (e) => {
|
||||||
|
_mouseY = e.clientY / document.body.clientHeight;
|
||||||
|
_mouseX = e.clientX / document.body.clientWidth;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mousey = signal(() => _mouseY);
|
||||||
|
export const mouseY = signal(() => _mouseY);
|
||||||
|
export const mousex = signal(() => _mouseX);
|
||||||
|
export const mouseX = signal(() => _mouseX);
|
||||||
|
|
||||||
// random signals
|
// random signals
|
||||||
|
|
||||||
const xorwise = (x) => {
|
const xorwise = (x) => {
|
||||||
|
|||||||
@ -4350,6 +4350,48 @@ exports[`runs examples > example "mask" example index 0 1`] = `
|
|||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "mousex" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/4 | note:C3 ]",
|
||||||
|
"[ 1/4 → 1/2 | note:C3 ]",
|
||||||
|
"[ 1/2 → 3/4 | note:C3 ]",
|
||||||
|
"[ 3/4 → 1/1 | note:C3 ]",
|
||||||
|
"[ 1/1 → 5/4 | note:C3 ]",
|
||||||
|
"[ 5/4 → 3/2 | note:C3 ]",
|
||||||
|
"[ 3/2 → 7/4 | note:C3 ]",
|
||||||
|
"[ 7/4 → 2/1 | note:C3 ]",
|
||||||
|
"[ 2/1 → 9/4 | note:C3 ]",
|
||||||
|
"[ 9/4 → 5/2 | note:C3 ]",
|
||||||
|
"[ 5/2 → 11/4 | note:C3 ]",
|
||||||
|
"[ 11/4 → 3/1 | note:C3 ]",
|
||||||
|
"[ 3/1 → 13/4 | note:C3 ]",
|
||||||
|
"[ 13/4 → 7/2 | note:C3 ]",
|
||||||
|
"[ 7/2 → 15/4 | note:C3 ]",
|
||||||
|
"[ 15/4 → 4/1 | note:C3 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "mousey" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/4 | note:C3 ]",
|
||||||
|
"[ 1/4 → 1/2 | note:C3 ]",
|
||||||
|
"[ 1/2 → 3/4 | note:C3 ]",
|
||||||
|
"[ 3/4 → 1/1 | note:C3 ]",
|
||||||
|
"[ 1/1 → 5/4 | note:C3 ]",
|
||||||
|
"[ 5/4 → 3/2 | note:C3 ]",
|
||||||
|
"[ 3/2 → 7/4 | note:C3 ]",
|
||||||
|
"[ 7/4 → 2/1 | note:C3 ]",
|
||||||
|
"[ 2/1 → 9/4 | note:C3 ]",
|
||||||
|
"[ 9/4 → 5/2 | note:C3 ]",
|
||||||
|
"[ 5/2 → 11/4 | note:C3 ]",
|
||||||
|
"[ 11/4 → 3/1 | note:C3 ]",
|
||||||
|
"[ 3/1 → 13/4 | note:C3 ]",
|
||||||
|
"[ 13/4 → 7/2 | note:C3 ]",
|
||||||
|
"[ 7/2 → 15/4 | note:C3 ]",
|
||||||
|
"[ 15/4 → 4/1 | note:C3 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "mul" example index 0 1`] = `
|
exports[`runs examples > example "mul" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/4 | freq:150 ]",
|
"[ 0/1 → 1/4 | freq:150 ]",
|
||||||
|
|||||||
@ -55,4 +55,12 @@ There is also `saw2`, `sine2`, `cosine2`, `tri2`, `square2` and `rand2` which ha
|
|||||||
|
|
||||||
<JsDoc client:idle name="brandBy" h={0} />
|
<JsDoc client:idle name="brandBy" h={0} />
|
||||||
|
|
||||||
|
## mouseX
|
||||||
|
|
||||||
|
<JsDoc client:idle name="mousex" h={0} />
|
||||||
|
|
||||||
|
## mouseY
|
||||||
|
|
||||||
|
<JsDoc client:idle name="mousey" h={0} />
|
||||||
|
|
||||||
Next up: [Random Modifiers](/learn/random-modifiers)
|
Next up: [Random Modifiers](/learn/random-modifiers)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user