• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Mountain a guest Feb 20th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package mountain;
2.
3. import fractal.*;
4.
5. public class Mountain extends Fractal{
6.     private Point p1;
7.     private Point p2;
8.     private Point p3;
9.     private double dev;
10.
11.     public Mountain(Point p1, Point p2, Point p3, double dev){
12.         super();
13.         this.p1 = p1;
14.         this.p2 = p2;
15.         this.p3 = p3;
16.         this.dev = dev;
17.     }
18.
19.     @Override
20.     public String getTitle() {
21.         return "Mountain Fractals";
22.     }
23.
24.     @Override
25.     public void draw(TurtleGraphics turtle) {
26.         turtle.moveTo(p1.getX(), p1.getY());
27.         fractalLine(turtle, order, p1, p2, p3);
28.     }
29.
30.
31.     private void fractalLine(TurtleGraphics turtle, int order, Point p1, Point p2, Point p3) {
32.         if(order == 0) {
33.             drawMinTriangle(turtle, p1, p2, p3);
34.         }
35.         else {
36.             //dev = dev/2;
37.             Point mP1 = mid(p1, p2, dev);
38.             Point mP2 = mid(p2, p3, dev);
39.             Point mP3 = mid(p3, p1, dev);
40.
41.
42.
43.             fractalLine(turtle, order-1, p1, mP1, mP3);
44.             fractalLine(turtle, order-1, p2, mP1, mP2);
45.             fractalLine(turtle, order-1, p3, mP2, mP3);
46.             fractalLine(turtle, order-1, mP1, mP2, mP3);
47.             }
48.     }
49.
50.
51.     /* Gives the point in the "deviated" middle of two points */
52.     private Point mid(Point x1, Point x2, double deviation) {
53.         double rand = RandomUtilities.randFunc(deviation);
54.         Point midPoint = new Point((x1.getX()+x2.getX())/2.0, (x1.getY()+x2.getY())/ 2.0 + rand/2);
55.         return midPoint;
56.     }
57.
58.     private void drawMinTriangle(TurtleGraphics turtle, Point x1, Point x2, Point x3) {
59.         turtle.moveTo(x1.getX(), x1.getY());
60.         turtle.forwardTo(x2.getX(), x2.getY());
61.         turtle.forwardTo(x3.getX(), x3.getY());
62.         turtle.forwardTo(x1.getX(), x1.getY());
63.     }
64.
65.
66.
67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top