Is there a way to plot time-value pairs in sclang similar to the way signals are plotted, where the x-axis shows time? Let say I have a list a values like
l = [
[0, 0.23],
[0.465, 0.98],
[2.91, 0.3]
// ...
]
where l[i][0] is the time on the x-axis and l[i][1] is the value on the y-axis.
How can I plot those values in a way similar to?
(
{
b = { Dust.kr(100) }.asBuffer(0.05);
s.sync;
0.05.wait;
{ b.plot.plotMode_(\bars) }.defer
}.fork
)
I don’t think there’s a direct way.
Plotter
expects an Array
which values are equally spaced. You might fill your original array with zeroes until it matches this specification, but this is probably overkill.
Manually, this can be a starting point:
(
var values = [
[0, 0.23],
[0.465, 0.98],
[2.91, 0.3],
[4.52, 0.77],
[5.66, 0.2],
];
var barWidth = 4;
var xMax = 10;
var yMax = 1;
var view = UserView()
.background_(Color.white())
.drawFunc_({
Pen.fillColor_(Color.red);
values.do({ |pair|
Pen.fillRect(
Rect(
pair[0].linlin(
0, xMax,
0, view.bounds.width
) - (barWidth / 2),
view.bounds.height -
pair[1].linlin(
0, yMax,
0, view.bounds.height
),
barWidth,
pair[1].linlin(
0, yMax,
0, view.bounds.height
)
);
);
});
});
view.front;
)
1 Like
Thanks, that is very useful, thank you.