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

📄 nudemengarden.txt

📁 视频交互游戏实验
💻 TXT
📖 第 1 页 / 共 2 页
字号:
       if(!mimosaList[i].readyGrow){
         mimosaList[i] = new Mimosa(x,240,50,int(random(35,110)),true);
         growFinish = true;
       }
     }
   }

 }






 class Mimosa{
   float[] xList = new float[300];
   float[] yList = new float[300];
   float[] leafList = new float[300];
   float thickness;
   int currentLeng; // current Length
   int finalLeng; // final Length
   int leng; //length
   float r;
   float motionDetect = 0;
   float foldFactor = 0;//exclusively for mimosa
   float wind = 0;
   float windPower=0;
   float life;
   boolean readyGrow;
   int mKey;

   Mimosa(float X, float Y, float THICKNESS, int LENG, boolean ready){//instantial the flower
     float x = X;
     float y = Y;
     thickness = THICKNESS;
     leng = LENG;
     currentLeng = 0;
     //    finalLeng = int(random(2,5));
     finalLeng = leng;
     readyGrow = ready;
     for(int j=0; j<leng;j++){
       if(j%7==0){
         leafList[j] = 99;
       }
       if(j%7==3){
         leafList[j] = -99;
       }
     }

     for(int i=0; i<leng; i++){
       xList[i] = x;
       yList[i] = y;
       if(leafList[i]==0){
         leafList[i] = -1;
       }
       y -=1;
     }
//     life =(20*30+int(random(5*30)))*3;
     
     life =(5*30+int(random(5*30)))*3;
//     life =400;
//     mKey = 70;
     mKey = int(random(30,80));
   }

   void grow(){/// frame action
     if (readyGrow) life = max(life-3,0);
     
     float motionDetectP = motionDetect;
     motionDetect = 0;
     for(int i=0; i<currentLeng; i++){
       /////check motion before drawing
       color c = video.get(int(xList[i]),int(yList[i]));
       motionDetect = motionDetect + brightness(c);
     }
     float motionDetected=abs(motionDetect-motionDetectP)/currentLeng;
     if (motionDetected>16 && life>currentLeng){
       windPower = min(motionDetected/5,7);
       foldFactor = 1;
       finalLeng = min(finalLeng+5,leng);
     }
     // life matters
     if (life<currentLeng){
       finalLeng = int(life);
     }
     // life matters
     wind = windPower*sin(millis()*0.006 + xList[1]);
     windPower = max(windPower-0.1,float(leng)/500);
     if (foldFactor>0.9){
       foldFactor *= 0.995;
     }else{
       if (foldFactor>0.5){
         foldFactor *= 0.9;
       }else{
         foldFactor *= 0.5;
       }
     }

     currentLeng = min(currentLeng+1,finalLeng);     
     /////////////////////////////////////

//               println(mKey);

     for(int i=0; i<currentLeng; i++){
       float swing = wind*i/currentLeng*1.3*(1+float(i)/20);// behavior affected by wind
       noStroke();
       fill(166,168,72);
       rectMode(CORNER);


       push();
       translate(xList[i]+swing,yList[i]);
       rect(0,0,2,2);
       pop();
       if(leafList[i]!=-1&& i>currentLeng*0.3){
         push();
         translate(xList[i]+swing,yList[i]);
         float leafRotate = 0;
         if(leafList[i]==99){
           leafRotate = PI/3 - float(i)/currentLeng*(0.75*PI);
           leafRotate = leafRotate*(1-foldFactor) + -PI/2*foldFactor;
         }else
         if(leafList[i]==-99){
           leafRotate = PI - (PI/3 - float(i)/currentLeng*(0.75*PI));
           leafRotate = leafRotate*(1-foldFactor) + 3*PI/2*foldFactor;
         }

         rotate(leafRotate);
         scale(float(i)/300+0.4);
         image(mimosa,0,0);
         pop();
       }
     }
     if(life==0){
       readyGrow=false;
//       growNew("Mimosa");
     }
   }
 }

 ///////////////////////////////////

 class Cactus{
   float[] xList = new float[300];
   float[] yList = new float[300];
   float[] leafList = new float[300];
   float thickness;
   int currentLeng; // current Length
   int finalLeng; // final Length
   int leng; //length
   float r;
   float motionDetect = 0;
   float wind = 0;
   float windPower=0;
   float life;
   boolean readyGrow;

   Cactus(float X, float Y, float THICKNESS, int LENG, boolean ready ){//instantial the flower
     float x = X;
     float y = Y;
     thickness = THICKNESS;
     leng = LENG;
     currentLeng = 0;
     readyGrow = ready;
     //    finalLeng = int(random(2,5));
     finalLeng = leng;
     for(int j=0; j<leng;j++){
       if(j%10==0){
         leafList[j] = PI+PI/20;
       }
       if(j%10==7){
         leafList[j] = -PI/20;
       }
     }


     for(int i=0; i<leng; i++){
       xList[i] = x;
       yList[i] = y;
       if(leafList[i]==0){
         leafList[i] = -1;
       }
       y -=1;
     }
     life =(3*30+int(random(3*30)))*3;
   }

   void grow(){/// frame action
     if (readyGrow) life = max(life-3,0);
     float motionDetectP = motionDetect;
     motionDetect = 0;
     for(int i=0; i<currentLeng; i++){
       /////check motion before drawing
       color c = video.get(int(xList[i]),int(yList[i]));
       motionDetect = motionDetect + brightness(c);
     }
     float motionDetected=abs(motionDetect-motionDetectP)/currentLeng;
     if (motionDetected>25 && life>currentLeng){
       windPower = min(motionDetected/3,5);
       finalLeng = min(finalLeng+3,leng);
     }
     // life matters
     if (life<currentLeng){
       finalLeng = int(life);
     }
     // life matters
     wind = windPower*sin(millis()*0.015 + xList[1]);
     windPower = max(windPower-0.5,0);
     currentLeng = min(currentLeng+1,finalLeng);
     /////////////////////////////////////

     for(int i=0; i<currentLeng; i++){
       float swing = wind*i/currentLeng*1.3*(1+float(i)/20);// behavior affected by wind
       noStroke();
       fill(32,145,119);
       ellipseMode(CENTER_DIAMETER);
       float sectionThickness = float(i)/5+sqrt(thickness)/2;
       r = max(sectionThickness,1);

       push();
       translate(xList[i]-r/2+swing,yList[i]);

       //    ellipse(0,0,r,r);
       if(i==currentLeng-1){
         image(cactusTop,0,-r/2+2,r,r/2);
       }else{
         image(cactus,0,0,r,2);
       }
       pop();

       if(leafList[i]!=-1){
         push();
         if(leafList[i]>PI){
           translate(xList[i]+swing-r/2,yList[i]);
         }else{
           translate(xList[i]+swing+r/2,yList[i]);
         }
         rotate(leafList[i]);
         scale(max(float(i)/400+0.1,0.2));
         image(spike,0,0);
         pop();
       }


     }
     if(life==0){
//       growNew("Cactus");
       readyGrow=false;
     }
   }
 }

 ///////////////////////////////////////////////////////////////////////
 class Flower{
   float[] xList = new float[300];
   float[] yList = new float[300];
   float[] leafList = new float[300];
   float thickness;
   int currentLeng; // current Length
   int finalLeng; // final Length
   int leng; //length
   float r;
   float motionDetect = 0;
   float wind = 0;
   float windPower=0;
   float life;
   boolean readyGrow;
   int flowerType;

   Flower(float X, float Y, float THICKNESS, int LENG, boolean ready ){//instantial the flower
     float x = X;
     float y = Y;
     thickness = THICKNESS;
     leng = LENG;
     currentLeng = 0;
     readyGrow = ready;
    // finalLeng = int(random(2,5));
     finalLeng = leng;
     int leafNumber = int(random(2,8));
     for(int j=0; j<leafNumber;j++){
       int whichNodeToGrow = int(random(leng-7));
       if (random(100)>50){
         leafList[whichNodeToGrow] = PI+PI/8;
       }else{
         leafList[whichNodeToGrow] = -PI/8;
       }
     }

     for(int i=0; i<leng; i++){
       xList[i] = x;
       yList[i] = y;
       if(leafList[i]==0){
         leafList[i] = -1;
       }
       y -=1;
     }
     flowerType = int(random(0.4,flowerImageList.length-0.6 ));

     life =(2*30+int(random(3*30)))*3;

   }

   void grow(){/// frame action
     if (readyGrow) life = max(life-3,0);
     float motionDetectP = motionDetect;
     motionDetect = 0;
     for(int i=0; i<currentLeng; i++){
       /////check motion before drawing
       color c = video.get(int(xList[i]),int(yList[i]));
       motionDetect = motionDetect + brightness(c);
     }
     float motionDetected=abs(motionDetect-motionDetectP)/currentLeng;
     if (motionDetected>20 && life>currentLeng){
       windPower = min(motionDetected/3,7);
       finalLeng = min(finalLeng+5,leng);
     }
     // life matters
     if (life<currentLeng){
       finalLeng = int(life);
     }
     // life matters
     wind = windPower*sin(millis()*0.008 + xList[1]);
     windPower = max(windPower-0.3,float(leng)/500);
     currentLeng = min(currentLeng+1,finalLeng);
     /////////////////////////////////////

     for(int i=0; i<currentLeng; i++){
       float swing = wind*i/currentLeng*1.3*(1+float(i)/20);// behavior affected by wind
       noStroke();
       fill(97,120,27);
       rectMode(CENTER_DIAMETER);
       float sectionThickness = thickness*(1-float(leng-currentLeng+i)/leng);
       r = max(sqrt(sectionThickness),1);

       push();
       translate(xList[i]+swing,yList[i]);
       rect(0,0,r,r);
       pop();
       if(leafList[i]!=-1){
         push();
         translate(xList[i]+swing,yList[i]);
         rotate(leafList[i]);
         scale(0.9*(1-float(leng-currentLeng+i)/(1.5*leng)));
         image(leafImageList[flowerType],0,0);
         pop();
       }

       if(i==currentLeng-1){
         push();
         r = float(i*25/50)+5;
         translate(xList[i]+swing,yList[i]-r/2);
         //      rotate(PI*sin(float(millis())/3000+xList[0]));
         image(flowerImageList[flowerType],-r/2,-r/2,r,r);
         pop();
       }

     }

     if(life==0){
//       growNew("Flower");
      readyGrow=false;
     }
   }

 }

 ///////////////////////////////////

⌨️ 快捷键说明

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