Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
anto21
anto21's Profile
2
Posts
4
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
changing country color
[6 Replies]
04-Jul-2012 12:43 PM
Forum:
Programming Questions
Hi,
I'm trying to reshape the countries with difffrent colors but the coordinates are wrong.
Please, need help
import processing.core.*;
import java.util.*;
public class Co2_Emission extends PApplet {
/**
*
*/
private static final long serialVersionUID = 5138543055487809746L;
// create PShape objects
PShape world;
PFont font, legende, jahre;
int plus = 50;
int z = 240;
boolean started = false;
int mode = 0;
int year = 1;
int j1 = 1;
// CSV data
csv countryData, co2Emission;
ArrayList<PShape> country = new ArrayList<PShape>();
String years[] = new String[] { new String("1990"), new String("1991"),
new String("1992"), new String("1993"), new String("1994"),
new String("1995"), new String("1996"), new String("1997"),
new String("1998"), new String("1999"), new String("2000"),
new String("2001"), new String("2002"), new String("2003"),
new String("2004"), new String("2005"), new String("2006"),
new String("2007"), new String("2008"), new String("2009"),
new String("2010"), };
public void setup() {
size(1450, 680);
smooth();
noLoop();
// load vector graphic
world = loadShape("../Weltkarte.svg");
// load csv
countryData = new csv("../Country.csv");
co2Emission = new csv("../Co2.csv");
frameRate(1);
}
public void draw() {
background(255);
world.enableStyle();
resetMatrix();
shape(world,20,30);
world.disableStyle();
// draw on display
font = createFont("AVGmdBU-48.vlw", 20);
textFont(font);
fill(85, 0, 0);
text("Co2 Emission 1990-2010", 15, 20);
legende = createFont("AVGmdBU-48.vlw", 15);
textFont(legende);
fill(85, 0, 0);
text("Legende \nCo2 pro Person in Tonnen \n 0 - 5 \n 5 - 10 \n 10 - 15 \n 15 - 20 \n 20 - 25 ",
15, 400);
// legend
fill(255, 105, 105);
stroke(255, 0, 0, 99);
rect(15, 440, 15, 10);
fill(255, 65, 65);
stroke(255, 0, 0, 99);
rect(15, 460, 15, 10);
fill(255, 26, 26);
stroke(255, 0, 0, 99);
rect(15, 480, 15, 10);
fill(242, 0, 0);
stroke(255, 0, 0, 99);
rect(15, 500, 15, 10);
fill(203, 0, 0);
stroke(255, 0, 0, 99);
rect(15, 520, 15, 10);
// dunkelste
fill(163, 0, 0);
stroke(242, 0, 0);
rect(15, 540, 15, 10);
// draw lines on display
stroke(85, 0, 0);
line(240, 640, 240, 655);
int x = 240;
for (int i = 0; i < years.length - 1; i++) {
x += plus;
line(x, 640, x, 655);
}
jahre = createFont("AVGmdBU-48.vlw", 15);
textFont(jahre, 15);
int y = 240;
// draw years on display
for (int j = 0; j < years.length; j++) {
text(years[j], y, 640);
y += plus;
}
fill(255);
stroke(170, 0, 0);
ellipse(z, 650, 8, 8);
if (z < 1240) {
z += 50;
}
//
while(mode < 20)
//{
//for(int i = year; i< co2Emission.csv.length;i++) // i == Spalte ; j1 == Zeile
//{
//if(Float.parseFloat(co2Emission.csv[1][2])<= 7.0f)
//{
fill(255, 26, 26);
shape(world.getChild(co2Emission.csv[1][0]));
}
/*else if(Float.parseFloat(co2Emission.csv[i][2]) > 5.0f && Float.parseFloat(co2Emission.csv[i][1]) <= 10.0f)
{
fill(255, 65, 65);
shape(world.getChild(co2Emission.csv[i][0]));
}
else if(Float.parseFloat(co2Emission.csv[i][3])> 10.0f && Float.parseFloat(co2Emission.csv[i][1])<= 15.0)
{
fill(255, 26, 26);
shape(world.getChild(co2Emission.csv[i][0]));
}
else if(Float.parseFloat(co2Emission.csv[i][4])>15.0 && Float.parseFloat(co2Emission.csv[i][1])<= 20.0)
{
fill(242, 0, 0);
shape(world.getChild(co2Emission.csv[i][0]));
}
else if(Float.parseFloat(co2Emission.csv[i][5])>20.0 && Float.parseFloat(co2Emission.csv[i][1])<= 25.0)
{
fill(203, 0, 0);
shape(world.getChild(co2Emission.csv[i][0]));
}
else if(Float.parseFloat(co2Emission.csv[i][6])>25.0)
{
fill(163, 0, 0);
shape(world.getChild(co2Emission.csv[i][0]));*/
//}
//mode++;
//}
//}
//}
public void mousePressed() {
if (started == false) {
loop();
}
started = true;
}
void saveHiRes(int scaleFactor) {
// create a new PGraphics object
PGraphics hires = createGraphics(width * scaleFactor, height
* scaleFactor, JAVA2D);
// everything is drawn as PGraphic
beginRecord(hires);
// and scale
hires.scale(scaleFactor);
draw();
endRecord();
// save PGraphics object as .png
hires.save("hires.svg");
}
float[] getCoords(PShape thisShape)
{
float xMax = 20;
float yMax = 30;
float xMin = width;
float yMin = height;
float[] coords = new float[2];
for(int i = 0; i < thisShape.getVertexCodeCount();i++)
{
if (thisShape.getVertexY(i)>yMax) yMax=thisShape.getVertexY(i);
if (thisShape.getVertexX(i)<xMin) xMin=thisShape.getVertexX(i);
if (thisShape.getVertexY(i)<yMin) yMin=thisShape.getVertexY(i);
}
coords[0]=(xMin+xMax)/2;
coords[1]=(yMin+yMax)/2;
return coords;
}
}
import processing.core.PApplet;
public class csv extends PApplet
{
/**
*
*/
private static final long serialVersionUID = 1L;
public String[][] csv;
public int max = 0;
public csv(String filename)
{
String[] lines = loadStrings(filename);
int csvWidth = 0;
System.out.println(lines.length);
//calculate max width of csv file
for (int i=0; i < lines.length; i++)
{
String[] strings = split(lines[i],';');
if (strings.length > csvWidth)
{
csvWidth = strings.length;
}
}
// csvWidth = 4;
csv = new String[lines.length][csvWidth];//1.Zeile rauswerfen-> also von und 3 Spalte rauswerfen
for (int i=0; i < lines.length; i++)
{
String[] tmp = new String[csvWidth];
tmp = split(lines[i], ";");
for (int j=0; j < tmp.length; j++)
{
tmp[j] = tmp[j].replaceAll("\"", ""); //"" entfernen
tmp[j] = tmp[j].replaceAll(" ", ""); //Leerzeichen entfernen
tmp[j] = tmp[j].replaceAll(":","0"); // bei leeren Feldern das : entfernen
csv[i][j] = tmp[j];
}
}
}
}
processing.app.SketchException: unexpected token: float
[2 Replies]
20-Jun-2012 08:24 AM
Forum:
Programming Questions
Hi !
I'm trying to visualize a school project and now I have a SketchException but can't find it.
Please help me.
// PShape Objekte erzeugen
PShape world;
PShape[] country;
PFont font;
PFont legende;
Table locationTable;
int rowCount;
Table dataTable;
float dataMin = MAX_FLOAT;
float dataMax = MIN_FLOAT;
void setup()
{
size(1450,700);
//Vektorgraphik laden
world = loadShape("Weltkarte.svg");
// Pfade der einzelnen Länder extrahieren
country = world.getChildren();
locationTable = new Table("Table_Country.csv");
rowCount = locationTable.getRowCount();
// read data table
dataTable = new Table("random.csv");
//Find minimum and maximum values
for(int row = 0; row < rowCount; row++)
{
float value = dataTable.getFloat(row,1);
if(value > dataMax)
{
dataMax = value;
}
if(value < dataMin)
{
dataMin = value;
}
}
}
void draw()
{
background(186,194,240);
// Gibt world auf dem Bildschirm aus
shape(world,0,0,0,0);
smooth();
noStroke();
// Beschriftung auf dem Bildschirm
font = loadFont("AVGmdBU-48.vlw");
textFont(font,20);
fill(255);
text("Co2 Emission 1990-2010",15,20);
// Koordinatensystem speichern
pushMatrix();
//Zeichnen der Länder
for(int i = 0;i < country.length;i++)
{
//zeichen der Länder
shape(country[i],20,30);
}
//Koordinatensystem repositionieren
popMatrix();
legende = loadFont("AVGmdBU-48.vlw");
textFont(legende,15);
fill(255);
text("Legende \nCo2 pro Person in Tonnen \n >= \n >= \n >= \n >= \n >=",15,400);
fill(#FFAAAA);
rect(15, 430, 15, 10);
fill(#FF8080);
rect(15, 450, 15, 10);
fill(#FF5555);
rect(15,470,15,10);
fill(#FF2A2A);
rect(15,490,15,10);
fill(#D40000);
rect(15,510,15,10);
for(int row = 0; row < rowCount; row++)
{
String abbrev = dataTable.getRowName(row);
float x = locationTable.getFloat(abbrev,1);
float y = locationTable.getFloat(abbrev, 2);
drawData(x,y,abbrev);
}
}
//Map the size of the ellipse to the data value
void drawData(float x, float y,String abbrev)
{
float value = dataTable.getFloat(abbrev,1);
// Re-map the value to a number between 2 and 40
float mapped = map(value; dataMin;dataMax;2;40);
//Draw an ellipse for this item
ellipse(x,y,mapped,mapped);
}
«Prev
Next »
Moderate user : anto21
Forum