Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #153981
| From | John Forkosh <forkosh@panix.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: terminal graphics using braille characters |
| Date | 2020-08-24 06:10 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <rhvlku$odu$1@reader1.panix.com> (permalink) |
| References | <cb09d2a4-9ca3-4827-81b4-f7bcfd0e9b35o@googlegroups.com> <rhso0k$8n7$1@reader1.panix.com> <eli$2008230251@qaz.wtf> |
Eli the Bearded <*@eli.users.panix.com> wrote:
> In comp.lang.c, JohnF <John@F.com> wrote:
>> luser droog <luser.droog@gmail.com> wrote:
>> > https://codereview.stackexchange.com/questions/248021/
>> > text-based-rendering-animation-engine-for-the-terminal
>>
>> Very cute. But I give up... where does "766F6964" come from?
>> And here's a 31-line terminal animation of stored functions...
>
> I reworked it as a dots program:
>
> // replaces asciigraph()
> void braille_graph( grid *g, double *f, int n )
> {
> int row=0,nrows=24, col=0,ncols=78;
> double bigf=0.0,yval;
>
> grid_clear(g);
>
> for ( col=0; col<n; col++ )
> if ( fabs(f[col]) > bigf ) bigf = fabs(f[col]);
>
> for ( row=0; row<nrows; row++ ) {
> yval = bigf*((double)(nrows/2-row))/((double)(nrows/2));
>
> for ( col=0; col<ncols; col++ )
> if (yval*f[(col*(n-1))/(ncols-1)]>=yval*yval)
> grid_set_pixel(g, col, row);
> }
>
> renderer_update(g);
> }
>
> // replaces main()
> void johnforkosh_function()
> {
> int width = 80;
> int height = 48;
>
> double f[999], pi=3.14159;
> double t=0.0, dt=0.05, w1=16.,w2=3.; int Nt=50;
> int i=0, N=511; /* f[] index */
>
> grid *g = grid_new(width, height);
> renderer_new(g);
> renderer_update(g);
>
> while ( --Nt > 0 ) {
> for ( i=0; i<N; i++ ) {
> double x = 2.0*pi*((double)i)/((double)(N-1));
> f[i] = .75*sin(2.*x+pi/3.+w1*t) + 1.*sin(1.*x+pi/2.+w2*t);
> }
>
> braille_graph(g, f, N);
> t += dt;
> }
> renderer_free();
> grid_free(g);
> }
>
> I stuck those in examples.c and called it from main() in main.c. Ending
> frame:
>
> ?????????????????????????????? ????????????????????????
> ?????????????????????????????????????????? ???????????????????????????????????????
> ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
> ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
> ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
> ??????????????????????????????????????????????????????????????????
>
> Also, to test it some more, I tried this out:
>
> void try_them_all()
> {
> int width = 64;
> int height = 64;
>
> grid *g = grid_new(width, height);
> renderer_new(g);
>
> renderer_update(g);
>
> for (int s = 0; s < 256; s ++) {
>
> for (int b = 0; b < 8; b ++) {
> int i = 2 * (s % 32) + (b / 4);
> int j = 4 * (s / 32) + (b % 4);
> if ( s & (1 << b) ) {
> grid_set_pixel(g, i, j);
> }
> }
> renderer_update(g);
> }
> renderer_free();
> grid_free(g);
> }
>
> Exercising the full character set:
>
> ?????????????????????????????????????????????????????????????????????????????????????????????
> ????????????????????????????????????????????????????????????????????????????????????????????????
> ????????????????????????????????????????????????????????????????????????????????????????????????
> ????????????????????????????????????????????????????????????????????????????????????????????????
> ????????????????????????????????????????????????????????????????????????????????????????????????
> ????????????????????????????????????????????????????????????????????????????????????????????????
> ????????????????????????????????????????????????????????????????????????????????????????????????
> ????????????????????????????????????????????????????????????????????????????????????????????????
>
> Elijah
> ------
> had not previously been aware of ncursesw
Interesting; thanks, Eli. I actually wrote asciigraph() just
as a simple debugging tool for math functions (one in particular
that prompted me to write it), where printing a few specific x,f(x)'s
wasn't showing everything I needed. Never actually had any use for
the dynamic/animation part. Just put that omega*t and sleep;clear
in the test driver for "decorative" purposes. It's trivial enough
to cut-and-paste asciigraph()'s 10 lines (was originally almost 50
until I stumbled onto that f[]*yval>=yval*yval idea which
semi-magically accomplishes all necessary logic at one fell swoop)
into any module where it's useful to display a function's
general behavior. All this additional stuff is cute, but way
too elaborate for asciigraph()'s intended "low-profile" debugging
purpose.
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
terminal graphics using braille characters luser droog <luser.droog@gmail.com> - 2020-08-22 17:41 -0700
Re: terminal graphics using braille characters JohnF <John@F.com> - 2020-08-23 03:32 +0000
Re: terminal graphics using braille characters Eli the Bearded <*@eli.users.panix.com> - 2020-08-23 06:52 +0000
Re: terminal graphics using braille characters "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-08-23 01:58 -0700
Re: terminal graphics using braille characters John Forkosh <forkosh@panix.com> - 2020-08-24 06:10 +0000
Re: terminal graphics using braille characters luser droog <luser.droog@gmail.com> - 2020-08-23 00:07 -0700
Re: terminal graphics using braille characters Öö Tiib <ootiib@hot.ee> - 2020-08-23 01:35 -0700
Re: terminal graphics using braille characters John Forkosh <forkosh@panix.com> - 2020-08-24 06:26 +0000
Re: terminal graphics using braille characters luser droog <luser.droog@gmail.com> - 2020-08-23 23:59 -0700
Re: terminal graphics using braille characters John Forkosh <forkosh@panix.com> - 2020-08-24 09:58 +0000
csiph-web