wormhole.pde

来自「This is processing for java examples.」· PDE 代码 · 共 71 行

PDE
71
字号
/** * Wormhole Demo Effect  * by luis2048. *  * A funnel-shaped hole sucking its texture to the middle. * The effect is accomplished like the tunnel effect but with  * a 15 x 15 texture and static lookup table. The texture is shifted  * and mapped to the static lookup table.  */PImage wormImg, wormTexture;int[] reg = new int[15];void setup() {  size(640, 360, P2D);  noSmooth();  // Reference image used to transpose texture   wormImg = loadImage("wormhole.png");  wormImg.resize(width, height);  wormImg.loadPixels();  // Texture image array  wormTexture = loadImage("texture.gif");  wormTexture.loadPixels();}// Moves the bottom row of pixels to the top and shifting remaining pixels 1 overvoid shiftup() {  for (int k = 0; k < 15; k++) {    reg[k] = wormTexture.pixels[k];  }  for (int k = 15; k < 225; k++) {    wormTexture.pixels[k-15] = wormTexture.pixels[k];  }  for (int k = 0; k < 15; k++) {    wormTexture.pixels[k+210] = reg[k];  }}// Moves left column of pixels to the right and shifting remaining pixels 1 overvoid shiftright() {  for(int k = 0; k < 15; k++) {    reg[k] = wormTexture.pixels[15*k+14];    for(int i = 14;i > 0; i--) {        wormTexture.pixels[15*k+i] = wormTexture.pixels[15*k+(i-1)];    }    wormTexture.pixels[15*k] = reg[k];  }}void draw() {  // Load pixel data array  loadPixels();  // Loop through all pixels  for (int i = 0; i < pixels.length; i++){    // Map texture to wormhole in a bit shift blue     pixels[i] = wormTexture.pixels[constrain(wormImg.pixels[i] & 0xFF, 0, 224)];  }    updatePixels();  shiftright();  shiftup();}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?