add generators/lissajous.pl

This commit is contained in:
tth 2020-10-09 02:38:03 +02:00
parent cff083a21d
commit 5e8ce2e84e
1 changed files with 75 additions and 0 deletions

75
generators/lissajous.pl Executable file
View File

@ -0,0 +1,75 @@
#!/usr/bin/perl -w
#
# Ugly code by tTh
#
my $port = 9000;
my $target = "localhost";
# ----------------------------------------------------------
use Net::OpenSoundControl::Client;
use Data::Dumper qw(Dumper);
use Getopt::Std;
my $client;
my $verbose = 0;
# ----------------------------------------------------------
sub lissajous($$$)
{
my $kx = shift; my $ky = shift;
my $phi = shift;
my ($i, $rads, $x, $y);
for ($i = 0; $i <= 360; $i++) {
$rads = $i * (3.141592654/180);
$x = int(31250*sin(($rads*$kx)+$phi));
$y = int(31250*cos($rads*$ky));
# printf "%5d %9f %6d %6d\n", $i, $rads, $x, $y;
$client->send(['/joystick/xy', 'i', $x, 'i', $y]);
# sleep 0.42;
}
sleep 2+rand(2);
$client->send(['/joystick/b', 'i', 50, 'i', 1]);
$client->send(['/joystick/b', 'i', 50, 'i', 0]);
}
# ----------------------------------------------------------
# main proggy
getopts('d:v', \%options);
if (defined $options{"d"}) {
# print Dumper $options{"d"};
($target, $port) = split /:/, $options{"d"};
}
$verbose = 1 if (defined $options{"v"});
print "trashing ", $target, " on port ", $port, "\n";
$client = Net::OpenSoundControl::Client->new(
Host => $target, Port => $port)
or die "Could not start client: $@\n";
print Dumper $client if $verbose;
my ($xk, $yk, $phase);
for ($xk=1; $xk<4; $xk++) {
for ($yk=1; $yk<4; $yk++) {
print "$$ -> $xk $yk\n";
for ($phase=0.0; $phase<1.5705; $phase+=0.0911) {
print "phi = ", $phase, "\n" if $verbose;
lissajous($xk, $yk, $phase);
}
}
}