# Use a list to updatePixels()

**URL:** <https://discourse.processing.org/t/use-a-list-to-updatepixels/16268>\
**Category:** Processing.py\
**Created:** [December 9, 2019, 3:23pm UTC](https://discourse.processing.org/t/use-a-list-to-updatepixels/16268 "2019-12-09T15:23:47Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 9, 2019, 8:38pm UTC](https://discourse.processing.org/t/use-a-list-to-updatepixels/16268/10 "2019-12-09T20:38:30Z")

</div>

- **filter()** already got the GRAY type: [Py.Processing.org/reference/filter.html](http://Py.Processing.org/reference/filter.html)
- It converts all colors to 1 of the 256 grey tones.
- You state you require 6 shades instead.
- So we just need to use POSTERIZE after GRAY in order to get the desired effect:

```auto
"""
 Gray Posterized PImage (v1.0.1)
 GoToLoop (2019-Dec-09)
 https://Discourse.Processing.org/t/use-a-list-to-updatepixels/16268/10
"""

def hex6Digits(v): return str(hex(v, 6))
def mapToHex(container): return tuple(map(hex6Digits, container))

FILENAME = (
    'https://' 'Upload.Wikimedia.org' '/wikipedia/commons/thumb/2/2e/'
    'Processing_3_logo.png/' '240px-Processing_3_logo.png')

IMGS, NUM_GREYS, COLOR_OCTET, BG = 3, 6, 0xff, 0300
GREY_INTERVAL = COLOR_OCTET / (NUM_GREYS - 1)

GREYS_RANGE = tuple(range(0, COLOR_OCTET + 1, GREY_INTERVAL))
GREYS = tuple(color(grey) for grey in GREYS_RANGE)

print FILENAME
print GREYS_RANGE, len(GREYS_RANGE)
print mapToHex(GREYS), len(GREYS)

def settings():
    global original, greyed, posterized

    original = loadImage(FILENAME)
    greyed, posterized = original.get(), original.get()

    size(IMGS * original.width, original.height)
    noLoop()

def draw():
    background(BG)
    set(0, 0, original)

    transferPixels(original, greyed)
    greyed.filter(GRAY)
    set(width / IMGS, 0, greyed)

    transferPixels(greyed, posterized)
    posterized.filter(POSTERIZE, NUM_GREYS)
    set(2 * width / IMGS, 0, posterized)

    posterized.loadPixels()
    unique_colors = set(mapToHex(posterized.pixels))
    print unique_colors, len(unique_colors)

def transferPixels(src, dst):
    src.loadPixels()
    arrayCopy(src.pixels, dst.pixels)
    dst.updatePixels()

```

---

_[View the full topic](https://discourse.processing.org/t/use-a-list-to-updatepixels/16268)._
