polygon slices to 3d sculpture.
in
Programming Questions
•
3 months ago
Dear all interested readers,
I've been working on a sketch to visualise the air temperatures in the Netherlands of the last 106 years.
What I'm trying to do is find a way to take all the years as slices for a 3d sculpture.
Here's a rough sketch of the idea:
I'm using this data:
http://witregel.nl/NL.csv
This is the sketch I'm using to visualise the temperatures for every year:
I've been working on a sketch to visualise the air temperatures in the Netherlands of the last 106 years.
What I'm trying to do is find a way to take all the years as slices for a 3d sculpture.
Here's a rough sketch of the idea:
I'm using this data:
http://witregel.nl/NL.csv
This is the sketch I'm using to visualise the temperatures for every year:
- float tw;
- String[] data_in;
- float[][] temps;
- float[] gemiddelden;
- float[] year_gemiddelden;
- float timeseries_average;
- int aantaljaren = 10;
- float tempscale = 300.0;
- float yearscale = 20.0;
- float yearGraphY = 560;
- int selYear = 0;
- int firstYear;
- PFont font;
- String[] monthnames = {
- "jan", "feb", "mar", "apr", "mei", "jun", "jul", "aug", "sept", "okt", "nov", "dec"
- };
- void setup() {
- size(800, 650);
- data_in = loadStrings("NL.csv");//"CBR1939_2009.csv");
- aantaljaren = data_in.length;
- temps = new float[aantaljaren][12];
- gemiddelden = new float[12];
- year_gemiddelden = new float[aantaljaren];
- parseData();
- font = createFont("Arial", 36);
- smooth();
- }
- void draw() {
- background(0);
- textFont(font, 14);
- fill(255, 255);
- textAlign(CENTER);
- float yearX = 50+((700.0*selYear)/aantaljaren);
- String jaartal = ""+firstYear;
- noStroke();
- tw = textWidth(jaartal);
- fill(0, 0, 250);
- rect(yearX-17, height-20, tw+4, 19);
- fill(255);
- text(selYear+firstYear, yearX, height-6);
- text(nf(year_gemiddelden[selYear], 1, 1)+"°", yearX, yearGraphY-50);
- stroke(255, 100);
- line(yearX, yearGraphY-40, yearX, yearGraphY+50);
- drawYears(yearGraphY);
- translate(400, 250);
- stroke(200);
- fill(100);
- monthLabels();
- noFill();
- for (int y=0; y<aantaljaren; y++) {
- stroke(255, 10);
- // drawMonths(temps[y]);
- }
- strokeWeight(2);
- stroke(0, 0, 255);
- // drawMonths(gemiddelden);
- // temp_puur(temps[selYear]);
- strokeWeight(1);
- stroke(255, 255);
- drawMonths(temps[selYear]);
- }
- void drawMonths(float[] months) {
- beginShape();
- for (int m=0; m<12; m++) {
- float theta = (TWO_PI/12.0)*m - HALF_PI;
- float temp = (months[m]*tempscale);
- // voor gemiddelden
- float diff = 150 + (mouseX/30*(months[m] - gemiddelden[m]));
- // voor werkelijke stand, zonder gemiddeldenberekeking
- // float diff = 150 + (mouseX/30*(months[m] ));
- vertex(cos(theta)*diff, sin(theta)*diff);
- }
- endShape(CLOSE);
- }
- void monthLabels() {
- textFont(font, 12);
- beginShape();
- for (int m=0; m<12; m++) {
- float theta = (TWO_PI/12.0)*m - HALF_PI;
- text(monthnames[m], cos(theta)*200, sin(theta)*200);
- noFill();
- strokeWeight(1);
- stroke(255, 0, 0, 255);
- //vertex(cos(theta)*150, sin(theta)*150);
- }
- endShape(CLOSE);
- }
- void drawYears(float ybase) {
- stroke(255);
- noFill();
- beginShape();
- for (int y=0; y<aantaljaren; y++) {
- vertex(50+(y*(700.0/aantaljaren)), ybase-((year_gemiddelden[y]-timeseries_average)*yearscale));
- }
- endShape();
- stroke(255, 0, 0, 100);
- line(50, ybase, 750, ybase);
- }
- void parseData() {
- println(data_in.length);
- for (int i=0; i<data_in.length; i++) {
- String[] row = split(data_in[i], ',');
- if (i == 0) firstYear = int(row[0]);
- float[] flrow = float(row);
- float[] trimrow = subset(flrow, 1);
- temps[i] = trimrow;
- for (int j=0; j<12; j++) {
- if (i>(1907-firstYear) && i<(2013-firstYear)) gemiddelden[j] += temps[i][j]; // make the average 1961-1990
- }
- year_gemiddelden[i] = aveArray(temps[i]);
- }
- for (int j=0; j<12; j++) {
- gemiddelden[j] = gemiddelden[j]/data_in.length;//(data_in.length-1);
- }
- // float[] twentyyear = subset(year_gemiddelden,1961-firstYear,1990-firstYear);
- timeseries_average = aveArray(gemiddelden);//year_gemiddelden);
- }
- void keyPressed() {
- if (keyCode == RIGHT) {
- selYear = min (aantaljaren-1, selYear+1);
- }
- else if (keyCode == LEFT) {
- selYear = max (0, selYear-1);
- }
- }
- float aveArray(float[] A) {
- float ave = 0;
- for (int i=0; i<A.length; i++) {
- ave += A[i];
- }
- ave = ave/A.length;
- return ave;
- }
On line 93, the part for the drawing of the polygons start. I know that I can, in P3D mode, can add an extra coordinate to make it 3d:
But I don't know where to start. Because after drawing one year/slice, the next one needs to be drawn as well as the walls of the shape. Can someone help me by showing an example?
Thanks in advance.
- 2d: vertex(cos(theta)*diff, sin(theta)*diff);
- 3d: vertex(cos(theta)*diff, sin(theta)*diff, 100);
But I don't know where to start. Because after drawing one year/slice, the next one needs to be drawn as well as the walls of the shape. Can someone help me by showing an example?
Thanks in advance.
1