radialpocky.pde

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

PDE
75
字号
/**  * Radial Pocky * by Ben Fry.  *  * Unwrap each frame of live video into a single line of pixels along a circle */     import processing.video.*;Capture video;int videoCount;int currentAngle;int pixelCount;int angleCount = 200;  // how many divisionsint radii[];int angles[];void setup() {  // size must be set to video.width*video.height*2 in both directions  size(960, 540);   // Uses the default video input, see the reference if this causes an error  video = new Capture(this, 24, 16);  videoCount = video.width * video.height;  pixelCount = width*height;  int centerX = width / 2;  int centerY = height / 2;  radii = new int[pixelCount];  angles = new int[pixelCount];  int offset = 0;  for (int y = 0; y < height; y++) {    for (int x = 0; x < width; x++) {      int dx = centerX - x;      int dy = centerY - y;      float angle = atan2(dy, dx);      if (angle < 0) angle += TWO_PI;      angles[offset] = (int) (angleCount * (angle / TWO_PI));      int radius = (int) mag(dx, dy);      if (radius >= videoCount) {        radius = -1;        angles[offset] = -1;      }      radii[offset] = radius;            offset++;    }  }  background(0);}void draw() {  if (video.available()) {    video.read();    video.loadPixels();      loadPixels();    for (int i = 0; i < pixelCount; i++) {      if (angles[i] == currentAngle) {        pixels[i] = video.pixels[radii[i]];      }    }    updatePixels();        currentAngle++;    if (currentAngle == angleCount) currentAngle = 0;  }}

⌨️ 快捷键说明

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