PImage wormImg, wormTexture; // define the two images been used in this example, wormImg and wormTexture
int[] reg = new int[15]; // a group of integer numbers, define 15 elements in this new integer group
void setup() { // at the begining of the program, define initial enviroment (screen size, image type in this example), void, function need to return
size(640, 360, P2D); // screen size, in units of pixels,(width, height, mode), P2D aka processing 2D, renderer of image
noSmooth(); // all geometry with jagged(aliased) edges
// Reference image used to transpose texture
wormImg = loadImage(“wormhole.png”); // load image “wormhole”
wormImg.resize(width, height); // resize the image’s width and height fit 640, 360
wormImg.loadPixels(); // Loads the pixel data for the image into its pixels[] array
// Texture image array
wormTexture = loadImage(“texture.gif”); // load image “texture”
wormTexture.loadPixels();
}
// Moves the bottom row of pixels to the top and shifting remaining pixels 1 over
void shiftup() { // define a fuction named shiftup
for (int k = 0; k < 15; k++) { // value k = 0, if k < 15, put pixels[k] into reg[k], then k = k+1
reg[k] = wormTexture.pixels[k];
}
for (int k = 15; k < 225; k++) { // value k = 15, if k < 225, pixels[k-15] = pixels[k], then k = k+1
wormTexture.pixels[k-15] = wormTexture.pixels[k];
}
for (int k = 0; k < 15; k++) { // value k = 0, if k < 15, pixels[k+210] = reg[k], then k = k+1
wormTexture.pixels[k+210] = reg[k];
}
}
// Moves left column of pixels to the right and shifting remaining pixels 1 over
void shiftright() { // define a fuction named shiftright
for(int k = 0; k < 15; k++) { // value k=0, if k < 15, reg[k] = pixels[15*k+14], then k = k+1
reg[k] = wormTexture.pixels[15*k+14];
for(int i = 14;i > 0; i–) { // at the same time, value i=14, if i>0, pixels[15*k+i] = pixels[15*k+(i-1)], then i=i-1 (move right in unit of 1 pixel)
wormTexture.pixels[15*k+i] = wormTexture.pixels[15*k+(i-1)];
}
wormTexture.pixels[15*k] = reg[k]; // then pixels[15*k] = reg[k] (put the original last pixel to the first of each line)
}
}
void draw() {
// Load pixel data array
loadPixels(); // load the pixels of screen into pixels[]
// Loop through all pixels
for (int i = 0; i < pixels.length; i++){ // value i=0, if i < pixels.length (640*360),
// Map texture to wormhole in a bit shift blue
pixels[i] = wormTexture.pixels[constrain(wormImg.pixels[i] & 0xFF, 0, 224)];
}
updatePixels();
shiftright();
shiftup();
}
Leave a Reply
You must be logged in to post a comment.