zsh-users
 help / color / mirror / code / Atom feed
* Just for fun
@ 2008-10-16 15:05 Bart Schaefer
  2008-10-16 16:24 ` Stephane Chazelas
  2008-10-16 16:56 ` Peter Stephenson
  0 siblings, 2 replies; 6+ messages in thread
From: Bart Schaefer @ 2008-10-16 15:05 UTC (permalink / raw)
  To: zsh-users

A long time ago Alan Third posted the following function to zsh-users.
Anyone want to have a stab at updating it to use the new prompt coloring
code for better accuracy?

function most_useless_use_of_zsh {
    local lines columns colour a b p q i pnew
    ((columns=COLUMNS-1, lines=LINES-1, colour=0))
    for ((b=-1.5; b<=1.5; b+=3.0/lines)) do
        for ((a=-2.0; a<=1; a+=3.0/columns)) do
            for ((p=0.0, q=0.0, i=0; p*p+q*q < 4 && i < 32; i++)) do
                ((pnew=p*p-q*q+a, q=2*p*q+b, p=pnew))
            done
            ((colour=(i/4)%8))
            echo -n "\\e[4${colour}m " 
        done
        echo
    done
}

-- 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Just for fun
  2008-10-16 15:05 Just for fun Bart Schaefer
@ 2008-10-16 16:24 ` Stephane Chazelas
  2008-10-16 16:56 ` Peter Stephenson
  1 sibling, 0 replies; 6+ messages in thread
From: Stephane Chazelas @ 2008-10-16 16:24 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

On Thu, Oct 16, 2008 at 08:05:47AM -0700, Bart Schaefer wrote:
> A long time ago Alan Third posted the following function to zsh-users.
> Anyone want to have a stab at updating it to use the new prompt coloring
> code for better accuracy?
> 
> function most_useless_use_of_zsh {
>     local lines columns colour a b p q i pnew
>     ((columns=COLUMNS-1, lines=LINES-1, colour=0))
>     for ((b=-1.5; b<=1.5; b+=3.0/lines)) do
>         for ((a=-2.0; a<=1; a+=3.0/columns)) do
>             for ((p=0.0, q=0.0, i=0; p*p+q*q < 4 && i < 32; i++)) do
>                 ((pnew=p*p-q*q+a, q=2*p*q+b, p=pnew))
>             done
>             ((colour=(i/4)%8))
>             echo -n "\\e[4${colour}m " 
>         done
>         echo
>     done
> }
[...]

I don't know of the new prompt colouring code, but the only way
I can see this "improved" would be using echoti setab $colour,
and maybe adapt it based on $terminfo[colors] to use more
colours where available (16, 88 or 256 as on most /recent/
X11 terminals).

-- 
Stéphane


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Just for fun
  2008-10-16 15:05 Just for fun Bart Schaefer
  2008-10-16 16:24 ` Stephane Chazelas
@ 2008-10-16 16:56 ` Peter Stephenson
  2008-10-16 19:57   ` Richard Hartmann
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2008-10-16 16:56 UTC (permalink / raw)
  Cc: zsh-users

On Thu, 16 Oct 2008 08:05:47 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> A long time ago Alan Third posted the following function to zsh-users.
> Anyone want to have a stab at updating it to use the new prompt coloring
> code for better accuracy?
> 
> function most_useless_use_of_zsh {
>     local lines columns colour a b p q i pnew
>     ((columns=COLUMNS-1, lines=LINES-1, colour=0))
>     for ((b=-1.5; b<=1.5; b+=3.0/lines)) do
>         for ((a=-2.0; a<=1; a+=3.0/columns)) do
>             for ((p=0.0, q=0.0, i=0; p*p+q*q < 4 && i < 32; i++)) do
>                 ((pnew=p*p-q*q+a, q=2*p*q+b, p=pnew))
>             done
>             ((colour=(i/4)%8))
>             echo -n "\\e[4${colour}m " 
>         done
>         echo
>     done
> }

Hmmm.... trivially tweaking it to use more colours is easy (I'm not sure
that "colours*4" and "(i/4)%colours" are still appropriate, I haven't done any
of the maths, just changed the obvious bits).  You do have to remember that if
you're printing " " that changing the foreground colour is a bit pointless,
however.  If you've really got lots of colours you could probably do something
cleverer with the RGB space.

The trouble is the only interesting part of the Mandelbrot set is near
the border, so without some cleverer change it doesn't actually look very
different on this scale---most of it is still (on my terminal, at least) either
red or black.

Maybe the thing to do is to narrow in on one particular part of the
boundary (and upgrade your CPU).

Unfortunately it's time I did something else...

function most_useless_use_of_zsh {
    integer colours

    if (( $# )); then
      colours=$1
    else
      colours=$(echotc Co) || return 1
    fi

    local lines columns colour a b p q i pnew
    ((columns=COLUMNS-1, lines=LINES-1, colour=0))
    for ((b=-1.5; b<=1.5; b+=3.0/lines)) do
        for ((a=-2.0; a<=1; a+=3.0/columns)) do
            for ((p=0.0, q=0.0, i=0; p*p+q*q < 4 && i < colours*4; i++)) do
                ((pnew=p*p-q*q+a, q=2*p*q+b, p=pnew))
            done
            ((colour=(i/4)%colours))
	    print -nP "%${colour}K %k"
        done
        echo
    done
}

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Just for fun
  2008-10-16 16:56 ` Peter Stephenson
@ 2008-10-16 19:57   ` Richard Hartmann
  2008-10-17  1:21     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Hartmann @ 2008-10-16 19:57 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

On Thu, Oct 16, 2008 at 18:56, Peter Stephenson <pws@csr.com> wrote:

> Hmmm.... trivially tweaking it to use more colours is easy (I'm not sure
> that "colours*4" and "(i/4)%colours" are still appropriate, I haven't done any
> of the maths, just changed the obvious bits).

Your version does not print any colors, for me with zsh 4.3.6 from Debian
unstable. I tried it both with my on RC file and with zsh -f under
Konsole 4.1.2 and xterm 237.

  echotc Co

returns 8. Manually setting colours to 8 does not yield any results, either.


But then, as you said, I should probably do something else, as well ;)
Richard


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Just for fun
  2008-10-16 19:57   ` Richard Hartmann
@ 2008-10-17  1:21     ` Bart Schaefer
  2008-12-05 13:57       ` zzapper
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2008-10-17  1:21 UTC (permalink / raw)
  To: zsh-users

On Oct 16,  9:57pm, Richard Hartmann wrote:
}
} Your version does not print any colors, for me with zsh 4.3.6

It wouldn't, you need zsh sources from more recently than May 2008.
4.3.6-dev-1 if you're not checking out of CVS.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Just for fun
  2008-10-17  1:21     ` Bart Schaefer
@ 2008-12-05 13:57       ` zzapper
  0 siblings, 0 replies; 6+ messages in thread
From: zzapper @ 2008-12-05 13:57 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer wrote in news:081016182116.ZM25156@torch.brasslantern.com:


Great on cygwin 4.3.9 though I get blank black lines between every colored 
line (Dos window)



-- 
zzapper
http://www.successtheory.com/tips/vimtips.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-12-05 13:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-16 15:05 Just for fun Bart Schaefer
2008-10-16 16:24 ` Stephane Chazelas
2008-10-16 16:56 ` Peter Stephenson
2008-10-16 19:57   ` Richard Hartmann
2008-10-17  1:21     ` Bart Schaefer
2008-12-05 13:57       ` zzapper

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).