⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shimmia.java

📁 processing製作之動態互動圖像,圖像隨滑鼠移動產生形變
💻 JAVA
字号:
import processing.core.*; import processing.xml.*; import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; import java.util.regex.*; public class shimmia extends PApplet {float x,y,t,d,m=50, b, h,v,fa=0.024f,fb=0.008f,aa=12,ab=16, sat=1.0f;int colour;int colours[]=new int[257];//float angle[][]=new float[300][300];float sinArray[]=new float[721];int flipper=1;float triHeight=4, triWidth=6;int xPos, yPos, c, i;float ta,tb,tc,td;float va=0.1f,vb=0.1f,vc=0.1f,vd=0.1f;PImage img;  // Declare variable "a" of type PImagepublic void setup() {   size(300, 300, P3D);   colorMode(HSB, 1.0f);  //stroke(0.5,0.7,1,0.2);  img = loadImage("autumn.jpg");  // Load the image into the program    noStroke();  frameRate(24);   x=0;/*  while (x<width){    y=0;    while (y<height){      angle[(int)x][(int)y]=atan2(x-m, y-m);      y++;    }    x++;  }*/  i=0;  while (i<720){    sinArray[i]=sin((float)i*PI/360.0f);    i++;  }  i=0;  while (i<256){    colours[i]=color(i,i,i);    i++;  }  /*PFont font = loadFont("CourierNew36.vlw");    textFont(font, 12);   */} public float sine(float ang){  while (ang<0) ang+=PI*2;  return sinArray[(int)((ang*360/PI))%720];} public float cosine(float ang){  while (ang<0) ang+=PI*2;  return sinArray[(int)((ang*360/PI)+540)%720];} public void draw(){  ta+=va;  tb+=vb;  tc+=va;  td+=vb;  //if(t<-10.0 && t>-10.2) println ("fps: " + t*10000/millis());  x=0;  background(0);  while (x<300){    y=0;    while (y<300){      h=x+aa* (cosine (((y+x)*fa-ta)))+ab* (cosine (((y+x)*fb+tb)));      v=y+ab* (sine (((x-y)*fb+tc)))+aa* (sine (((y+x)*fa-td)));      //xPos=(int)(h-v+150);      //yPos=(int)(h+v+50);      /*c=(int)(brightness(get(xPos,yPos)))+8;       if (c<0) c=0;       if (c>255) c=255;       colour=colours[c];       	set(xPos,yPos,colour);*/      //fill(y/100,sat,1,0.2);      //noFill();      //stroke(y/100,0.0,1,0.2);      //triangle (xPos, yPos, xPos+triWidth/2, yPos+triHeight*flipper, xPos+triWidth, yPos);      //ellipse (xPos, yPos, triWidth, triWidth);      //text ("O",xPos, yPos);      y+=1;      set((int)x,(int)y,img.get(abs((int)h)%img.width,abs((int)v)%img.width));    }    x+=1;    flipper=-flipper;  }}public void mouseDragged(){  if (mouseButton==LEFT && keyCode==SHIFT && keyPressed==true){    va+=((mouseX-pmouseX)*0.002f);    vb+=((mouseY-pmouseY)*0.002f);    if (va<0) va=0;    if (vb<0) vb=0;  }  else if (mouseButton==LEFT){    fa+=(mouseX-pmouseX)*0.001f;    aa-=(mouseY-pmouseY)*0.1f;      }  else if (mouseButton==RIGHT | (keyPressed == true && keyCode == CONTROL)){    fb+=(mouseX-pmouseX)*0.001f;    ab-=(mouseY-pmouseY)*0.1f;      }        }public void keyPressed(){  if (key=='s') saveFrame ("zoobie-###.tga");  else if (key=='p') {    if (sat==0) sat=0.75f;    else if (sat==1.0f) sat=0.0f;    else sat=1.0f;  }}  static public void main(String args[]) {    PApplet.main(new String[] { "--bgcolor=#c4c4c4", "shimmia" });  }}

⌨️ 快捷键说明

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