I want the fill color of a grid of ellipses based on the elevation data parsed from a GPX file. However the resulting fill is all one color.
- import processing.opengl.*;
- import tomc.gpx.*;
- import processing.pdf.*;
- import processing.dxf.*;
- GPX gpx;
- PGraphicsPDF pdf;
- boolean pdfrecord;
- boolean record;
- float xR;
- float tileCountX;
- float tileCountY;
- float stepX = 0;
- float stepY = 0;
- void setup(){
- size(1400, 600, OPENGL);
- ellipseMode(CORNER);
- rectMode(CORNER);
- gpx = new GPX(this);
- // parse test.gpx from the sketch data folder
- gpx.parse("MasterTest02.gpx"); // or a URL
- //background(255);
- pdf = (PGraphicsPDF) createGraphics((width), (height), PDF, "line.pdf");
- smooth();
- }
- void draw(){
- background(255);
- float maxEle = 0;
- float minEle = 99999;
- for (int i = 0; i < gpx.getTrackCount(); i++) {
- GPXTrack trk = gpx.getTrack(i);
- // do something with trk.name
- for (int j = 0; j < trk.size(); j++) {
- GPXTrackSeg trkseg = trk.getTrackSeg(j);
- //println(trkseg);
- for (int k = 0; k < trkseg.size(); k++) {
- GPXPoint pt = trkseg.getPoint(k);
- tileCountX = 150;
- tileCountY = 100;
- stepX = width/tileCountX;
- stepY = height/tileCountY;
- float x = (float)pt.lon;
- float y = (float)pt.lat;
- xR = map((int)pt.ele, 0, 1200, 0, 255);
- noLoop();
- //Elevation array
- int[] eleArray = new int[k];
- for(int e = 0; e < eleArray.length; e++){
- eleArray[e] = (int)pt.ele;
- if(eleArray[i]>maxEle)
- {
- maxEle = max(eleArray);
- minEle = min(eleArray);
- //println(eleArray[e]);
- }
- }
- }
- }
- }
- for (int gridY = 0; gridY < height; gridY += stepY){
- for (int gridX = 0; gridX < width; gridX += stepX){
- fill(xR);
- // if(gridX == 27){
- // fill(0);}
- // if(gridY == 468){
- // fill(0);
- // }
- ellipse(gridX, gridY, 10, 10);
- }
- }
- }
- //PDF RECORD
- //void keyPressed() {
- // if (key == 'r') {
- // if (pdfrecord) {
- // endRecord();
- // println("Recording stopped.");
- // pdfrecord = false;
- // } else {
- // beginRecord(pdf);
- // println("Recording started.");
- // pdfrecord = true;
- // }
- // } else if (key == 'q') {
- // if (pdfrecord) {
- // endRecord();
- // }
- // exit();
- // }
- //}
- //dxf
- void keyPressed() {
- if (key == 'r') {
- if (record) {
- endRaw();
- println("Recording stopped.");
- record = false;
- } else {
- beginRaw(DXF, "output.dxf");
- println("Recording started.");
- record = true;
- }
- } else if (key == 'q') {
- if (record) {
- endRaw();
- }
- exit();
- }
- }
1