Created
March 24, 2016 00:53
-
-
Save Spaxe/35b71b61b3484b316f7c to your computer and use it in GitHub Desktop.
Sorting image colours by RGB in descending order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Processing 3.0.1 Python mode | |
# Original artist: https://medium.com/@GroundTruth/in-living-color-antarctica-s-vibrant-wildlife-under-the-sea-54ee6f09d662#.maye8r6ws | |
'''Sorts an image by rgb colour and draws them in gradient''' | |
bar_width = 50 | |
w = 1980 | |
h = 1366 | |
def setup(): | |
size(1980, 1366) | |
img = loadImage('test.png') | |
px = [] | |
image(img, bar_width + 3, 0) | |
for x in range(img.width): | |
for y in range(img.height): | |
c = img.get(x, y) | |
px.append((red(c), green(c), blue(c))) | |
px.sort(reverse=True) | |
total = img.width * img.height | |
for i in range(total): | |
c = color(*px[i]) | |
ti = i / float(total) * h | |
stroke(c) | |
line(0, ti, 50, ti) | |
noLoop() | |
def draw(): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment