card dealer

2013-09-27 Thread markotaht
from random import *
from math import floor


kaarte_alles = 52
kaart_tõmmatud = [False for i in range(52)]


mast = ["ärtu", "ruutu", "poti", "risti"]
aste = ["äss", "kaks", "kolm", "neli","viis", "kuus", \
"seitse", "kaheksa", "üheksa", "kümme", "soldat",\
"emand", "kuningas"]

def tõmba_kaart():
global kaarte_alles
if kaarte_alles == 0:
print("Segan pakki")
kaarte_alles = 52
for i in range(52):
kaart_tõmmatud[i] = False
kaarte_alles -= 1
n = random(kaarte_alles)
kaart = vali_järgmine_vaba(n)
m = kaart % 13
a = kaart / 13
print(mast[int(a)] + " " + aste[int(m)])

def vali_järgmine_vaba(n):
i = -1

while(n  > 0):
n -= 1
i = i + 1
while kaart_tõmmatud[i]:
i = i + 1
kaart_tõmmatud[i] = True
return i

def random(n):
return randint(0, n)

while True:
n = int(input("Mitu kaarti tõmmata(0 et väljuda): "))
if(n==0):
break

for i in range(n):
tõmba_kaart()


HI im trying to make a card dealer, but this code doesent work correctly. It 
deasl cards, but the cards to repeat. when i type in 52 ten i might get 3 the 
same cards. This is a translation from my c++ code. In c++ it works correctly.
-- 
https://mail.python.org/mailman/listinfo/python-list


class implementation

2013-09-30 Thread markotaht
Is there a way to give a class extra functions whidout editing the .py file 
where the class is located?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: class implementation

2013-09-30 Thread markotaht
esmaspäev, 30. september 2013 11:43.19 UTC+3 kirjutas mark...@gmail.com:
> Is there a way to give a class extra functions whidout editing the .py file 
> where the class is located?

But does it have all the variables that the main class have?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: class implementation

2013-09-30 Thread markotaht
under variables, i mean, the int's and lists and strings and floats that the 
parent class uses. IF in parent class there is variable called location, then 
can i use the same variable in my sub class.

-- 
https://mail.python.org/mailman/listinfo/python-list


Image manipulation

2013-10-04 Thread markotaht
Is there a way using the python 3.3.2 whidout any additional downloaded moduls, 
to get a pixels RGB value?
-- 
https://mail.python.org/mailman/listinfo/python-list


Odd-length string

