Some functions using the modulo-operation (mod, %, remainder) :

basic case: y=x%100, value waves between 0 and 99:

Additions:

addition of two different modulos: y=(x%100+x%79)/2

addition of three: y=(x%100+x%31+x%79)/3. I divide by n to get a result easier to compare, with f'(x)=1 when defined …

addition of four – and we’re approaching a fractal wave: y=(x%100 + x%79 + x%31 + x%17)/4

Subtract:

Subtracting two modulos: y=x%50 -x%30 – tops of the levels are horizontal e.g. f'(x)=0 when defined

and four y=x%50 -x%30 +x%20 -x%12, a ‘city skyline’-function

ZigZags:

A zigzag function: y=|x%(2*m)-m| : m= wave’s height, 2*m = wavelength:

In the javascript-demo I defined a special function for that:

function zigzag(x,m) {

return Math.abs(x%(2*m)-m);

}

adding two zigzags, y=zigzag(x,25) +zigzag(x,15):

… and three, y=zigzag(x,25) +zigzag(x,21)+zigzag(x,15), for a ‘random’ mountain silhuette:

small javascript-demo for testing (try also (x*x)%100 or the ‘barcode’-function: (x*x*x)%150-(x*x*x)%75 )

Pixel Bendel -code as an example of this in 2D, creating a ‘random’ size tiling:

Awesome, well presented, many thanks.

By:

kafkaon September 7, 2008at 12:25 pm

I’d love to see the pixel bender code for the random tile effect — can you link to it?

By:

drunkencopon September 24, 2008at 10:50 am

it’s right here …

By:

pixeleroon September 24, 2008at 12:02 pm

Cool man, the modulu-waves is real similiar to what we call in (musical) Analogue-oscillators “Hard-Sync”,

The 2d example is real cool. attach an oscillator man!

By:

oyd11on November 12, 2008at 5:29 pm

Are you doing modulos division using ActionScript or from within PixelBinder? I’m having trouble doing simple modulo division in PixelBender getting ERROR: (line 35): ‘%’ : syntax error parse error

By:

JP DeVrieson January 23, 2009at 11:30 pm

Figured out the modulo question. This worked

float xr = float(5);

float yr = float(7);

float qer = mod(xr,yr);

Anyone know of a full list of built in PixelBuilder methods…I haven’t found any such thing from Adobe

By:

JP DeVrieson January 24, 2009at 12:00 am

@oyd11 : I might try that some day, I’ve just recently done some first studies with generating Sound with Flash 10.

@JP DeVries :

yes, it’s sometimes %, sometimes mod, see http://en.wikipedia.org/wiki/Modulo_operation

I think you’ll info in Menu:Help/Pixel Bender Specification in the toolkit, on the last pages of that pdf.

btw and generally, one thing sometimes causing extra trouble is that different languages have different practicies when it comes to the sign of a modulo operation with negative values: see http://en.wikipedia.org/wiki/Modulo_operation , second table on the right

By:

pixeleroon January 24, 2009at 8:23 am

thanks pixelero!

I just did my first PixelBender filter, can be seen here

By:

JP DeVrieson January 24, 2009at 9:45 pm

[…] is an article by PIXELERO, he’s to be credited for that and the article is available here: various functions with modulo. I’ve added a greyscale representation underneath to view it as a series of variations on 1 […]

By:

basics in generative art #2 : LINE « HIDIHO!on December 10, 2010at 1:02 pm