# Pixel sorting on an angle

**URL:** <https://discourse.processing.org/t/pixel-sorting-on-an-angle/34206>\
**Category:** Coding Questions\
**Created:** [December 20, 2021, 10:53am UTC](https://discourse.processing.org/t/pixel-sorting-on-an-angle/34206 "2021-12-20T10:53:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![synthetick](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@synthetick](https://discourse.processing.org/u/synthetick)\
**Post date:** [December 20, 2021, 10:53am UTC](https://discourse.processing.org/t/pixel-sorting-on-an-angle/34206/1 "2021-12-20T10:53:12Z")

</div>

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?

 ![Screen Shot 2021-12-20 at 11.44.49 PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a64787777de5e9dd8ee49082d25a0f27f753547d.jpeg)

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [December 20, 2021, 11:08am UTC](https://discourse.processing.org/t/pixel-sorting-on-an-angle/34206/2 "2021-12-20T11:08:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 20, 2021, 11:49am UTC](https://discourse.processing.org/t/pixel-sorting-on-an-angle/34206/3 "2021-12-20T11:49:51Z")

</div>

Hello,

There are resources here:  
[https://processing.org/](https://processing.org/)

This tutorial may be of interest:  
[https://processing.org/tutorials/pixels](https://processing.org/tutorials/pixels)

And examples that come with the Processing IDE:

> **Click to open**
>
> ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f6737a202dd9cbe8ee2e4fcc07c839035d34893a.png)

Search through the topics to glean some insight.

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

![8001d4e5fb6f6d0a8b4462af184689d8b1a01b14_2_357x375](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/57a477e4dc87a6d29de47e8f731454ca136ac447.jpeg)

`:)`

---

<div class="post-metadata">

**Author:** ![wall-e](https://avatars.discourse-cdn.com/v4/letter/w/47e85d/32.png) [@wall-e](https://discourse.processing.org/u/wall-e)\
**Post date:** [July 14, 2022, 9:45am UTC](https://discourse.processing.org/t/pixel-sorting-on-an-angle/34206/4 "2022-07-14T09:45:22Z")

</div>

Hi  
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?
