Come for the quick hacks, stay for the epiphanies. PerlMonks

### spiraling quine

by Len (Friar)
 on Jun 20, 2002 at 15:23 UTC Need Help??

This self-reproducing code prints a turning spirale filled with it's own code. Turning speed depends on processor speed. Comments welcome.
```#!/usr/bin/perl
\$_='
\$q ="\                   47"; wh
ile                           (\$ ;=
\$z                +=              .5 ){
%c=           \$r=0;\$/ ="";whi         le(2
0+          \$z>(\$;+=.05)){\$c{int\$       _+ 2
6+         2*(\$              r+= .0       2) *
s          in\$                   ;}{1       -\$_
+1         0+           int        \$r*c       o s
\$         ;}         =1for(0.       .1)        }\$
t        =r         ever se;\$        /.        =`
c        le        ar     `.         "         #!
/        usr       /bi             n/         pe
rl       \n\       \$_ =\$q        \n"          ;
fo        r\$y        (1..20){\$c{\$_}          {
\$ y       }? \$         /.=chop\$t            :
(\$/        . ="                          \4
0")         for(0.                    .53)          ;
\$/.        ="\n"}pri            nt"\$/\$          q;
s; ".         chr(9 2)."s;;g;eval\n           "}

';s;\s;;g;eval

Replies are listed 'Best First'.
Re: spiraling quine
by thelenm (Vicar) on Jun 20, 2002 at 15:27 UTC
My only complaint is that I don't have the ability to upvote it multiple times. :-) That is absolutely incredible. Good work!!

-- Mike

--
just,my\${.02}

I totaly aggree. That kind of code just shows me how mutch more I have yet to learn. Keep it up Len. (++) :-)

---If it doesn't fit use a bigger hammer
Re: spiraling quine
by Marza (Vicar) on Jun 20, 2002 at 20:06 UTC

Really slick! Only had to change clear to cls as I have a PC.

Really slick! Only had to change clear to cls as I have a PC.

s/PC/DOS or Win32 based PC/;

PCs can run many different operating systems, and Windows is just one of them. Unixish operating systems use "clear", DOS (and Win32) systems use "cls", but it can be something completely different. If you want to extend your computer (or PC :) knowledge, or just dislike Windows' instability, try some operating systems, like Linux or FreeBSD. Many are free.

```- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
```

Re: spiraling quine
by johnirl (Monk) on Jul 12, 2002 at 15:29 UTC
Fantastic Len!!

recently at my first day in my new job my boss said we going to require you to do mostly perl programming. I said no problem always willing to learn a new language. He said we expect you to be up too this level in a few weeks and showed me this code.
Frightened the life out of me.

Cool code though. :-)

Sounds like a cool place to work in :)
Re: spiraling quine
by sschneid (Deacon) on Jun 20, 2002 at 18:10 UTC
(++) ...wow. quite incredible, if i do say so myself.
Re: spiraling quine
by cecil36 (Pilgrim) on Jun 20, 2002 at 20:40 UTC
My upvote has just crossed over into...the Twilight Zone.
Re: spiraling quine
by BrowserUk (Patriarch) on Jun 21, 2002 at 14:09 UTC

Brilliant. A real clever twist on the theme.

Re: spiraling quine
by Anonymous Monk on Jun 21, 2002 at 19:07 UTC
Easily the strangest thing I've seen in code. Jolly good work, Len.
Re: spiraling quine
by RMGir (Prior) on Jun 21, 2002 at 19:54 UTC
Wow.

/msg'd myself, I definitely want to ++ this tomorrow...

What were you drinking when you thought this up, though? :)
--
Mike

Re: spiraling quine
by phrenesis (Initiate) on Jun 21, 2002 at 12:54 UTC
This is really cool, too bad im a n00b and cant vote on it yet :) Phrenesis
Re: spiraling quine
by wufnik (Friar) on Jul 25, 2003 at 12:15 UTC
beautiful; your spiral the best tool for perl evangelism i have know of. should be sent to hofstadter for inclusion in his next volume.

wufnik

-- in the world of the mules there are no rules --
Hypnotic
by perlmoth (Hermit) on Jun 27, 2002 at 12:20 UTC
I lost an hour playing with this code this morning. Now I feel a strange compulsion to ++ all your nodes.
Re: spiraling quine
by ambrus (Abbot) on Feb 18, 2011 at 11:02 UTC

Just like Sparkling Japh, I have to pipe this through

```| perl -we 'use Time::HiRes "sleep"; \$/="\e"; while(<>){ print; sleep
+0.1 }'
so that it becomes enjoyable.
Re: spiraling quine
by PyrexKidd (Monk) on Feb 17, 2011 at 21:20 UTC

In an effort to understand what is going on here, I decided to put the code in a more readable format

```#!/usr/bin/perl
\$_='
\$q="\47";
while(\$; = \$z+ =.5){

%c = \$r = 0;
\$/="";
while(20+\$z>(\$;+=.05)){
\$c
{ int \$_ + 26 + 2 * (\$r += .02) * sin \$; }
{ 1 - \$_ + 10 + int \$r * cos \$; }
= 1for(0..1)
}

\$t = reverse;
\$/ .= `clear` . "#!/usr/bin/perl\n\\$_=\$q\n";
for \$y (1..20){
\$c{\$_}{\$y}
? \$/  .= chop \$t
: (\$/ .= "\40")for(0..53);
\$/.="\n"
}

print "\$/\$q;s;" .chr(92). "s;;g;eval\n"
}
';
s;\s;;g;eval

Quite amazingly it prints the same image in this format. I think it has to do with the sin/cos.

Two things I am unfamiliar with, the \$; variable and this line:

```s;\s;;g;eval

Big props BTW

Re: spiraling quine
by RocketPro (Initiate) on Oct 21, 2002 at 23:56 UTC
Yeah, um... on Windows NT it looks like crap... too bad there isn't a way to clear the window.
The initial version of this code was designed for *nix.

However, there is a Windows version available as well.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://176043]
Approved by ferrency
Front-paged by rob_au
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2023-11-28 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?