OpenGl(jogl)分形算法生成树

本文介绍了如何利用OpenGL和JOGL库来实现分形树的绘制。首先,文章提到了配置环境所需的jar包,并提供了下载链接。接着,详细讲解了两个关键的代码部分——GlPoint类和TreeAnimation类。最后,展示了程序运行后的分形树效果图,指出通过调整角度可以实现树向两边偏移的效果。

一,配置环境

1.需要的jar包

这里写图片描述
jar包的下载地址在这里

二,代码

1,GlPoint类

/**
 * 自定义的点类,存储x和y值
 * @author mcl
 *
 */
public class GlPoint {
   
   

    /*x坐标*/
    float x = 0.00f;
    /*y坐标*/
    float y = 0.00f;

    public GlPoint() {

    }
    public GlPoint(float x, float y) {
        this.x = x;
        this.y = y;
    }
    public float getX() {
        return x;
    }
    public void setX(float x) {
        this.x = x;
    }
    public float getY() {
        return y;
    }
    public void setY(float y) {
        this.y = y;
    }
}

2,TreeAnimation类


import javax.swing.JFrame;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;


/**
 * 实现GLEventListener接口
 * @author mcl
 *
 */
public class TreeAnimation implements GLEventListener{
   
   



    static final String START_POINT_X = "START_POINT_X";
    static final String START_POINT_Y = "START_POINT_Y";
    static final String END_POINT_X = "END_POINT_X";
    static final String END_POINT_Y = "END_POINT_Y";

    double partition = 10.0;


    JSONArray jsonArray = new JSONArray();
    JSONArray jsonArray1 = new JSONArray();
    JSONArray jsonArray2 = new JSONArray();
    JSONArray jsonArray3 = new JSONArray();
    JSONArray jsonArray4 = new JSONArray();

    JSONArray jsonArray5 = new JSONArray();
    JSONArray jsonArray6 = new JSONArray();
    JSONArray jsonArray7 = new JSONArray();


    @Ove
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值