We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Sorry for the length of the post, but I'm new to processing, but LOVE IT. I want to try and get better and am working with some of the texts on offer, but am having difficulty with my current project. Below is the looong code I have so far, and following it is the arrays I am trying to use to really compress it.
//SHAPES
PShape p;
// FAR NORSIDE
PShape LS;
PShape RP;
PShape WR;
PShape UPT;
PShape LINC;
PShape AP;
PShape EW;
PShape NP;
PShape FG;
PShape JP;
PShape NWP;
PShape EP;
PShape OHA;
// NORTHSIDE
PShape NC;
PShape LP;
PShape LV;
PShape AV;
// CENTRAL
PShape NN;
PShape NS;
PShape LOOP;
// SOUTHSIDE
PShape OAK;
PShape FUL;
PShape ARM;
PShape KEN;
PShape WASH;
PShape HYDE;
PShape GRA;
PShape DOUG;
PShape WOOD;
PShape BRI;
PShape SSH;
PShape GGC;
//FAR SOUTHEASTSIDE
PShape A;
PShape CH;
PShape PO;
PShape AVP;
PShape ES;
PShape CHA;
PShape SC;
PShape WPUL;
PShape RIV;
PShape ROS;
PShape HEG;
PShape SD;
//FAR SOUTHWEST SIDE
PShape MOUNT;
PShape WH;
PShape MP;
PShape AG;
PShape BEV;
PShape ASH;
//SOUTHWEST SIDE
PShape WEL;
PShape MC;
PShape AH;
PShape GP;
PShape LAWN;
PShape DP;
PShape ENG;
PShape WL;
PShape WEW;
PShape CL;
PShape GR;
PShape NEW;
// NORTHWEST SIDE
PShape MONT;
PShape HO;
PShape IP;
PShape DU;
PShape BEL;
PShape PP;
// WESTSIDE
PShape WGP;
PShape EGP;
PShape LWS;
PShape NL;
PShape HP;
PShape SL;
PShape WT;
PShape NWS;
PShape AU;
PShape lines;
//FLOATS
float diameter;
float radius = 10;
boolean a = false;
void setup () {
size(720, 720);
}
void draw() {
background(200);
ellipseMode(RADIUS);
fill(0, 0, 0);
ellipse(418.819, 194.913, radius, radius);
if (dist(418.819, 194.913, mouseX, mouseY) < radius+2) {
fill(0);
ellipse(110, 600, 100, 100);
textAlign(CENTER);
fill(255);
text("Logan Square - 73,595", 110, 600);
}
ellipse(457.675, 35.429, radius, radius);
if (dist(457.675, 35.429, mouseX, mouseY) < radius+2) {
fill(0);
ellipse(110, 600, 100, 100);
textAlign(CENTER);
fill(255);
text("Rogers Park - 54991", 110, 600);
}
ellipse(421.67, 51.769, radius, radius);
if (dist(421.67, 51.769, mouseX, mouseY) < radius+2) {
fill(0);
ellipse(110, 600, 100, 100);
textAlign(CENTER);
fill(255);
text("West Ridge - 71942", 110, 600);
}
ellipse(484.352, 116.866, radius, radius);
if (dist(484.352, 116.866, mouseX, mouseY) < radius+2) {
fill(0);
ellipse(110, 600, 100, 100);
textAlign(CENTER);
fill(255);
text("Uptown - 56362", 110, 600);
}
// KEY
//FAR NORTHSIDE
fill (0, 150, 0);
rect(90, 250, 20, 20);
textAlign(LEFT);
fill(0);
text("Far North Side", 120, 265);
//NORTHSIDE
fill (150, 0, 0);
rect(90, 280, 20, 20);
textAlign(LEFT);
fill(0);
text("North Side", 120, 295);
//CENTRAL
fill (0, 0, 150);
rect(90, 310, 20, 20);
textAlign(LEFT);
fill(0);
text("Central", 120, 325);
//SOUTHSIDE
fill (100, 100, 150);
rect(90, 340, 20, 20);
textAlign(LEFT);
fill(0);
text("Southside", 120, 355);
//FAR SOUTHEAST SIDE
fill (50, 100, 150);
rect(90, 370, 20, 20);
textAlign(LEFT);
fill(0);
text("Far South-East Side", 120, 385);
//FAR SOUTHWESTSIDE
fill(50, 120, 50);
rect(90, 400, 20, 20);
textAlign(LEFT);
fill(0);
text("Far South-East Side", 120, 415);
// WESTSIDE
fill(211, 200, 68);
rect(90, 430, 20, 20);
textAlign(LEFT);
fill(0);
text("Westside", 120, 445);
//NORTH WEST SIDE
fill(87, 25, 66);
rect(90, 460, 20, 20);
textAlign(LEFT);
fill(0);
text("North-Westside", 120, 475);
p = loadShape("neighbourhood maps-01.svg");
lines = p.getChild("lines");
// FAR NORSIDE
UPT = p.getChild("UPT");
RP = p.getChild("RP");
WR = p.getChild("WR");
LINC = p.getChild("LINC");
EW = p.getChild("EW");
AP = p.getChild("AP");
NP = p.getChild("NP");
FG = p.getChild("FG");
JP = p.getChild("JP");
NWP = p.getChild("NWP");
EP = p.getChild("EP");
OHA = p.getChild("OHA");
//NORTHSIDE
LS = p.getChild("LS");
LP = p.getChild("LP");
NC = p.getChild("NC");
LV = p.getChild("LV");
AV = p.getChild("AV");
p.disableStyle();
noStroke();
// CENTRAL
NN = p.getChild("NN");
LOOP = p.getChild("LOOP");
NS = p.getChild("NS");
//SOUTHSIDE
OAK = p.getChild("OAK");
FUL = p.getChild("FUL");
ARM = p.getChild("ARM");
KEN = p.getChild("KEN");
WASH = p.getChild("WASH");
HYDE = p.getChild("HYDE");
GRA = p.getChild("GRA");
DOUG = p.getChild("DOUG");
WOOD = p.getChild("WOOD");
BRI = p.getChild("BRI");
SSH = p.getChild("SSH");
GGC = p.getChild("GGC");
//FAR SOUTHEASTSIDE
A = p.getChild("A");
CH = p.getChild("CH");
PO = p.getChild("PO");
AVP = p.getChild("AVP");
ES = p.getChild("ES");
CHA = p.getChild("CHA");
SC = p.getChild("SC");
WPUL = p.getChild("WPUL");
RIV = p.getChild("RIV");
ROS = p.getChild("ROS");
HEG = p.getChild("HEG");
SD = p.getChild("SD");
//FAR SOUTHWESTSIDE
MOUNT = p.getChild("MOUNT");
WH = p.getChild("WH");
MP = p.getChild("MP");
AG = p.getChild("AG");
BEV = p.getChild("BEV");
ASH = p.getChild("ASH");
//SOUTHWEST SIDE
WEL = p.getChild("WEL");
MC = p.getChild("MC");
AH = p.getChild("AH");
GP = p.getChild("GP");
LAWN = p.getChild("LAWN");
DP = p.getChild("DP");
ENG = p.getChild("ENG");
WL = p.getChild("WL");
WEW = p.getChild("WEW");
CL = p.getChild("CL");
GR = p.getChild("GR");
NEW = p.getChild("NEW");
// NORTHWEST SIDE
MONT = p.getChild("MONT");
HO = p.getChild("HO");
IP = p.getChild("IP");
DU = p.getChild("DU");
BEL = p.getChild("BEL");
PP = p.getChild("PP");
// WESTSIDE
WGP = p.getChild("WGP");
EGP = p.getChild("EGP");
LWS = p.getChild("LWS");
NL = p.getChild("NL");
HP = p.getChild("HP");
SL = p.getChild("SL");
WT = p.getChild("WT");
NWS = p.getChild("NWS");
AU = p.getChild("AU");
shapeMode(CORNER);
//APPLY SIZE AND COLOR TO NEIGHBOURHOODS
// shape(lines, 0,0);
//NORTHSIDE
LS.disableStyle();
fill(150, 0, 0);
shape(LS, 0, 0);
shape(NC, 0, 0);
shape(LP, 0, 0);
shape(LV, 0, 0);
shape(AV, 0, 0);
// FAR NORSIDE
UPT.disableStyle();
fill(0, 150, 0);
shape(UPT, 0, 0);
shape(RP, 0, 0);
shape(WR, 0, 0);
shape(LINC, 0, 0);
shape(EW, 0, 0);
shape(AP, 0, 0);
shape(NP, 0, 0);
shape(FG, 0, 0);
shape(JP, 0, 0);
shape(NWP, 0, 0);
shape(EP, 0, 0);
shape(OHA, 0, 0);
//CENTRAL
LOOP.disableStyle();
fill(0, 0, 150);
shape(LOOP, 0, 0);
shape(NN, 0, 0);
shape(NS, 0, 0);
//SOUTHSIDE
OAK.disableStyle();
fill(100, 100, 150);
shape(OAK, 0, 0);
shape(FUL, 0, 0);
shape(ARM, 0, 0);
shape(KEN, 0, 0);
shape(WASH, 0, 0);
shape(HYDE, 0, 0);
shape(GRA, 0, 0);
shape(DOUG, 0, 0);
shape(WOOD, 0, 0);
shape(BRI, 0, 0);
shape(SSH, 0, 0);
shape(GGC, 0, 0);
//FAR SOUTHEASTSIDE
A.disableStyle();
fill(50, 100, 150);
shape(A, 0, 0);
shape(CH, 0, 0);
shape(PO, 0, 0);
shape(AVP, 0, 0);
shape(ES, 0, 0);
shape(CHA, 0, 0);
shape(SC, 0, 0);
shape(WPUL, 0, 0);
shape(RIV, 0, 0);
shape(ROS, 0, 0);
shape(HEG, 0, 0);
shape(SD, 0, 0);
//FAR SOUTHWESTSIDE
WH.disableStyle();
fill(50, 120, 50);
// shape(MOUNT, 0, 0);
shape(WH, 0, 0);
shape(MP, 0, 0);
shape(AG, 0, 0);
shape(BEV, 0, 0);
shape(ASH, 0, 0);
//SOUTHWEST SIDE
WEL.disableStyle();
fill(75, 100, 75);
shape(WEL, 0, 0);
shape(MC, 0, 0);
shape(AH, 0, 0);
shape(GP, 0, 0);
shape(LAWN, 0, 0);
shape(DP, 0, 0);
shape(ENG, 0, 0);
shape(WL, 0, 0);
shape(WEW, 0, 0);
shape(CL, 0, 0);
shape(GR, 0, 0);
shape(NEW, 0, 0);
//NORTH WEST SIDE
MONT.disableStyle();
fill(87, 25, 66);
shape(MONT, 0, 0);
shape(HO, 0, 0);
shape(IP, 0, 0);
shape(DU, 0, 0);
shape(BEL, 0, 0);
shape(PP, 0, 0);
// WESTSIDE
WGP.disableStyle();
fill(211, 200, 68);
shape(WGP, 0, 0);
shape(EGP, 0, 0);
shape(LWS, 0, 0);
shape(NL, 0, 0);
shape(HP, 0, 0);
shape(SL, 0, 0);
shape(WT, 0, 0);
shape(NWS, 0, 0);
shape(AU, 0, 0);
smooth();
noStroke();
// shape(LS, 418.819, 180.913, 200, 200);
}
VERSION 2
int[] t = new int[34];
PShape[] n = new PShape[34];
float[] x = new float[34];
float[] y = new float[34];
int rowCount;
Table locationTable;
void setup() {
size (720, 720);
smooth();
noStroke();
fill(255);
ellipseMode(RADIUS);
locationTable = loadTable ("neighbourhoods_data.csv");
rowCount = locationTable.getRowCount( );
for (int i = 0; i < rowCount; i++) {
float x[i] = locationTable.getFloat(row, 2);
float y[i] = locationTable.getFloat(row, 3);
int t[i] = locationTable.getInt(row, 4);
// PShape n = locationTable.(row,1);
}
void draw() {
int t[i] = map(t[i], 10000, 100000, 10, 100);
ellipse(x, y, t, t);
}
Obviously I haven't finished it yet, but am working on it - I'm trying to read from a table (pictured below) and think it should work, but unfortunately I am getting a error - "unexpected token: float" on line 21 - " float x[i] = locationTable.getFloat(row, 2);" and I imagine I will get it for line 22 and 23 also, but am not sure why. I figured if I could get this working and draw some ellipses I'll know I'm going in the right direction!
Thanks for your time,
Tom
Answers
Obviously I have not got your data file so I can't test your code but you are missing a } at line 26. You can see from the indentation that it thinks the draw method is part of the setup method. Try this and see if it fixes the problem.
Remember that every { must have a matching }. If you put the cursor behing a { or } Processing will highlight what it thinks is the matching one.
Also should
not be
If you look in Processing's JavaDoc under Table class you will find:
getFloatColumn(int col)
and
getFloatColumn(String name)
those methods are both returning arrays of floats containing all values of specified column. That may make things easier, but… they are not in reference page for table I don't know why.
I finally looked at it and thought I had figured out the problem - mixing ints and floats:
So I changed it to:
But I'm still getting the"unexpected token: float" error message.
Also what is the difference between Float and float - they seem to act differently.
Most obvious bug is that you're redeclaring variables x & y inside the loop, overshadowing their "global" versions!
About the difference between primitive type
float
& object type Float, take a read here:http://docs.oracle.com/javase/tutorial/java/data/numberclasses.html
this
instead of this
A simple example using getFloatRow();
Thanks for all your help and time guys.
Okeydoke, I've been working on getting the hack to be finished and now I want to spend time making the code side look beautfiul (and be a hell of a lot easier to edit than 1000 lines of code!!!)
Currently I am getting a nullpointerexception at line 45:
diameter = map(t[i], 1000, 100000, 10, 100);)
and I'm not sure why... when I comment this out i then get one at 47 and then also at 48... is it that the arrays are wrong?Hello,
in lines 27 to 31 do not repeat the type pls
when you repeat the type here (the 1st word) processing makes it a new local var and defines that one - your global vars in lines 1 to 5 stay undefined. Bad. Thus all crashes in draw().
Once you remove the types in lines 27 to 31, those lines will really define the global vars and draw() should work just fine.
but the code looks nice and short now, congrats, good job!
;-)
Ok, Hurrah!
Really enjoying how it looks and is working.
still a bit elongated, but working well. I'd love to be able to put this onto webpage to show, but at the moment it is just displaying as a grey screen when exported as javascript, (wellgroomedwebsites.businesscatalyst.com/web-export) does anyone know why this might be? Also, does anyone have any advice on easing between ellipse sizes inside a piece of code like this (adding easing between mouse clicks).