Buat pohon pake java…

nyam…nyam searching dpat link bagus neh…sekedar sharing…sapa tw berguna…monggo…
http://www.toves.org/books/java/ch18-recurex/index.html

package Aritmat;

import acm.program.*;
import java.awt.*;
import acm.graphics.*;
/**
 *
 * @author www.toves.org/books/java/ch18-recurex/index.html
 */
public class Pohon extends GraphicsProgram {
    @Override
    public void run(){
            drawTree(120, 200, 50, 80);
    }

    private void drawTree(double i, double i0, double i1, double angle) {
        if(i1 > 2){
            double x1 = i + i1 * GMath.cosDegrees(angle);
            double y1 = i0 - i1 * GMath.sinDegrees(angle);

            add(new GLine(i, i0, x1, y1));
            drawTree(x1, y1, i1 * 0.78, angle + 30);
            drawTree(x1, y1, i1 * 0.66, angle - 50);
        }
    }
}

hasilnya :

gw belum explorer lebih tentang package acm kayaknya cie fungsinya hampir sama ma graphic kali…silahkan dicoba sendiri..:D

One thought on “Buat pohon pake java…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s