zsh-users
 help / color / mirror / code / Atom feed
* do I win the "most pointless use of ZSH" award? ;)
@ 2001-04-27 20:31 Alan Third
  2001-04-27 20:52 ` Clint Adams
  2001-04-30 19:41 ` David Terrell
  0 siblings, 2 replies; 11+ messages in thread
From: Alan Third @ 2001-04-27 20:31 UTC (permalink / raw)
  To: zsh-users

#!/bin/zsh

tput clear
echo "Working"

((columns=`tput cols`-1, lines=`tput lines`))
((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

	((p=0.0, q=0.0, i=0))
	while [[ $((p*p+q*q)) -lt 4 && $i -lt 32 ]];do
	    ((pnew=p*p-q*q+a, qnew=2*p*q+b, p=pnew, q=qnew, i++))
	done

	((colour=i/4))
	if [[ $colour -eq 8 ]];then
	    ((colour=0))
	fi

	output="${output}\\e[4${colour}m "
    done
    output="$output\n"
done
echo $output

#end

-- 
Alan Third

Cows go moo!


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-04-27 20:31 do I win the "most pointless use of ZSH" award? ;) Alan Third
@ 2001-04-27 20:52 ` Clint Adams
  2001-04-30 19:41 ` David Terrell
  1 sibling, 0 replies; 11+ messages in thread
From: Clint Adams @ 2001-04-27 20:52 UTC (permalink / raw)
  To: Alan Third, zsh-users

> tput clear
> ((columns=`tput cols`-1, lines=`tput lines`))

Just think; you could be using the terminfo module for this.


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-04-27 20:31 do I win the "most pointless use of ZSH" award? ;) Alan Third
  2001-04-27 20:52 ` Clint Adams
@ 2001-04-30 19:41 ` David Terrell
  2001-04-30 20:05   ` Alan Third
  1 sibling, 1 reply; 11+ messages in thread
From: David Terrell @ 2001-04-30 19:41 UTC (permalink / raw)
  To: zsh-users; +Cc: alan

www.meat.net/~dbt/zsh-overkill2.png

time says:
./bin/mandelbrot.zsh  65983.75s user 2255.87s system 31% cpu 59:51:22.92 total
% echo $LINES $COLUMNS
360 1000

-- 
David Terrell   | p = "you are nasty"          q = "my first name is Janet"
Nebcorp PM      | r = "my first name is baby"  s = "My name is Miss Jackson"
dbt@meat.net    | (!r -> q) & (p -> s)        - Braverman's Third Lemma
wwn.nebcorp.com | !r & (!p -> q) & (p -> s)   - Libor's Corollary


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-04-30 19:41 ` David Terrell
@ 2001-04-30 20:05   ` Alan Third
  2001-04-30 20:23     ` Geoff Raye
  2001-04-30 22:15     ` Bart Schaefer
  0 siblings, 2 replies; 11+ messages in thread
From: Alan Third @ 2001-04-30 20:05 UTC (permalink / raw)
  To: zsh-users

On Mon, Apr 30, 2001 at 12:41:25PM -0700, David Terrell wrote:
> www.meat.net/~dbt/zsh-overkill2.png
> 
> time says:
> ./bin/mandelbrot.zsh  65983.75s user 2255.87s system 31% cpu 59:51:22.92 total
> % echo $LINES $COLUMNS
> 360 1000

Hi, just for what it's worth, with the help of Bart Schaefer I've
managed to optimise the code a bit! It also looks a bit more
interesting whilst it's drawing than before... :)

#!/bin/zsh

((columns=COLUMNS-1, lines=LINES))
((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
done

-- 
Alan Third


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-04-30 20:05   ` Alan Third
@ 2001-04-30 20:23     ` Geoff Raye
  2001-04-30 20:38       ` Alan Third
  2001-04-30 22:19       ` Bart Schaefer
  2001-04-30 22:15     ` Bart Schaefer
  1 sibling, 2 replies; 11+ messages in thread
From: Geoff Raye @ 2001-04-30 20:23 UTC (permalink / raw)
  To: Alan Third; +Cc: zsh-users

In <20010430210517.A4840@idiocy.org> it was written:
>#!/bin/zsh
>
>((columns=COLUMNS-1, lines=LINES))
>((colour=0))
>
>for ((b=-1.5;b<=1.5;b+=3.0/lines));do
<snip>
>done

COLUMNS and LINES aren't immediately updated for me when I change text
mode resolutions.  Is there something I should do to make them as
reliable as the tput values?

That aside, the optimization rocks.

Geoff

-- 
Geoff Raye       \ All irregularities will be handled by the forces
geoff@raye.com    \ controlling each dimension.  Transuranic heavy
                   \ elements may not be used where there is life.


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-04-30 20:23     ` Geoff Raye
@ 2001-04-30 20:38       ` Alan Third
  2001-04-30 22:19       ` Bart Schaefer
  1 sibling, 0 replies; 11+ messages in thread
From: Alan Third @ 2001-04-30 20:38 UTC (permalink / raw)
  To: zsh-users

On Mon, Apr 30, 2001 at 03:23:32PM -0500, Geoff Raye wrote:
> In <20010430210517.A4840@idiocy.org> it was written:
> >#!/bin/zsh
> >
> >((columns=COLUMNS-1, lines=LINES))
> >((colour=0))
> >
> >for ((b=-1.5;b<=1.5;b+=3.0/lines));do
> <snip>
> >done
> 
> COLUMNS and LINES aren't immediately updated for me when I change text
> mode resolutions.  Is there something I should do to make them as
> reliable as the tput values?

I don't know about making COLUMNS and LINES accurate, but you could
change them back to the tput system...

((columns=`tput cols`-1, lines=`tput lines`))
-- 
Alan Third


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-04-30 20:05   ` Alan Third
  2001-04-30 20:23     ` Geoff Raye
@ 2001-04-30 22:15     ` Bart Schaefer
  2001-05-02 17:30       ` Alan Third
  2001-05-02 22:26       ` Bruce Stephens
  1 sibling, 2 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-04-30 22:15 UTC (permalink / raw)
  To: zsh-users

