Search code examples
pythonjythongetpixeljes

How to turn on Color Wrap in JES


I can't find the answer t this anywhere.

I am using JES. I am creating function with images. I need the color values to wrap;

for example:

if red = 250

250 + 20 = 15

instead of

250 + 20 = 255

Can anybody please tell me, how I can achieve this?


Solution

  • What you're describing is modular arithmetic. You can use the modulo operator to do this:

    def makeChange(pic):
        for p in getPixels(pic):
            r = int(getRed(p))
            g = int(getGreen(p))
            b = int(getBlue(p))
    
            color = makeColor((r + 10) % 255, (g - 20) % 255, (b - 10) % 255)
            setColor(p, color)