Let’s first open an image so we can resize it.
After
from PIL import Image, ImageFilter
setpos (also can be used as .setposition()) can be used to set a position for turtle.
If you combine it with penup() and pendown() methods you can avoid drawing while positioning the turtle.
turtle.setpos(100,100)
turtle.setposition(100,100)
turtle.goto(100,100)
setx can be used to change the turtle’s positing along the x-axis (horizontally) while vertical position is untouched.
It can be used as: turtle.sety(-200)
to go to 200 below zero horizontally.
sety can be used to change the turtle’s positing along the y-axis (vertically) while horizontal position is untouched.
It can be used as: turtle.sety(-200)
to go to 200 below zero vertically.
This method can be used to set the heading of turtle. While other methods such as left or right can be used to turn and rotate relatively, setheading offers an absolute way to set heading.
For instance, you can use turtle.heading(180)
to turn your turtle to the West.
We can use our newly acquired turtle positioning knowledge to create a simple coat hanger without the hook. I think it actually exists in hotel wardrobes for practicality.
.setpos(x, y)
.setx(x, y)
.goto(x, y)
.sety(x, y)
import turtle
turtle.color("green")
turtle.setpos(-200,-100)
turtle.color("blue")
turtle.setx(200)
turtle.color("orange")
turtle.goto(0,0)
turtle.color("red")
turtle.sety(50)
turtle.exitonclick()
Let’s draw a left single angle quotation mark only using heading and forward with turtle in Python.
Writing the name of this character is almost harder than drawing it with turtle.
.setheading(135)
.fd(100)
.setheading(45)
.forward(100)
import turtle
turtle.color("red")
turtle.setheading(135)
turtle.forward(100)
turtle.setheading(45)
turtle.forward(100)
turtle.exitonclick()
You can hide turtle icon for a better result.
In this Python Tutorial, we’ve seen how to resize an image and different scenarios regarding the new size.
We have also seen hot to get the size of an image and we saw an example regarding how to make use of this information.
You can really see the power of PIL library in image processing as well as basic image editing tasks through these operations.