-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPurple.java
114 lines (84 loc) · 3.13 KB
/
Purple.java
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
113
114
/*
Program that draws a map from the list of long/lat pairs
Author: Savannah Obregon
Class: CS 1233 01
*/
//import scanner, io.file, color and error
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException; //import for the throw if not found stop
import java.awt.Color;
public class Purple
{
public static void main (String[] args) throws FileNotFoundException
{
if (args.length < 1) //if not enough(proper) inputs
{
System.out.println("Usage: java White <region-symbol>"); //error message
System.exit(-1);
}
Scanner sc = new Scanner(new File("purple/" + args[0] + ".txt")); //call file from input
//reading min long/lat
double xmin = sc.nextDouble();
double ymin = sc.nextDouble(); //y is lat and x is long
//reading max long/lat
double xmax = sc.nextDouble();
double ymax = sc.nextDouble();
//changing window sizing
StdDraw.setCanvasSize(712, 512);
//scale drawing window
StdDraw.setXscale(xmin, xmax);
StdDraw.setYscale(ymin, ymax);
//number of subregions
int num_subregions = sc.nextInt();
//drawing each subregion
for (int i = 0; i < num_subregions; i++)
{
sc.nextLine(); //skip new line
sc.nextLine(); //skip empty line
//get subregion and region from next line in file
String subregion = sc.nextLine();
String region = sc.nextLine();
int num_points = sc.nextInt(); //get number of times to read file from next line
double [] longs = new double [num_points]; //save longitude and latitude in double array
double [] lats = new double [num_points];
for (int j = 0; j < num_points; j++) //drawing subregions
{
longs[j] = sc.nextDouble();
lats[j] = sc.nextDouble();
}
Scanner sck = new Scanner(new File("purple/" + region + args[1] + ".txt")); //use region and argument to call file
sck.nextLine(); //skip line
int red = 0; //set red, green, blue to 0
int green = 0; //use these totals for final formula
int blue = 0;
while (sck.hasNext())
{
double rojo = 0.0; //set rojo, azul and verde to 0
double azul = 0.0; //set to 0.0 for double
double verde = 0.0;
int total = 0;
String a = sck.nextLine();
String [] comp = a.split(","); //split array by comma
//use .contains for name that has portion of name
//set to uppercase
if (comp[0].toUpperCase().contains(subregion.toUpperCase()) || subregion.toUpperCase().contains(comp[0].toUpperCase()))
{
verde = Double.parseDouble(comp[3]); //set r,g,b to respective positions in array
azul = Double.parseDouble(comp[2]);
rojo = Double.parseDouble(comp[1]);
total += verde + azul + rojo; //use += because it is a double and an int (conflicting data types)
green = (int) ((verde / total) * 255); //use formula
blue = (int) ((azul / total) * 255); //set red, green and blue to int
red = (int) ((rojo / total) * 255);
break; //break out of loop
}
}
sck.close(); //close scanner
Color pcolor = new Color(red, green, blue); //set pcolor in separate variable
StdDraw.setPenColor(pcolor); //call pcolor in setPenColor
//draw polygon
StdDraw.filledPolygon(longs, lats);
}
}
}