-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.java
More file actions
executable file
·59 lines (50 loc) · 1.84 KB
/
Utility.java
File metadata and controls
executable file
·59 lines (50 loc) · 1.84 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
import greenfoot.*;
/**
* This is Mr.Cohen's Utility Class
*
* @author (your name)
* @version (a version number or a date)
*/
public class Utility {
/** density should be 1-100. 100 will be almost completely white */
public static GreenfootImage drawStorm(int width, int height, int density) {
Color[] swatch = new Color[64];
int red = 70;
int blue = 192;
// Build a color pallete out of shades of near-white yellow and near-white blue
for (int i = 0; i < swatch.length / 2; i++) { // first half blue tones
swatch[i] = new Color(red, 240, 255);
red += 2;
}
for (int i = swatch.length / 2; i < swatch.length; i++) { // second half yellow tones
swatch[i] = new Color(255, 255, blue);
blue++;
}
// The temporary image, my canvas for drawing
GreenfootImage temp = new GreenfootImage(width, height);
// Run this loop one time per "density"
for (int i = 0; i < density * 50; i++) {
for (int j = 0; j < 100; j++) { // draw 100 circles
int randSize;
// Choose a random colour from my swatch, and set its tranparency randomly
int randColor = Greenfoot.getRandomNumber(swatch.length);
int randTrans = Greenfoot.getRandomNumber(220) + 35; // around half transparent
temp.setColor(swatch[randColor]);
// setTransparency(randTrans);
// random locations for our dot
int randX = Greenfoot.getRandomNumber(width);
int randY = Greenfoot.getRandomNumber(height);
int tempVal = Greenfoot.getRandomNumber(250);
if (tempVal >= 1) {
// randSize = 2;
temp.drawRect(randX, randY, 0, 0);
} else {
randSize = Greenfoot.getRandomNumber(2) + 2;
temp.fillOval(randX, randY, randSize, randSize);
}
// silly way to draw a dot..
}
}
return temp;
}
}