Pixel sorting on an angle

Is there anyone who can help me understand how to change the angle of sorted pixels? Instead of sorting in horizontal lines, how would I implement something like this 45 degree angle?

1 Like

Usually, pixel sorting compares (and possibly swaps) pixels[i] with either pixels[i+width] (for vertical only shifts) or pixels[i+1] (for row sorting).

You might consider comparing pixels[i] to pixels[i+width+1], which would sort them diagonally.

Draw a diagram of the i’th pixel and its surrounding 8 pixels. Work out what the indexes are for those other 8 pixels. That’ll help get you started.

1 Like


There are resources here:

This tutorial may be of interest:

And examples that come with the Processing IDE:

Click to open

Search through the topics to glean some insight.

I did this in one of the topics here in the forum:



1 Like

i think rotating image to change the sort direction only works when the image is quadrate and angle value is particular such as 45 degree and so on
but how can i change the sort direction to some ordinary angle value such as 30/45 degree in any ordinary image?