Erubi

d

Aug 29th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.88 KB | None | 0 0
  1. import turtle
  2. import math
  3. from PIL import Image
  4.  
  5. def pix(x,y,l):
  6.     turtle.setx(6*x)
  7.     turtle.sety(6*y)
  8.     turtle.setheading(0)
  9.     turtle.pd()
  10.     turtle.forward(6)
  11.     turtle.left(90)
  12.     turtle.forward(6)
  13.     turtle.left(90)
  14.     turtle.forward(6)
  15.     turtle.left(90)
  16.     turtle.forward(6)
  17.     turtle.left(90)
  18.     h=0
  19.     turtle.tracer(0, 0)
  20.     if l == 0:
  21.         for g in range(3):
  22.             turtle.forward(1)
  23.             h+=1
  24.             turtle.left(135)
  25.             turtle.forward(h*math.sqrt(2))
  26.             turtle.right(45)
  27.             turtle.forward(1)
  28.             h+=1
  29.             turtle.right(135)
  30.             turtle.forward(h*math.sqrt(2))
  31.             turtle.left(45)
  32.            
  33.         turtle.left(90)
  34.         for g in range(3):
  35.             turtle.forward(1)
  36.             h-=1
  37.             turtle.left(45)
  38.             turtle.forward(h*math.sqrt(2))
  39.             turtle.right(135)
  40.             turtle.forward(1)
  41.             h-=1
  42.             turtle.right(45)
  43.             turtle.forward(h*math.sqrt(2))
  44.             turtle.left(135)
  45.     if l == 1:
  46.         for g in range(2):
  47.             turtle.forward(1)
  48.             h+=1
  49.             turtle.left(135)
  50.             turtle.forward(h*math.sqrt(2))
  51.             turtle.right(45)
  52.             turtle.forward(1)
  53.             h+=1
  54.             turtle.right(135)
  55.             turtle.forward(h*math.sqrt(2))
  56.             turtle.left(45)
  57.             turtle.forward(1)
  58.             h+=1
  59.            
  60.         turtle.left(90)
  61.         for g in range(2):
  62.             turtle.forward(1)
  63.             h-=1
  64.             turtle.left(45)
  65.             turtle.forward(h*math.sqrt(2))
  66.             turtle.right(135)
  67.             turtle.forward(1)
  68.             h-=1
  69.             turtle.right(45)
  70.             turtle.forward(h*math.sqrt(2))
  71.             turtle.left(135)
  72.             turtle.forward(1)
  73.             h-=1
  74.         turtle.left(180)
  75.         turtle.forward(6)
  76.         turtle.left(180)
  77.         for g in range(2):
  78.             turtle.forward(2)
  79.             h+=2
  80.             turtle.left(135)
  81.             turtle.forward(h*math.sqrt(2))
  82.             turtle.right(45)
  83.             turtle.right(135)
  84.             turtle.forward(h*math.sqrt(2))
  85.             turtle.left(45)
  86.             turtle.forward(1)
  87.             h+=1
  88.            
  89.         turtle.left(90)
  90.         for g in range(2):
  91.             turtle.forward(2)
  92.             h-=2
  93.             turtle.left(45)
  94.             turtle.forward(h*math.sqrt(2))
  95.             turtle.right(135)
  96.             turtle.right(45)
  97.             turtle.forward(h*math.sqrt(2))
  98.             turtle.left(135)
  99.             turtle.forward(1)
  100.             h-=1
  101.     if l == 2:
  102.         for g in range(2):
  103.             turtle.forward(2)
  104.             h+=2
  105.             turtle.left(135)
  106.             turtle.forward(h*math.sqrt(2))
  107.             turtle.right(45)
  108.             turtle.right(135)
  109.             turtle.forward(h*math.sqrt(2))
  110.             turtle.left(45)
  111.             turtle.forward(1)
  112.             h+=1
  113.            
  114.         turtle.left(90)
  115.         for g in range(2):
  116.             turtle.forward(2)
  117.             h-=2
  118.             turtle.left(45)
  119.             turtle.forward(h*math.sqrt(2))
  120.             turtle.right(135)
  121.             turtle.right(45)
  122.             turtle.forward(h*math.sqrt(2))
  123.             turtle.left(135)
  124.             turtle.forward(1)
  125.             h-=1
  126.  
  127.     else:
  128.         turtle.forward(6)
  129.         h+=6
  130.         turtle.left(135)
  131.        
  132.  
  133.  
  134.        
  135.  
  136. imagefile = Image.open("C:/Users/trine/OneDrive/Desktop/Untitled.png")
  137. imagedata = imagefile.load()
  138. turtle.shape("turtle")
  139. turtle.speed(0)
  140. width,height=imagefile.size[0],imagefile.size[1]
  141. turtle.screensize(width*8,height*8,'white')
  142. for y in range(height):
  143.     for x in range(width):
  144.         pixeldata = int(round((imagedata[x,y][0]+imagedata[x,y][1]+imagedata[x,y][2])/255))
  145.         pix(x-width/2,height/2-y,pixeldata)
  146.     turtle.update()
Advertisement
Add Comment
Please, Sign In to add comment