Processing 教程(16)- 图片加载和处理

  • Post author:
  • Post category:其他



实例1:加载图片


把一张图片直接拖入编辑器界面,这样自动会在本程序项目文件夹下创建dada文件夹,图片被复制在dada目录下。





float x;
PImage p1;

void setup(){
    size(720,404);
    background(20);
    x = width;
    frameRate(16);
    p1 = loadImage("f35.png");
    
    
    //size(360,202);
    //fullScreen();
    // ---------------- Variables -------------------
}

void draw(){
  image(p1,x,0);
  x -= 5;
  if (x <= 0) x = 0;  
}

void keyPressed() {
    println("Key Pressed, key (",key,"),  keyCode(", keyCode, ")");  
    if (key == 32) {    
    setup();   
    } 
}


图片会从屏幕右侧向左滑动,滑到左边界时停止;




实例2:随机焦距效果:


float x;
PImage p1;
int frameSpeed;
float t;
void setup(){
    size(720,404);
    background(20);
    x = width;
    frameSpeed = 16;
    frameRate(frameSpeed);
    p1 = loadImage("f35.png");
    t = 0;
    
    //size(360,202);
    //fullScreen();
    // ---------------- Variables -------------------
}

void draw(){
  int x = int(map(noise(t),0,1,0,width-320));
  int y = int(map(noise(t+5),0,1,0,height-180));
  int wi = int(map(noise(t+10),0,1,0,320));
  int hi = int(wi * 9 / 16.0);
  
  
  copy(p1,x,y,wi,hi,0,0,720,404);
  t += 0.01;
}



这个实例,产生动态的变焦式的动画效果。下面是随机截图;






The end.



版权声明:本文为Losacii原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。