0

I have to write a function to rotate an image 90 degrees clockwise. I got it to rotate. But it also flipped and rotated counterclockwise. So wrong way, and it flipped along the y-axis. Really weird.

def rotate(self):
	rotatedImage = EmptyImage(self.height, self.width)
	for row in range(self.height):
		for col in range(self.width):
			(r, g, b) = self.image.getPixel2D(col, row)
			rotatedImage.setPixel2D(row, col, (r, g, b))
	self.allImages.append(rotatedImage)

self.height and self.width are the height and width of the original image. self.image is the original image.

Can someone give me a pointer as to where I am messing up and a good direction to proceed?

Thanks.

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by hunterm
0

Figured it out with:

rotatedImage.setPixel2D(self.height - row - 1, col, (r, g, b))
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.