CreateDocsImages
last analyzed

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 101
dl 0
loc 139
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A org.gannacademy.cdf.turtlelogo.docs.CreateDocsImages.resetDirectory(String) 0 3 2
B org.gannacademy.cdf.turtlelogo.docs.CreateDocsImages.main(String[]) 0 113 4
A org.gannacademy.cdf.turtlelogo.docs.CreateDocsImages.site(String) 0 2 1
deleteContents 0 8 ?
site 0 2 ?
resetDirectory 0 3 ?
A org.gannacademy.cdf.turtlelogo.docs.CreateDocsImages.deleteContents(File) 0 8 4
1
package org.gannacademy.cdf.turtlelogo.docs;
2
3
import org.gannacademy.cdf.turtlelogo.Turtle;
4
5
import java.awt.*;
6
import java.io.File;
7
8
public class CreateDocsImages {
9
  public static final String BASE_PATH = "src/org/gannacademy/cdf/turtlelogo/doc-files";
10
11
  private static void deleteContents(File directory) {
12
    File[] contents = directory.listFiles();
13
    if (contents != null) {
14
      for (File file : contents) {
15
        if (file.isDirectory()) {
16
          deleteContents(file);
17
        } else {
18
          file.delete();
0 ignored issues
show
introduced by
Use "java.nio.Files#delete" here for better messages on error conditions.
Loading history...
introduced by
Do something with the "boolean" value returned by "delete".
Loading history...
19
        }
20
      }
21
    }
22
  }
23
24
  private static void resetDirectory(String path) {
0 ignored issues
show
Unused Code introduced by
Remove this unused method parameter "path".
Loading history...
25
    if (!new File(BASE_PATH).mkdirs()) {
26
      deleteContents(new File(BASE_PATH));
27
    }
28
  }
29
30
  private static String site(String name) {
31
    return BASE_PATH + "/" + name + ".png";
32
  }
33
34
  public static void main(String[] args) {
35
    SavableTerrarium terrarium = new SavableTerrarium();
36
    Turtle turtle = new Turtle(terrarium);
37
    resetDirectory(BASE_PATH);
38
39
    // cecil.png
40
    turtle.fd(100);
41
    turtle.lt(90);
42
    turtle.fd(100);
43
    turtle.lt(90);
44
    turtle.fd(100);
45
    turtle.lt(90);
46
    turtle.fd(100);
47
    terrarium.drawTo(site("cecil"));
48
49
    // resize for small figures
50
    terrarium.setSize(148, 92); // 148 is min width, 92:148 is golden ratio
51
52
    // trail.png
53
    terrarium.clear();
54
    turtle.home();
55
    turtle.hd(Turtle.WEST);
56
    for (double i = 0; i < 44; i++) {
57
      turtle.rt(15);
58
      turtle.fd(i / 3.0);
59
    }
60
    terrarium.drawTo(site("trail"));
61
62
    // move.png
63
    terrarium.clear();
64
    turtle.home();
65
    turtle.lt(36);
66
    turtle.tp(5, terrarium.getHeight() - 5);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this subtraction to double.
Loading history...
67
    turtle.to(terrarium.getWidth() - 5, 5);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this subtraction to double.
Loading history...
68
    terrarium.drawTo(site("move"));
69
70
    // turn.png
71
    terrarium.clear();
72
    Turtle[] turtles = new Turtle[8];
73
    int width = 115;
74
    for (int i = 0; i < turtles.length; i++) {
75
      turtles[i] = new Turtle();
76
      turtles[i].tp((terrarium.getWidth() - width) / 2 + width / turtles.length * i, terrarium.getHeight() / 2);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this addition to double.
Loading history...
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this division to double.
Loading history...
77
      turtles[i].lt(180 / turtles.length * i);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this multiplication to double.
Loading history...
78
    }
79
    turtle.tp((terrarium.getWidth() - width) / 2 + width, terrarium.getHeight() / 2);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this addition to double.
Loading history...
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this division to double.
Loading history...
80
    turtle.hd(180);
81
    terrarium.drawTo(site("turn"));
82
    for (int i = 0; i < turtles.length; i++) {
83
      turtles[i].tp(-10, -10);
84
    }
85
86
    // penColor.png
87
    terrarium.clear();
88
    turtle.home();
89
    turtle.tp(20, terrarium.getHeight() / 2);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this division to double.
Loading history...
90
    turtle.pc(Color.red);
91
    turtle.to(terrarium.getWidth() - 20, terrarium.getHeight() / 2);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this subtraction to double.
Loading history...
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this division to double.
Loading history...
92
    terrarium.drawTo(site("penColor"));
93
94
    // penWidth
95
    terrarium.clear();
96
    turtle.tp(20, terrarium.getHeight() / 2);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this division to double.
Loading history...
97
    turtle.pc(Color.green);
98
    turtle.pw(15);
99
    turtle.to(terrarium.getWidth() - 20, terrarium.getHeight() / 2);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this subtraction to double.
Loading history...
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this division to double.
Loading history...
100
    terrarium.drawTo(site("penWidth"));
101
102
    // setBackground
103
    terrarium.clear();
104
    turtle.home();
105
    terrarium.setBackground(Color.pink);
106
    terrarium.drawTo(site("setBackground"));
107
108
    // moveTo
109
    terrarium.clear();
110
    terrarium.setBackground(Color.white);
111
    turtle.pc(Color.black);
112
    turtle.pw(1);
113
    turtle.home();
114
    turtle.lt(36);
115
    turtle.lt(90);
116
    turtle.tp(15, terrarium.getHeight() - 10);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this subtraction to double.
Loading history...
117
    turtle.to(terrarium.getWidth() - 15, 10);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this subtraction to double.
Loading history...
118
    terrarium.drawTo(site("moveTo"));
119
120
    // teleport
121
    terrarium.clear();
122
    turtle.home();
123
    turtle.tp(15, terrarium.getHeight() - 10);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this subtraction to double.
Loading history...
124
    turtles[0].home();
125
    turtles[0].tp(terrarium.getWidth() - 5, 10);
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this subtraction to double.
Loading history...
126
    terrarium.drawTo(site("teleport"));
127
128
    // hide
129
    terrarium.clear();
130
    turtles[0].tp(-10, -10);
131
    turtle.home();
132
    double side = terrarium.getWidth() / 3;
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this division to double.
Loading history...
133
    turtle.tp(side, terrarium.getHeight() - (side / 2));
134
    turtle.lt(60);
135
    turtle.fd(side);
136
    turtle.rt(120);
137
    turtle.fd(side);
138
    turtle.rt(120);
139
    turtle.fd(side);
140
    turtle.ht();
141
    terrarium.drawTo(site("hide"));
142
143
    turtle.st();
144
    terrarium.drawTo(site("show"));
145
146
    System.exit(0);
147
  }
148
}
149