forked from APCSLowell/Dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDice.pde
112 lines (89 loc) · 1.87 KB
/
Dice.pde
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
int count =0;
double ad = 0.00000;
void setup()
{
noLoop();
size(500,500);
}
void draw()
{
background(255);
int a,b;
for(a = 50 ; a< 450 ; a=a+100){
for(b=50 ; b<400 ; b = b + 100){
Die hello = new Die (a,b);
stroke(5);
hello.show();
//hello.sumDice();
fill(255);
noStroke();
rect(20,460,200,50);
fill(0);
text("Sum of dice: " + count,40,480);
fill(255);
rect(200,460,300,50);
fill(0);
text("Average of dice: "+ad,250,480);
}
}
}
void mousePressed()
{
count = 0;
ad = 0.000;
redraw();
}
class Die //models one single dice cube
{
int myX, myY;
int diceNum;
//variable declarations here
Die(int x, int y) //constructor
{
diceNum = (int)(Math.random()*6+1);
myX = x;
myY = y;
count = diceNum + count ;
ad = count/16 ;
}
void show()
{
fill((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
rect(myX,myY,80,80,20);
fill(0);
if(diceNum < 2)
{
ellipse(myX +40,myY + 40,10,10);
}
else if (diceNum < 3) {
ellipse(myX +60 ,myY+20,10,10);
ellipse(myX + 20 ,myY +60,10,10);
}
else if (diceNum < 4) {
ellipse(myX + 40,myY + 40,10,10);
ellipse(myX +60 ,myY+20,10,10);
ellipse(myX + 20 ,myY +60,10,10);
}
else if(diceNum < 5){
ellipse(myX +60,myY +60,10,10);
ellipse(myX + 20,myY+20,10,10);
ellipse(myX +60 ,myY+20,10,10);
ellipse(myX + 20 ,myY +60,10,10);
}
else if(diceNum < 6){
ellipse(myX+40,myY+40,10,10);
ellipse(myX +60,myY +60,10,10);
ellipse(myX + 20,myY+20,10,10);
ellipse(myX +60 ,myY+20,10,10);
ellipse(myX + 20 ,myY +60,10,10);
}
else if(diceNum < 7){
ellipse(myX +20,myY+40,10,10);
ellipse(myX +60,myY + 40,10,10);
ellipse(myX +60,myY +60,10,10);
ellipse(myX + 20,myY+20,10,10);
ellipse(myX +60 ,myY+20,10,10);
ellipse(myX + 20 ,myY +60,10,10);
}
}
}