'DrawPixelArea' |
Print Previous Next |
Two specific functions will be described in this chapter. First, MADRIX Script provides a function to be able to retrieve the content of a specific area of the matrix. Second, there is a function which is able to draw pixels onto the matrix using the obtained data field(s) as source. Retrieving Content Of The Matrix The function GetPixelArea retrieves data from the matrix and stores it into a 2-dimensional field of colors. Data is stored in the background at a certain position of the virtual matrix. void GetPixelArea(matrix[][], int xSrc, int ySrc, int w, int h,
Explanation:
color matrix[][]; GetPixelArea(matrix);
Drawing Content Onto The Matrix The function DrawPixelArea copies data from a 2-dimensional field of colors from the background and renders it onto the actual matrix. void DrawPixelArea(matrix[][], int xDst, int yDst, int w, int h, int xSrc, int ySrc, color filter)
Explanation:
color matrix[][]; DrawPixelArea(matrix);
Using Filters For Drawing The filter can be used to leave different color channels of the matrix unchanged. The following example draws just the red and the alpha channel onto the matrix and leaves other channels unchanged: color matrix[][]; color filter = {255, 0, 0, 0, 255}; DrawPixelArea(matrix, 0, 0, -1, -1, 0, 0, filter);
Examples DrawPixelArea (Without Color Filter) The first example for the MAS Script Effect will simply draw a small, red square in the upper left corner of the matrix with a green center. The colors drawn are defined in the field variable matrix[][] in InitEffect. @scriptname=""; @author=""; @version=""; @description="";
color matrix[][];
void InitEffect() { matrix[0][0]=RED; matrix[0][1]=RED; matrix[0][2]=RED; matrix[0][3]=RED; matrix[1][0]=RED; matrix[1][1]=GREEN; matrix[1][2]=GREEN; matrix[1][3]=RED; matrix[2][0]=RED; matrix[2][1]=GREEN; matrix[2][2]=GREEN; matrix[2][3]=RED; matrix[3][0]=RED; matrix[3][1]=RED; matrix[3][2]=RED; matrix[3][3]=RED; }
void RenderEffect() { DrawPixelArea(matrix, 0, 0, -1, -1, 0, 0); }
DrawPixelArea (With Color Filter) The second example for the MAS Script Effect uses a color filter. You will see that it filters the red color channel. As a result, the green center will remain, while the red square will not be displayed anymore. @scriptname=""; @author=""; @version=""; @description="";
color matrix[][]; color filter = {0, 255, 255, 255};
void InitEffect() { matrix[0][0]=RED; matrix[0][1]=RED; matrix[0][2]=RED; matrix[0][3]=RED; matrix[1][0]=RED; matrix[1][1]=GREEN; matrix[1][2]=GREEN; matrix[1][3]=RED; matrix[2][0]=RED; matrix[2][1]=GREEN; matrix[2][2]=GREEN; matrix[2][3]=RED; matrix[3][0]=RED; matrix[3][1]=RED; matrix[3][2]=RED; matrix[3][3]=RED; }
void RenderEffect() { DrawPixelArea(matrix, 0, 0, -1, -1, 0, 0, filter); }
|