On Apr 30,  9:05pm, Alan Third wrote:
> 
> Hi, just for what it's worth, with the help of Bart Schaefer I've
> managed to optimise the code a bit! It also looks a bit more
> interesting whilst it's drawing than before... :)

Just one thing:

> #!/bin/zsh
> 
> ((columns=COLUMNS-1, lines=LINES))
> ((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

With that echo inserted, one can do e.g.

	COLUMNS=60 LINES=20 zmandel

(or whatever you've called this) to draw the set smaller than the actual
screen size.


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-04-30 20:23     ` Geoff Raye
  2001-04-30 20:38       ` Alan Third
@ 2001-04-30 22:19       ` Bart Schaefer
  1 sibling, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-04-30 22:19 UTC (permalink / raw)
  To: zsh-users

On Apr 30,  3:23pm, Geoff Raye wrote:
> Subject: Re: do I win the "most pointless use of ZSH" award? ;)
> 
> COLUMNS and LINES aren't immediately updated for me when I change text
> mode resolutions.

So changing resolutions doesn't send the process a SIGWINCH?

> Is there something I should do to make them as reliable as the tput
> values?

	precmd() { kill -SIGWINCH $$ }

though that's probably overkill (nyuk nyuk nyuk).


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-04-30 22:15     ` Bart Schaefer
@ 2001-05-02 17:30       ` Alan Third
  2001-05-02 22:26       ` Bruce Stephens
  1 sibling, 0 replies; 11+ messages in thread
From: Alan Third @ 2001-05-02 17:30 UTC (permalink / raw)
  To: zsh-users

On Mon, Apr 30, 2001 at 03:15:53PM -0700, Bart Schaefer wrote:
> On Apr 30,  9:05pm, Alan Third wrote:
> > 
> 
> Just one thing:
> 
> > #!/bin/zsh
<snip>
> > 
> > 	echo -n "\\e[4${colour}m "
> >     done
> 
>       echo
> 
> > done
> 
> With that echo inserted, one can do e.g.
> 
> 	COLUMNS=60 LINES=20 zmandel
> 
> (or whatever you've called this) to draw the set smaller than the actual
> screen size.

It also fixes a small bug which seems to occur occasionaly where the
mandelbrot draws out slightly skewed.
-- 
Alan Third

Cows go moo!


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-04-30 22:15     ` Bart Schaefer
  2001-05-02 17:30       ` Alan Third
@ 2001-05-02 22:26       ` Bruce Stephens
  2001-05-02 22:56         ` Bart Schaefer
  1 sibling, 1 reply; 11+ messages in thread
From: Bruce Stephens @ 2001-05-02 22:26 UTC (permalink / raw)
  To: zsh-users

"Bart Schaefer" <schaefer@candle.brasslantern.com> writes:

[...]

> > 	for (( p=0.0, q=0.0, i=0 ; p*p+q*q < 4 && i < 32 ; i++));do

I couldn't get this to work for a while.  It turned out one of my
initialization scripts was setting i to an absolute pathname:

        zsh% i=/foo; for ((i=0; i<10; i++)) echo $i
        zsh: bad math expression: operand expected at `/foo'

Is this a bug or a feature that I'm entirely missing?

[...]


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

* Re: do I win the "most pointless use of ZSH" award? ;)
  2001-05-02 22:26       ` Bruce Stephens
@ 2001-05-02 22:56         ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2001-05-02 22:56 UTC (permalink / raw)
  To: Bruce Stephens, zsh-users

On May 2, 11:26pm, Bruce Stephens wrote:
> Subject: Re: do I win the "most pointless use of ZSH" award? ;)
> "Bart Schaefer" <schaefer@candle.brasslantern.com> writes:
> 
> [...]
> 
> > > 	for (( p=0.0, q=0.0, i=0 ; p*p+q*q < 4 && i < 32 ; i++));do
> 
> I couldn't get this to work for a while.  It turned out one of my
> initialization scripts was setting i to an absolute pathname:

Alan's code was intended to be run as a script, not as a shell function.
To make a shell function of it, you should add:

	local lines columns colour a b p q i pnew

at the top.

>         zsh% i=/foo; for ((i=0; i<10; i++)) echo $i
>         zsh: bad math expression: operand expected at `/foo'
> 
> Is this a bug or a feature that I'm entirely missing?

It's a feature.  The value of any parameter that appears in math context
is evaluated as an expression (up to a maximum recursion depth, I forget
what just now).  So

	i=foo/bar
	((i))

is the same as

	((foo/bar))

and so on for the values of `foo' and `bar'.


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

end of thread, other threads:[~2001-05-02 22:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-27 20:31 do I win the "most pointless use of ZSH" award? ;) Alan Third
2001-04-27 20:52 ` Clint Adams
2001-04-30 19:41 ` David Terrell
2001-04-30 20:05   ` Alan Third
2001-04-30 20:23     ` Geoff Raye
2001-04-30 20:38       ` Alan Third
2001-04-30 22:19       ` Bart Schaefer
2001-04-30 22:15     ` Bart Schaefer
2001-05-02 17:30       ` Alan Third
2001-05-02 22:26       ` Bruce Stephens
2001-05-02 22:56         ` Bart Schaefer

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).