Jul-06-2019, 08:14 AM
Here's a bit of info. I am creating a simple program (for now) that takes an image, makes it black and white, then using turtle, draws it on the screen.
When y is this the output becomes:
However the problem is, 'x' never increments, it always is 0. There's got to be a simple fix but I can't find it. The only reason I am not using a nested for loop is so that I can increment 'x' and 'y' with different values.
The other problem is how can I speed up the turtle? I am already using 'speed(10)' but it is still very slow when drawing. If I can speed it up a lot that would be nice!
Thanks,
Dream
from PIL import Image
from turtle import *
image_path = "image.png"
loaded_image = None
x, y, old_x = 0, 0, 0
def convert_img():
image_file = Image.open(image_path)
image_file = image_file.convert('L')
image_file.save('bw_image.png')
def get_pix_col(pixels, x, y):
return pixels[x,y]
def draw(img, pixels):
global old_x, x ,y
while x < img.size[0]:
while y < img.size[1]:
pendown()
brightness = get_pix_col(pixels, x, y)
color(brightness, brightness, brightness)
if(x == old_x):
goto((-img.size[0]/2) + x, (-img.size[1]/2) + y)
else:
penup()
goto((-img.size[0]/2) + x, (-img.size[1]/2) + y)
old_x = x
y += 1
x += 1
done()
def main():
convert_img()
loaded_image = Image.open('bw_image.png')
pix = loaded_image.load()
canvas_setup(loaded_image)
draw(loaded_image, pix)
def canvas_setup(img):
colormode(255)
setup(img.size[0], img.size[1])
bgcolor(0, 0, 0)
speed(10)
penup()
setposition(-img.size[0], -img.size[1])
main()The first problem with this is the nested while loops. They should go:Output:x,y:
0,0
0,1
0,2
0,3
0,4
...until 'y' reaches, 562 in the case of my image. But it is whatever the 'y' size of the image is.When y is this the output becomes:
Output:1,0
1,1
1,2
...over and over until 'x' is equal to the x size of the image (1000 in my case).However the problem is, 'x' never increments, it always is 0. There's got to be a simple fix but I can't find it. The only reason I am not using a nested for loop is so that I can increment 'x' and 'y' with different values.
The other problem is how can I speed up the turtle? I am already using 'speed(10)' but it is still very slow when drawing. If I can speed it up a lot that would be nice!
Thanks,
Dream
