Curhat, tutorial, tugas kuliah, dll..

Konsep

Untuk konsep silakan download slide dari sini ajaa (klik di gambarnya)

implementasi dengan processing

Silakan download source code di sini
atau kalau mau copas langsung bisa dari sini


// STANDAR TEMPLATE TUBES GRAFCIT @IT TELKOM | 2011
//--------------------------------- inisialisasi, ga perlu dirubah
static int canvasW = 600;
static int canvasH = 600;
void setup() {
  size(canvasW, canvasH);
  background(255);
}

//--------------------------------- variable global ditulis disini
int xc = 0;
int yc = 0;
float A;
float Px;
float Py;
int rx= 300;
int ry= 150;
int x;
int y;
//--------------------------------- disini mulai codingnya
void draw() {
     
    //----------------------------- region 1
    A =ry*ry-rx*rx*ry+(1/(4*rx*rx));
    
    x=0; y=ry;
    
        drawHelpLines();  
        stdPoint(x+xc,y+yc);
        Px=0;
    Py=2*rx*rx*y;
        while (Px<Py) {
          x=x+1;
          Px=Px+2*ry*ry; 
          if (A>=0) 
            {
             y=y-1;
             Py=Py-2*rx*rx;
             A=A+ry*ry+Px-Py;
          }
          else
          {
             A=A+ry*ry+Px;  
             
          }
            stdPoint(x+xc,y+yc);
             proy4(x,y);
             proy5(x,y);
             proy8(x,y);
            
        }
    //----------------------------- region 2
    stdPoint(x+xc,y+yc);
    A=ry*ry*(x+0.5)*(x+0.5)+rx*rx*(y-1)*(y-1)-rx*rx*ry*ry;
    while (y>0)
    {
        y=y-1;
        Py=Py-2*rx*rx;
        if(A<=0)
        {
            x=x+1;
            Px=Px+2*ry*ry;
            A=A+rx*rx+Px-Py;
        }
        else
        {
            A=A+rx*rx-Py;
        }
        stdPoint(x+xc,y+yc);
        proy4(x,y);
        proy5(x,y);
        proy8(x,y);
    }


    
}      
//--------------------------------- procedure/fungsi bikinan sendiri
//--------------------------------- silahkan ditulis dibawah sini
void proy2(int x, int y)
{
  int a;
  a=y;
  y=x;
  x=a;
  stdPoint(x+xc,y+yc);
}
void proy3(int x, int y)
{
  int a;
  a=y;
  y=-x;
  x=a;
  stdPoint(x+xc,y+yc);
}
void proy4(int x, int y)
{  
  y=-y;
  x=x;
  stdPoint(x+xc,y+yc);
}

void proy5(int x, int y)
{
  x=-x;
  y=-y;
  stdPoint(x+xc,y+yc);
}
void proy6(int x, int y)
{
  int a;
  a=y;
  y=-x;
  x=-a;
  stdPoint(x+xc,y+yc);
}
void proy7(int x, int y)
{
  int a;
  a=y;
  y=x;
  x=-a;
  stdPoint(x+xc,y+yc);
}
void proy8(int x, int y)
{
  x=-x;
  y=y;
  stdPoint(x+xc,y+yc);
}

// -------------------------------- normalisasi, ga perlu dirubah

void stdPoint(int xxx, int yyy)
{
  point(xxx+(canvasW/2), (yyy*-1)+(canvasH/2));
}

void drawHelpLines()
{
  stroke(0, 0, 255);
  for (int z=0; z<canvasW; z=z+1) {
    point((canvasW/2), z);
    point(z, (canvasH/2));
  }
  stroke(0, 0, 0);
}

Kalo code yg di copy ini error, silakan coba yg di download aja, soalnya kadang beberapa syntax suka ilang sendiri kalo di post di web

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: