from PIL import Image
import csv
filer=open("map_csv.txt","r")
reader=csv.reader(filer,delimiter=";")
rows=0
for x in reader:
    rows=rows+1
filer.seek(0)
r=reader.next()
cols=len(r)
print rows," ",cols
filer.seek(0)
im2=Image.new("RGB",(cols*40,rows*40),"white")
f0=Image.open("textures/grass.png")
f1=Image.open("textures/rock.png")
f2=Image.open("textures/sand.png")
f3=Image.open("textures/water.png")
j=0
i=0
for x in reader:
    for y in x:
        if y=="3": 
            im2.paste(f3,(i,j,i+40,j+40))
        elif y=="2":
            im2.paste(f2,(i,j,i+40,j+40))
        elif y=="1":
            im2.paste(f1,(i,j,i+40,j+40))
        elif y=="0":
            im2.paste(f0,(i,j,i+40,j+40))
        i=i+40
    i=0
    j=j+40
im2.save("new.bmp")
