Java Reference

In-Depth Information

point
(x2, y2)
is
(x1+dx/3, y1+dy/3)
.

point
(x4, y4)
is
(x1 +
2 *
dx / 3, y1 +
2*
dy / 3)
.

point
(x3, y3)
is
((x1 + x5) /2+p*(y1-y5),

(y1+y5)/2+p*(x5-x1))
.

Points
(x2, y2)
and
(x3, y3)
are easy to figure out. The calculation of
(x3,

y3)
is harder; it rests on trig and the fact that all four lines are the same length.

Once procedure
drawFlakeLine
is written, we suggest that you put it in a

subclass of
JFrame
or
JPanel
along with static constants that give the coordi-

nates
(xtop,ytop)
,
(xleft, yleft)
,
(xright, yright)
of an equilateral tri-

angle and a variable
K
and then write this method
paint
:

/**
Draw a Koch snowflake of order
K
by drawing three Koch lines of order

K
from
(xtop, ytop)
to
(xleft, yleft), (xleft, yleft)
to

(xright, yright)
, and
(xright, yright)
to
(xtop, ytop) */

public void
paint(Graphics g)

Figure out suitable values for the points of the main equilateral triangle by exper-

iment.

Search WWH ::

Custom Search