KochSnow曲线
在这里实现了Koch曲线,而且提到我们只需要对一个等边三角形的各条边按照Koch曲线的算法进行绘图就能得到KochSnow曲线,将其实现到之前提到的绘图框架中,考虑到KochSnow的实现主要依赖Koch曲线的绘图算法,所以讲KochSnow作为Koch类的子类实现,在这个子类中实现一个新的构造函数,同时重写父类的draw方法,在这个方法中调用三次父类的drawShape方法对三条边进行绘图即可。
package com.elvalad; import java.awt.*; /** * Created by elvalad on 2014/12/29. */ public class KochSnow extends Koch { private double x1; private double y1; private double x2; private double y2; private double x3; private double y3; private Color color = new Color(43, 77, 219); /** * KochSnow曲线构造函数 */ public KochSnow() { super(); } /** * KochSnow曲线构造函数 * @param x1 KochSnow曲线初始三角形顶点1横坐标 * @param y1 KochSnow曲线初始三角形顶点1纵坐标 * @param x2 KochSnow曲线初始三角形顶点2横坐标 * @param y2 KochSnow曲线初始三角形顶点2纵坐标 * @param x3 KochSnow曲线初始三角形顶点3横坐标 * @param y3 KochSnow曲线初始三角形顶点3纵坐标 * @param color KochSnow曲线的颜色 */ public KochSnow(double x1, double y1, double x2, double y2, double x3, double y3, Color color) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; this.x3 = x3; this.y3 = y3; this.color = color; } /** * * @param g */ @Override public void draw(Graphics g) { g.setColor(this.color); super.drawShape(g, this.x1, this.y1, this.x2, this.y2); super.drawShape(g, this.x2, this.y2, this.x3, this.y3); super.drawShape(g, this.x3, this.y3, this.x1, this.y1); } }
-------------------------------
问道,修仙
-------------------------------