From 61664260220f4a2726a9dcbd0e0f98a65abb39bf Mon Sep 17 00:00:00 2001 From: James Date: Sun, 7 Aug 2016 14:36:42 +0100 Subject: fish --- code/Makefile | 31 ++++++--- code/hpgl.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 204 insertions(+), 38 deletions(-) diff --git a/code/Makefile b/code/Makefile index e5170e7..5c9f55a 100644 --- a/code/Makefile +++ b/code/Makefile @@ -1,3 +1,5 @@ +default: test.wav + scp test.wav laser64: test.wav: test.s16 sox -r 44100 -c 2 -t s16 $< -r 44100 -t wav $@ @@ -26,7 +28,7 @@ test.s16:part.s16 cat $< $< $< $< $< $< $< $< $< $< $< $< $< $< $< $< $< $< $< $< >> $@ part.s16: in.hpgl hpgl - hpgl < in.hpgl > part.s16 || /bin/rm -f $@ + ./hpgl < in.hpgl > part.s16 || /bin/rm -f $@ #part.s16:square # square > $@ || /bin/rm -f $@ @@ -35,7 +37,7 @@ part.s16: in.hpgl hpgl # cc -o lp lp.c hpgl: hpgl.c - cc -o hpgl hpgl.c + cc -o hpgl hpgl.c -lm #in.svg: @@ -46,17 +48,30 @@ hpgl: hpgl.c -google.dat:google.csv - awk -F, '(NR % 10 == 0 ) {print $2}' < $< | tac > $@ || /bin/rm -f $@ +#google.dat:google.csv +# awk -F, '(NR % 10 == 0 ) {print $$7}' < $< | tail -n +2 | tac > $@ || /bin/rm -f $@ in.hpgl: google.dat - echo "set term hpgl ; set output 'in.hpgl'; unset xtics; unset ytics; plot 'google.dat' with lines notitle " | gnuplot || /bin/rm -f $@ +# echo "set term hpgl ; set output 'in.hpgl'; unset xtics; unset ytics; plot 'google.dat' with lines notitle " | gnuplot || /bin/rm -f $@ + echo "set term hpgl ; set output 'in.hpgl'; unset xtics; unset ytics; unset border; plot 'google.dat' with lines notitle " | gnuplot || /bin/rm -f $@ +# echo "set term hpgl ; set output 'in.hpgl'; plot 'google.dat' with lines notitle " | gnuplot || /bin/rm -f $@ +# echo "set term hpgl ; set output 'in.hpgl'; set grid ytics xtics linestyle 1; plot 'google.dat' with lines notitle " | gnuplot || /bin/rm -f $@ +#set grid ytics xtics linestyle 1 + + +#in.hpgl: drawing.hpgl +# cp $< $@ #in.hpgl: -# echo "set term hpgl ; set output 'in.hpgl'; plot 2 with lines notitle " | gnuplot +# echo "set term hpgl ; set output 'in.hpgl'; set grid ytics; plot 2 with lines notitle " | gnuplot + +in.hpgl:in.ps + pstoedit -f plot-hpgl -penplotter in.ps in.hpgl + +in.ps:in.svg + inkscape --export-ps=$@ $< -#in.hpgl:in.ps -# pstoedit -f plot-hpgl -penplotter in.ps in.hpgl +#pstoedit -f plot-hpgl -penplotter in.svg in.hpgl play: test.wav aplay test.wav diff --git a/code/hpgl.c b/code/hpgl.c index f9436b4..83ae6d2 100644 --- a/code/hpgl.c +++ b/code/hpgl.c @@ -1,44 +1,209 @@ #include #include #include +#include +#include +#include +FILE *debug; + void -pos (int x, int y, int b) +emit (int *lr, int b) { - int16_t lr[2]; - int i; + int16_t ilr[2]; - lr[0] = 3 * y + 10000; - lr[1] = 15000 - x * 3; + if (!b) fprintf(debug,"\n"); + fprintf(debug,"%d %d\n",lr[0],lr[1]); - lr[0] &= ~1; - lr[1] &= ~1; + ilr[0] = lr[0]; + ilr[1] = lr[1]; + + ilr[0] &= ~1; + ilr[1] &= ~1; + +#if 1 if (!b) - lr[1] |= 1; + ilr[1] |= 1; +#endif + + fwrite (ilr, sizeof (ilr), 1, stdout); + + + + //fprintf(stderr," %d %d %d\n",lr[0],lr[1],b); + +} + +int +fast_steps (int *olr, int *lr) +{ + uint64_t d, c; + int ret = 0; + int i; + + + d = 0; + for (i = 0; i < 2; ++i) + { + c = ((int64_t) lr[i]) - ((int64_t) olr[i]); + d += c * c; + } + + while (d > 5000) + { + ret++; + d = d / 2; + } + + return ret; +} + +void +move_fast (int *olr, int *lr) +{ + int s = fast_steps (olr, lr); + while (s--) + emit (lr, 0); +} - fprintf (stderr, "%6d %6d %d\n", x, y, b); +void +move_linear (int *olr, int *lr ,int b) +{ + float d, c, s[2]; + int elr[2]; + float nlr[2]; + int ns; + int i; - for (i = 0; i < 15; ++i) + d = 0; + for (i = 0; i < 2; ++i) { - fwrite (lr, sizeof (lr), 1, stdout); + c = ((int64_t) lr[i]) - ((int64_t) olr[i]); + d += c * c; + } + + d = sqrt (d); + +// if (d<10) return; + + ns = (int) d/60 ; + + + if (!ns) ns=1; + + for (i = 0; i < 2; ++i) + { + s[i] = ((float) (lr[i] - olr[i])) / (float) ns; + nlr[i] = (float) olr[i]; + } + + while (ns--) + { + for (i = 0; i < 2; ++i) + { + nlr[i] += s[i]; + elr[i] = (int) (nlr[i] + .5); + } + + emit (elr, b); + } } + +void +place (int *lr, int b) +{ + static int olr[2], ob,q[2]; + + //fprintf(stderr,"%d %d %d %d\n",lr[0],lr[1],ob,b); + //fprintf(stderr,"@ %d %d %d (%d)\n",lr[0],lr[1],b,ob); + + if (ob && !b) + { + //maybe_emit olr with beam off here? + emit (olr, 1); + emit (olr, 0); + move_fast (olr, lr); +// move_linear (olr, lr,0); + } + + if (ob && b) { + + move_linear (olr, lr,1); +// emit(lr,b); + } + + if (!ob && b) + { + move_fast (olr, lr); +// move_linear (olr, lr,0); + emit(lr,1); + } + + if (b || ob) { + memcpy (olr, lr, sizeof (olr)); + ob = b; + } + +} + +void +pos (int x, int y, int b) +{ + int lr[2]; + + +// lr[0] = 20000 - 3 * y ; + lr[0] = 3 * y +10000; + lr[1] = x * 3; + + + place (lr, b); + +// emit(lr,b); +} + + +static int beam=0; +static int ox,oy; + +void pu(void) +{ +beam=0; +} + +void pd(void) +{ +beam=1; +pos(ox,oy,1); +} + +void pa(int x,int y) +{ +ox=x; +oy=y; +pos(ox,oy,beam); +} + + + int main (int argc, char *argv[]) { char c; - char buf[1024]; + char buf[10240]; int ic, len; int commas; - int beam = 0, oldbeam = 0; int x, y; + debug=fopen("debug.dat","w"); + buf[0] = 0; len = 0; commas = 0; @@ -52,7 +217,6 @@ main (int argc, char *argv[]) buf[len++] = c; buf[len] = 0; -// fprintf(stderr,"A>%s