-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiamondClass.java
More file actions
69 lines (53 loc) · 1.51 KB
/
DiamondClass.java
File metadata and controls
69 lines (53 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//DiamondClass
import hsa.Console;
import java.awt.*;
class DiamondClass extends SuitClass
{
// Constructors
public DiamondClass ()
{
super ();
setColor (Color.blue);
}
public DiamondClass (int w, int h, int x, int y)
{
super (w, h, x, y);
setColor (Color.blue);
}
public void draw (Console c)
{
// declare two arrays for X & Y coordinates of Diamond
int iPointsX[] = new int [4];
int iPointsY[] = new int [4];
// calculate points on diamond & store in the arrays
iPointsX [0] = iCentreX - iWidth / 2;
iPointsY [0] = iCentreY;
iPointsX [1] = iCentreX;
iPointsY [1] = iCentreY - iHeight / 2;
iPointsX [2] = iCentreX + iWidth / 2;
iPointsY [2] = iCentreY;
iPointsX [3] = iCentreX;
iPointsY [3] = iCentreY + iHeight / 2;
// draw the diamond using methods available from the Console object (c)
c.setColor (cColor);
c.fillPolygon (iPointsX, iPointsY, 4);
}
public void draw (Graphics g)
{
// declare two arrays for X & Y coordinates of Diamond
int iPointsX[] = new int [4];
int iPointsY[] = new int [4];
// calculate points on diamond & store in the arrays
iPointsX [0] = iCentreX - iWidth / 2;
iPointsY [0] = iCentreY;
iPointsX [1] = iCentreX;
iPointsY [1] = iCentreY - iHeight / 2;
iPointsX [2] = iCentreX + iWidth / 2;
iPointsY [2] = iCentreY;
iPointsX [3] = iCentreX;
iPointsY [3] = iCentreY + iHeight / 2;
// draw the diamond using methods available from the Console object (c)
g.setColor (cColor);
g.fillPolygon (iPointsX, iPointsY, 4);
}
}