Wednesday, May 20, 2015

Latihan membuat bola memantul yang berada di dalam kotak dan bisa di lihat dari berbagai sisi dengan cara menggerakkan / menekan mouse :

berikut source codenya :

                        float  speed = 1 / .0125, range = .125, y=0;
                        boolean jalan;
                       float rx = PI / 6, ry = -PI / 6, rmax = PI / 240;
 
                        void setup () {
                                 size (256, 256, P3D);
                         }
   
                        void draw () {
                                 background (255);
   
                        if (!mousePressed) {
                            speed = constrain (dist (128, 128, mouseX, mouseY) / 128, 0, 1) * .02;
                            range = pow (constrain (dist (128, 128, mouseX, mouseY) / 128, 0, 1), 2) * .65;
                        } else {
                            rx = rx + (mouseX - pmouseX) * PI / width;
                            ry = constrain (ry - (mouseY - pmouseY) * PI / height, -HALF_PI, HALF_PI);
                    }
   
                       translate (128, 128, -192);
                       rotateX (ry);
                       rotateY (rx);
                       noFill ();
                       stroke (0, 0, 0, 31);
                       box (256, 256, 256);
   
                       if (y==-60) {
                           jalan=false;
                 };
                   if (y==60) {
                          jalan=true;
                 };
   
                 if(!jalan)
                  y=y+1;
                  else
                 y=y-1;
 
                 translate(0, y);
                 sphere(50);
        }

berikut adalah tampilannya :

========================================================================
** SEMOGA BERMANFAAT :) **

0 komentar:

Post a Comment