Question

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?

Was it helpful?

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)

OTHER TIPS

Blender gave me an idea:

def makeChange(pic):
  for p in getPixels(pic):
    r=int(getRed(p))
    g=int (getGreen(p))
    b=int (getBlue(p ))
    if (r +10) >255: 
      newR= r -255 +10
    else:
      newR= r+10
    if (g -20) <0:
      newG= g +255 -20
    else:
      newG=g-20
    if (b-10) <0:
      newB = b +255 -10
    else:
      newB =b-10
    color = makeColor (newR,newG,newB)
    setColor(p,color)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top