2013-10-06 Thread markotaht
print("Key-" + str(võti) + ": " + str(unhexlify("".join(tulemus

IM getting this error on this line. This is the print line of a decryption 
program. I wanti it to convert the tulemus which is in HEX to ASCII so i could 
read it. I could use online translators for the line, but since i have 255 
lines of the HEX codes, it would be higly unefficient.

How to i fix the Oddlenght string?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: class implementation

2013-10-06 Thread markotaht
There is this class file, it has its functions and variables. Now im greating 
my program, that uses the funcions from the class. BUt there are some functions 
missing from the class. So i want to add some extra funtions to the class, 
whidout altering the original source code, but by extending it in my code. But 
for that i need to use some variables that exsist in the original class. Is 
there a way i can acccsess them?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Image manipulation

2013-10-06 Thread markotaht
Image consists of pixels. Each pixel has its RGBA values. In python whidout any 
extra downloadable modules, is there a way to get those values. I know PIG has 
it but i hav Python 3.3.2 so PIG wont do. In java under swingx there is a 
command called .getRGB() and whit some manipulation to that value i can get the 
R G B and A. Is there something similar in python?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Odd-length string

2013-10-06 Thread markotaht
I fixed this problem but encountered new problem. Problem was that some parts 
that came throug my decryption were 00 or 0 the first symbol so the program 
didnt show them. 

NEw problem is : Traceback (most recent call last):
  File "C:\Users\Marko\Desktop\hacker.org\XOR cypher.py", line 35, in 
print("Key-" + str(võti) + ": " + str("".join(tulemus2)))
TypeError: sequence item 0: expected str instance, bytes found

If i  take away the join command i get this: Key-: [b'u', b'o', 
b'\x00', b'\x1d', b' ', b'|', b'N', b'\x0f', b'9', b'j', b'K', b'J', b'&', 
b'#', b'A', b'K', b'5', b'k', b'_', b'\x1e', b',', b'j', b'\x0c', b'\x08', 
b'i', b'(', b'\x06', b'\\', b'r', b'3', b'\x1f', b'V', b's', b'9', b'\x1d']

the Key- is the key im using to decrypt the code. everything else is 
generated byt the decrytion process and the unhexlify command. So my guess is, 
the join command cant handle the b"u" type of format. how can i get rid of the 
b.

Or does anyone have a better idea how to translate HEX into ASCII and sort out 
the lines that make sense
-- 
https://mail.python.org/mailman/listinfo/python-list


HEX to ASCII

2013-10-06 Thread markotaht
 problem is : Traceback (most recent call last): 
  File "C:\Users\Marko\Desktop\hacker.org\XOR cypher.py", line 35, in  
print("Key-" + str(võti) + ": " + str("".join(tulemus2))) 
TypeError: sequence item 0: expected str instance, bytes found 

If i  take away the join command i get this:
 Key-: [b'u', b'o', b'\x00', b'\x1d', b' ', b'|', b'N', b'\x0f', b'9', 
b'j', b'K', b'J', b'&', b'#', b'A', b'K', b'5', b'k', b'_', b'\x1e', b',', 
b'j', b'\x0c', b'\x08', b'i', b'(', b'\x06', b'\\', b'r', b'3', b'\x1f', b'V', 
b's', b'9', b'\x1d'] 

the Key- is the key im using to decrypt the code. everything else is 
generated by the decrytion process and the unhexlify command. So my guess is, 
the join command cant handle the b"u" type of format. how can i get rid of the 
b. 

Or does anyone have a better idea how to translate HEX into ASCII and sort out 
the lines that make sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HEX to ASCII

2013-10-07 Thread markotaht
esmaspäev, 7. oktoober 2013 4:27.44 UTC+3 kirjutas Piet van Oostrum:
> markot...@gmail.com writes:
> 
> 
> 
> >  problem is : Traceback (most recent call last): 
> 
> >   File "C:\Users\Marko\Desktop\hacker.org\XOR cypher.py", line 35, in 
> >  
> 
> > print("Key-" + str(võti) + ": " + str("".join(tulemus2))) 
> 
> > TypeError: sequence item 0: expected str instance, bytes found 
> 
> >
> 
> > If i  take away the join command i get this:
> 
> >  Key-: [b'u', b'o', b'\x00', b'\x1d', b' ', b'|', b'N', b'\x0f', 
> > b'9', b'j', b'K', b'J', b'&', b'#', b'A', b'K', b'5', b'k', b'_', b'\x1e', 
> > b',', b'j', b'\x0c', b'\x08', b'i', b'(', b'\x06', b'\\', b'r', b'3', 
> > b'\x1f', b'V', b's', b'9', b'\x1d'] 
> 
> >
> 
> > the Key- is the key im using to decrypt the code. everything else 
> > is generated by the decrytion process and the unhexlify command. So my 
> > guess is, the join command cant handle the b"u" type of format. how can i 
> > get rid of the b. 
> 
> >
> 
> > Or does anyone have a better idea how to translate HEX into ASCII and sort 
> > out the lines that make sense
> 
> 
> 
> Why do you post the same question twice under different subjects?
> 
> -- 


Because i was told so, cause the subject change so it cant be under there 
anymore.

This is the code i came up with:
from teisendaja import *
from operator import *
import binascii

teisendus = teisendus()
kood = input("Kood: ")
key = input("Võti: ")

chunksize = 2
vastus = [teisendus.teisendus3(16,2,kood[i: (i + chunksize)]) for i in range(0, 
len(kood),chunksize)]
vastus = ["0"*(8-len(x)) + x for x in vastus]
#key = teisendus.teisendus3(10,2,int(key))
getBin = lambda x, n: x >= 0 and str(bin(x))[2:].zfill(n) or "-" + 
str(bin(x))[3:].zfill(n)


def dekrüpteeria(vastus, key):
XOR = []
tulemus = []
for i in range(len(vastus)):
for j in range(8):
XOR.append(str(ixor(int(vastus[i][j]), int(key[j]
tulemus.append("".join(XOR))
key = "".join(XOR)
XOR = []
return tulemus

tulemus2= []
if key == "":
for i in range(256):
võti = getBin(i,8)
tulemus = [teisendus.teisendus3(2,16,i) for i in dekrüpteeria(vastus, 
võti)]
tulemus = ["0"*(2-len(x)) + x for x in tulemus]
   # for j in range(len(tulemus)):
tulemus2.append(binascii.unhexlify("".join(tulemus)))
print("Key-" + str(võti) + ": " + str(tulemus2))
tulemus2 = []
#tulemus = [teisendus.teisendus3(2,16,i) for i in dekrüpteeria(vastus, key)]
#print(":".join(tulemus))

#751a6f1d3d5c3241365321016c05620a7e5e34413246660461412e5a2e412c49254a24

Although this is quite ugly atm. But it serves me well, until i reach the 
unhexlify part. The number and lette r string at the wery end is the mesage im 
trying to decypher. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HEX to ASCII

2013-10-07 Thread markotaht
I forgot to tell. The teisendaja module that i have imported, is a number 
converter that allow to convert numbers from one base to another. i mostly use 
it for HEX to BIN and vice versa, but it supports other bases too.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HEX to ASCII

2013-10-08 Thread markotaht
esmaspäev, 7. oktoober 2013 18:52.21 UTC+3 kirjutas Piet van Oostrum:
> markot...@gmail.com writes:
> 
> 
> 
> > This is the code i came up with:
> 
> > from teisendaja import *
> 
> > from operator import *
> 
> > import binascii
> 
> >
> 
> > teisendus = teisendus()
> 
> > kood = input("Kood: ")
> 
> > key = input("Võti: ")
> 
> >
> 
> > chunksize = 2
> 
> > vastus = [teisendus.teisendus3(16,2,kood[i: (i + chunksize)]) for i in 
> > range(0, len(kood),chunksize)]
> 
> > vastus = ["0"*(8-len(x)) + x for x in vastus]
> 
> > #key = teisendus.teisendus3(10,2,int(key))
> 
> > getBin = lambda x, n: x >= 0 and str(bin(x))[2:].zfill(n) or "-" + 
> > str(bin(x))[3:].zfill(n)
> 
> 
> 
> Instead of boolean and expr1 or expr2 in current Python you can better write:
> 
> expr1 if boolean else expr2.
> 
> and I think using def getBin(x, n):would be more clear. 
> 
> 
> 
> But I have another observation: You use getBin only for positive ints, so the 
> whole '-' case isn't necessary. Actually it would be damaging, as the rest of 
> the code assumes that the key that results from getBin is 8 characters long, 
> whereas in the negative case it would be 9 characters. Also you use 
> int(key[j]) and if key[0] == '-' this would give an error.
> 
> If you just want to get 8 binary digits for an int using format would be 
> simpler:
> 
> 
> 
> getBin = lambda x, n: '{0:={1}b}'.format(x, n)
> 
> or getBin = lambda x, n: '{0:=0{1}b}'.format(x, n) if you want also negatives 
> (but this would give you 7 or eight binary digits, not always 8.)
> 
> 
> 
> 
> 
> > def dekrüpteeria(vastus, key):
> 
> > XOR = []
> 
> > tulemus = []
> 
> > for i in range(len(vastus)):
> 
> > for j in range(8):
> 
> > XOR.append(str(ixor(int(vastus[i][j]), int(key[j]
> 
> > tulemus.append("".join(XOR))
> 
> > key = "".join(XOR)
> 
> > XOR = []
> 
> > return tulemus
> 
> 
> 
> You can use list comprehension:
> 
> 
> 
> def dekrüpteeria(vastus, key):
> 
> tulemus = []
> 
> for i in range(len(vastus)):
> 
> XOR = [(str(ixor(int(vastus[i][j]), int(key[j] for j in range(8)]
> 
> tulemus.append("".join(XOR))
> 
> key = "".join(XOR)
> 
> return tulemus
> 
> 
> 
> and then because you only use "".join(XOR), not XOR itself:
> 
> 
> 
> def dekrüpteeria(vastus, key):
> 
> tulemus = []
> 
> for i in range(len(vastus)):
> 
> XOR = "".join([(str(ixor(int(vastus[i][j]), int(key[j] for j in 
> range(8)])
> 
> tulemus.append(XOR))
> 
> key = XOR
> 
> return tulemus
> 
> 
> 
> and then you could rewrite this also to use a list comprehension for tulemus, 
> but that may make it in a too big one liner.
> 
> 
> 
> Also note that you always use int() on the elements of key and vastus, so it 
> might be simpler to store these as int arrays (lists) instead of strings
> 
> >
> 
> > tulemus2= []
> 
> > if key == "":
> 
> > for i in range(256):
> 
> > võti = getBin(i,8)
> 
> > tulemus = [teisendus.teisendus3(2,16,i) for i in 
> > dekrüpteeria(vastus, võti)]
> 
> > tulemus = ["0"*(2-len(x)) + x for x in tulemus]
> 
> 
> 
> Look at the zfill method for the above 2 line
> 
> 
> 
> Probably
> 
> tulemus = [teisendus.teisendus3(2,16,i).zfill(2) for i in 
> dekrüpteeria(vastus, võti)]
> 
> will do the same
> 
> 
> 
> ># for j in range(len(tulemus)):
> 
> > tulemus2.append(binascii.unhexlify("".join(tulemus)))
> 
> > print("Key-" + str(võti) + ": " + str(tulemus2))
> 
> > tulemus2 = []
> 
> > #tulemus = [teisendus.teisendus3(2,16,i) for i in dekrüpteeria(vastus, key)]
> 
> > #print(":".join(tulemus))
> 
> >
> 
> > #751a6f1d3d5c3241365321016c05620a7e5e34413246660461412e5a2e412c49254a24
> 
> >
> 
> > Although this is quite ugly atm. But it serves me well, until i reach the 
> > unhexlify part. The number and lette r string at the wery end is the mesage 
> > im trying to decypher. 
> 
> 
> 
> The result of unhexlify is a byte string. So tulemus2 is a list of byte 
> strings, which you can joint with xxx = b''.join(tulemus2), and then you have 
> another byte string. If you are sure this is ASCII (which means all bytes are 
> < 128), the you can convert it to a string with str(xxx, 'ascii') or 
> xxx.decode('ascii'). If there are bytes > 127 then you have to know which 
> encoding it is to be able to make a string out of it.
> 
> 
> 
> Is this some known encryption method? If so why not use a standard solution 
> for it? If it is a home brew encryption: are you sure it is safe? Most home 
> brew solutions in encryption are not.
> 
> -- 
> 
> Piet van Oostrum 
> 
> WWW: http://pietvanoostrum.com/
> 
> PGP key: [8DAE142BE17999


Are you familira with the page called hacker.org? THere are tons of challenges. 
And this is one of the cypher challenges called Feedback cypher. The end result 
should be in the format of "The antswer is ." Or something like that. The 
problem is that the

Re: HEX to ASCII

2013-10-08 Thread markotaht
esmaspäev, 7. oktoober 2013 17:16.29 UTC+3 kirjutas Mark Lawrence:
> On 07/10/2013 14:54, markot...@gmail.com wrote:
> 
> > I forgot to tell. The teisendaja module that i have imported, is a number 
> > converter that allow to convert numbers from one base to another. i mostly 
> > use it for HEX to BIN and vice versa, but it supports other bases too.
> 
> >
> 
> 
> 
> That's nice to know, but what has it got to do with the market price of 
> 
> oranges in Timbuktu?  Or to put it another way, you're forcing 
> 
> volunteers to go and find your original message as once again you don't 
> 
> quote any context.  Please make life easier for everybody, including 
> 
> yourself, by quoting something from the original.
> 
> 
> 
> Thanks in anticipation.
> 
> 
> 
> -- 
> 
> Roses are red,
> 
> Violets are blue,
> 
> Most poems rhyme,
> 
> But this one doesn't.
> 
> 
> 
> Mark Lawrence
teisendaja module doesent matter. Only thing that matters about is that it 
returns a string with the converted number.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: class implementation

2013-10-08 Thread markotaht
I cant just subclassing doesent work. It seem the init method of the source 
class also calls out another class. And the problem is, i can subclass the 
other class to with the required function but the end result is that it doesent 
work, since the source class cant accsess the subclass functions. 

The source code is pykkar. 

https://courses.cs.ut.ee/all/MTAT.03.100/2012_fall/uploads/opik/_downloads/pykkar.py

I want to add it a new ability called left(). I cant manipulate the source 
class, cause then my comp will be the only one where the program runs.

class pykkar_l(Pykkar):
def left(self):
self._world.execute("left")

def _cmd_left(self):
headings = (N,E,S,W)
cur_tile = self._get_current_tile() 

cur_heading_index = headings.index(cur_tile.pykkar_heading)
new_heading_index = (cur_heading_index - 1) % 4
cur_tile.pykkar_heading = headings[new_heading_index]

self._update_pykkar_image(cur_tile)

class world_l(World):
def left(self):
self._world.execute("left")

These are my subclasses. For it to work. Class World, must obtain the method 
from subclass world_l
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: class implementation

2013-10-08 Thread markotaht
Parent class is at the link. 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Image manipulation

2013-10-08 Thread markotaht
First helpful advice i have gotten from this forum

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Image manipulation

2013-10-08 Thread markotaht
teisipäev, 8. oktoober 2013 17:26.33 UTC+3 kirjutas Steven D'Aprano:
> On Tue, 08 Oct 2013 07:15:46 -0700, markotaht wrote:
> 
> 
> 
> > First helpful advice i have gotten from this forum
> 
> 
> 
> If you insist on dropping cryptic comments with bad spelling, incoherent 
> 
> sentences, and a complete lack of any context, it might be the last 
> 
> advice you get too.
> 
> 
> 
> Please help us to help you. We are not mind readers, we cannot read your 
> 
> mind and magically understand what you are talking about. Please include 
> 
> content when replying to an posts. Please take the time to try to explain 
> 
> your questions, with proper grammar and syntax and spelling. We will make 
> 
> allowances if English is not your native language, but we won't make 
> 
> allowances if you are just being lazy.
> 
> 
> 
> Please show small code snippets that demonstrate the problem. You should 
> 
> read this site: even though it is written for Java, the basic ideas hold 
> 
> for Python as well.
> 
> 
> 
> http://sscce.org
> 
> 
> 
> 
> 
> Remember that we are volunteers and we are not being paid to help you. 
> 
> The harder you make it for us to understand your posts, the less likely 
> 
> we are to solve your problem.
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Well english isnt my native language, and there are things i just dont know how 
to explain in any language. And i cant give all the codes i am using, since 
there are loads of pieces i do not own, but i know the people who made them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Image manipulation

2013-10-08 Thread markotaht
I rembembered a bit too late, are there any good tutorials for Pillow? 
ImageTk.PhotoImage() keeps giving me error that there isnt such a method.
-- 
https://mail.python.org/mailman/listinfo/python-list


Pygame with python 3.3.2

2013-10-09 Thread markotaht
>From pygame tutorials i copied this example:
import pygame
 
class spritesheet(object):
def __init__(self, filename):
try:
self.sheet = pygame.image.load(filename).convert()
except pygame.error, message:
print('Unable to load spritesheet image:', filename)
raise SystemExit, message
# Load a specific image from a specific rectangle
def image_at(self, rectangle, colorkey = None):
"Loads image from x,y,x+offset,y+offset"
rect = pygame.Rect(rectangle)
image = pygame.Surface(rect.size).convert()
image.blit(self.sheet, (0, 0), rect)
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, pygame.RLEACCEL)
return image
# Load a whole bunch of images and return them as a list
def images_at(self, rects, colorkey = None):
"Loads multiple images, supply a list of coordinates" 
return [self.image_at(rect, colorkey) for rect in rects]
# Load a whole strip of images
def load_strip(self, rect, image_count, colorkey = None):
"Loads a strip of images and returns them as a list"
tups = [(rect[0]+rect[2]*x, rect[1], rect[2], rect[3])
for x in range(image_count)]
return self.images_at(tups, colorkey)

When ever i run it i get syntax error on this line except pygame.error, message:
There are no example to show what happens, because, this doesent even work, 
untile the error is fixed. My guess is, that this has something to do with the 
python versions. But im not very familiar with the changes so i dont know how 
to fix it.
-- 
https://mail.python.org/mailman/listinfo/python-list


öpcaö variable refrenced before assignment

2013-10-09 Thread markotaht
fail4 = "palgad.txt"

f4 = open(fail4, "r")

def koguarv_ridu failis(f):
for i, l in enumerate(f):
pass
return i+1

def palgad(f4):
palgad = 0
while True:
f4r = f4.readline()
if f4r == "":
break
palgad += int(f4r[f4r.find(";")+1:])
return palgad

def kuu_keskmine(palgad, f):
return palgad/koguarv_ridu_failis(f)

print(kuu_keskmine(palgad(f4), f4))


Why does it give me local variable "i" referenced before assignment in 
koguarv_ridu_failis(f) on the return i+1 line
But if i do directly koguarv_ridu_failis(f4) then i get correct antswer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: öpcaö variable refrenced before assignment

2013-10-09 Thread markotaht
So i got it working, by saving palgad in a variable, before printing it and i 
count the lines into a global variable. Ty
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: class implementation

2013-10-10 Thread markotaht
kolmapäev, 9. oktoober 2013 2:55.28 UTC+3 kirjutas Cameron Simpson:
> On 08Oct2013 01:20,  wrote:
> 
> > I cant just subclassing doesent work. It seem the init method of the source 
> > class also calls out another class. And the problem is, i can subclass the 
> > other class to with the required function but the end result is that it 
> > doesent work, since the source class cant accsess the subclass functions. 
> 
> > 
> 
> > The source code is pykkar. 
> 
> > 
> 
> > https://courses.cs.ut.ee/all/MTAT.03.100/2012_fall/uploads/opik/_downloads/pykkar.py
> 
> > 
> 
> > I want to add it a new ability called left(). I cant manipulate the source 
> > class, cause then my comp will be the only one where the program runs.
> 
> > 
> 
> > class pykkar_l(Pykkar):
> 
> > def left(self):
> 
> > self._world.execute("left")
> 
> [...]
> 
> 
> 
> You normally need to call the superclasses' __init__ method as well.
> 
> Example:
> 
> 
> 
> def __init__(self):
> 
> Pykkar.__init__(self)
> 
> ... any of your own init stuff ...
> 
> 
> 
> Likewise for your world_l class.
> 
> 
> 
> BTW, it is conventional to start class names with an upper case letters. Just
> 
> style, but it helps other people when reading your code.
> 
> 
> 
> Cheers,
> 
> --  
> 
> 
> It looks like you've got Mister Bus Error installed.- tjc

OK so I did a took time of and read the pykkar code through. abd I found that 
there is a third class i have to implement. 

This Is the pykkar sourcecode
# coding=UTF-8
"""
Intro and usage
===
Pykkar is a virtual robot living in a virtual world. It can step, turn 90 
degrees right,
paint floor tiles, take and put down traffic cones and push boxes. It can detect
whether there is a wall or other obstacle ahead or whether it's standing on a 
painted
tile. It can be commanded by Python code (either procedural or OOP style)

Pykkar's world can be created by a call to ``create_world`` (when using 
procedural style)
or by instantiating class ``World`` (OOP style). Both take single argument, 
which is
a string representation of the world. Lines in the string represent the rows in 
the world
map. Each character represents one tile. Meaning of characters:

#wall
  plain floor
.painted floor
bbox on plain floor
Bbox on painted floor
^ > v <  pykkar on plain floor without cone 
 (caret, greater-than, lowercase v, less-than)
N E S W  pykkar on painted floor without cone
1 2 3 4 5 6 7 8 9cone stack on plain floor
Csingle cone on painted floor

Sample:

create_world('''

#> #
# 3#

''')

this creates a world where 2x2 floor are is padded with walls. Pykkar is in 
north-west
corner of the floor, looking east and in south-east corner there is a stack of 
3 traffic
cones.

In procedural style, Pykkar can be commanded by calling global functions 
defined in this 
module (eg. ``step()``, ``right()``, etc). There are also functions for 
querying the 
world (``is_wall()``, ``is_box()``, etc). New compound commands can be defined 
by defining 
new functions in client module.

In OOP style, Pykkar is represented by a separate object of class ``Pykkar``. 
In the
start of the program, client code is supposed to create new world (eg. ``w = 
World(layout)``)
and a Pykkar living in that world (eg ``p = Pykkar(w)``). Commands are given by 
calling 
the methods of Pykkar object. New commands should be defined by subclassing 
``Pykkar``. 
"""

"""
Technical stuff

In order to reserve the main thread for executing commands (this way respective 
function calls
can be written in client module's toplevel), tkinter window must run in a 
different thread. 
Unfortunately, tkinter runs reliably only in the main thread of the process. 
For this reason the execution is divided into 2 processes: the "main" process, 
which is just a shallow command proxy and the child process, which runs actual 
program 
logic and presents the world state in a tkinter window.

Main process (ie. user module) normally begins by creating the world (with 
either 
``create_world(...)`` or ``World(...)``). This spawns a child process which 
creates
tkinter window representing the world. Main process then continues by executing
user-provided function/method calls, which amounts to writing respective 
command strings
to child process' stdin and reading results back from child process' stdout.

Main player in child process is an object of class ``_WorldProper``. It keeps 
the 
data structures about world layout, responds to commands that alter the world 
state and runs 
a tkinter window. It reads periodically next command from stdin, acts upon it 
and writes 
result (may be None) to stdout.

NB! as stdout from tkinter process is parsed, you can't just print out debug 
information
to sys.stdout. Use sys.stderr instead!

Reading

Unlimited canvas painting program

2013-10-24 Thread markotaht
How to create a program similar to paint, but the difference would be that the 
cursor would be always in the middle and the canvas moves or the camera is 
always fixed on the cursor as it moves around the canvas. And the canvas should 
be infinite. What would be reasonable to use? 

In addition, i want it to draw a line whidout me having to press a button, just 
move the mouse.

Ill try to think a better way to describe, what i want, but for now i hope this 
is sufficient and clear enough.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unlimited canvas painting program

2013-10-24 Thread markotaht
So, i`ll take the canvas, somekind of mouse tracker, for each mouse location il 
draw a dot or 2X2 square or something. Main thing i have never understood, is 
how can i get the backround to move. 

Lets say ia hve 200X200 window. In the middle of it is the cursor that draws. 
If i move the mouse the cursor doesent move, but the canvas moves. So if i move 
mouse to the left, i get a line that goes to the left. So i probably must 
invert the canvas movement. If mouse goes left, canvas goes right. 

And if possible i would like to save my piece of art aswell :D
-- 
https://mail.python.org/mailman/listinfo/python-list