Return to the tutorials
Return to the scripting
HDR Shop Scripting - Accessing Pixels
For more advanced operations, you need to change individual pixels. Doing pixel by pixel operations in Javascript is significantly slower than the equivelent C code. However it gives you a lot more control. To set pixels you use another member of the Image class which takes a x,y position (the origin is the top left pixel) and a rgb color as either three floats or a 3x1 float array.
void SetPixel(x,y,r,g,b);
void SetPixel(x,y,c[]);
Here is a script that shows a more unconventional use of pixel operations to create an 1000 frame animation of a fire like effect.
var img = NewImage(128, 128);
img.Clear(0, 0, 0);
for (var x = 0; x < 1000; x++)
{
img.Pan(0, -2);
for (y = 0; y < 9; y++)
{
r = 6000 * Math.random() * Math.random();
g = 6000 * Math.random() * Math.random();
b = 6000 * Math.random() * Math.random();
img.SetPixel(Math.random() * (img.Width - 1),127 r, g, b);
}
img.GaussianBlur(1);
img.Scale(0.87, .81, .7);
Sleep(20);
}

Wierd.js
Return to the scripting
Return to the tutorials