Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to do draw pattern with python?

Reply
Thread Tools

how to do draw pattern with python?

 
 
Mark Lawrence
Guest
Posts: n/a
 
      09-21-2012
On 21/09/2012 15:29, Peter Otten wrote:
> http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
>> may i know how to shift the bits using only looping and branching??

>
> import time
>
> data = """\
> x....x
> .x..x.
> ..xx..
> ..xx..
> .x..x.
> x....x
>
> """.splitlines()
>
> data = [line * 12 for line in data] # optional
>
> while True:
> print "\x1b[2J\x1b[0;0H" # optional
> for i, line in enumerate(data):
> print line
> data[i] = line[1:] + line[:1]
> time.sleep(.1)
>
> Doing your homework since 2001
>


I tried running your code but got this:-

c:\Users\Mark>pattern.py
File "C:\Users\Mark\pattern.py", line 22
Doing your homework since 2001
^
SyntaxError: invalid syntax

What am I doing wrong?

--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      09-21-2012
On Fri, 21 Sep 2012 11:50:35 -0500, Ismael Farfán <(E-Mail Removed)>
declaimed the following in gmane.comp.python.general:

> 2012/9/21 Peter Otten <(E-Mail Removed)>:
> > (E-Mail Removed) wrote:
> >
> > print "\x1b[2J\x1b[0;0H" # optional

>
> Nice code : )
>
> Could you dissect that weird string for us?


http://www.termsys.demon.co.uk/vtansi.htm
--
Wulfraed Dennis Lee Bieber AF6VN
(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
 
 
 
Hans Mulder
Guest
Posts: n/a
 
      09-22-2012
On 21/09/12 19:32:20, Ian Kelly wrote:
> On Fri, Sep 21, 2012 at 10:50 AM, Ismael Farfán <(E-Mail Removed)> wrote:
>> 2012/9/21 Peter Otten <(E-Mail Removed)>:
>>> (E-Mail Removed) wrote:
>>>
>>> print "\x1b[2J\x1b[0;0H" # optional

>>
>> Nice code : )
>>
>> Could you dissect that weird string for us?
>>
>> It isn't returning the cursor to (0,0), it's just like executing
>> clear(1), and looks like those line coloring scape sequences for bash.

>
> They're called "ANSI escape codes".
>
> CSI 2J clears the screen.
> CSI 0;0H means "move the cursor to row 0, column 0". However, I don't
> think that's valid ANSI, as the coordinates are 1-based. Probably it
> should have been "\x1b[2J\x1b[1;1H".


Yes, the coordinates are 1-base, so it should have been
"\x1b[2J\x1b[1;1H". Or, since 1;1 is the default, "\x1b[2J\x1b[H".

On my machine, clear(1) uses "\x1b[H\x1b[2J".

Using clear(1) appears to be the most portable way to do it:

import os, time

data = """\
x....x
..x..x.
...xx..
...xx..
..x..x.
x....x

""".splitlines()

data = [line * 12 for line in data] # optional

try:
while True:
os.system("clear") # optional
for i, line in enumerate(data):
print line
data[i] = line[1:] + line[:1]
time.sleep(.1)
except KeyboardInterrupt:
pass



Hope this helps,

-- HansM
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:25 PM
May I have a example of design pattern of "composite", I still feel fuzzy after reading book of Addison-Wesley's"design pattern " jones9413@yahoo.com C++ 1 08-31-2007 04:09 AM
documents related to factory design pattern and Abstract foctory pattern. sunny C++ 1 12-07-2006 04:26 AM
boolean endsWith(String s, Pattern pattern) lepikhin@gmail.com Java 17 11-16-2005 10:31 AM



Advertisments