1 / 14

Plotting

Plotting. Read/write files in processing Refine a sampled curve Plot curves Exaggerate the discrepancy between two curves Use keys to control view parameters Produce pulsating animation Form teams for Project 1 Investigate how to visualize plot discrepancies. Write to a file.

Download Presentation

Plotting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Plotting • Read/write files in processing • Refine a sampled curve • Plot curves • Exaggerate the discrepancy between two curves • Use keys to control view parameters • Produce pulsating animation • Form teams for Project 1 • Investigate how to visualize plot discrepancies

  2. Write to a file float [] F = {200,240,250,210.1,160,150,170,200,209,240,250,220,200,150,110,100}; // array of values int n=F.length; // number of entries in F String [] SF = new String [n]; // allocate table of strings that will contain strings representing F[0], F[1]...F[n-1] for (int i=0; i<n; i++) SF[i]=str(F[i]); // store string forms of F values in SF saveStrings("F.val",SF); // writes content of SF to a file named F.val created in the sketch folder

  3. Read a file String [] SF = loadStrings("F.val"); // reads array of strings from a file named F.val in the sketch folder int n=SF.length; // sets the number of values in the array float [] F = new float [n]; // table of values that will be extracted from the strings for (int i=0; i<n; i++) F[i] = float(SF[i]); // recovers float values from strings and stores in F for (int i=0; i<n; i++) println(F[i]); // prints read values in the bottom pane of the Processing window // does not work in applets

  4. Interpolate Write the expression for C in terms of A and B d d A C= B d sd A C= B

  5. C(0) C(1) C(-1) M B D C(-3) A C(3) E M’ Insert new sample • Insert a new sample along each edge: M=(B+D)/2 • Displace it (bulge-out). By how much? • Fit a cubit C=C(t) through A, B, D, and E C(t)=at3+bt2+ct+d, and thus C(0)=d Set 4 constraints and solve for d: B=C(–1)= –a+b–c+d D=C( 1)= a+b+c+d A=C(–3)= –27a+9b–3c+d E=C( 3)= 27a+9b M=(B+D)/2=b+d M’–9M=–8d M’=(A+E)/2=9b+d C(0)=d=M+(M–M’)/8 bulge = M’M/8

  6. C(0) C(1) C(-1) M B D C(-3) A C(3) If A is unknown, estimate it as E+3(B–D) E M’ Boundary conditions • The bulge of an edge is computed from 2 neighbors on each side • What if you have only one neighbor on one side? • Add a dummy (missing) sample estimated from neighbors

  7. Refine a sampling String [] SF = loadStrings("F.val"); // reads array from F.val int n=SF.length; // sets the number of values in the array float [] F = new float [n]; // table of values for (int i=0; i<n; i++) F[i]=float(SF[i]); // recover F values from strings int r = 2*n-1; // number of values in refined array float [] R = new float [r]; // refined array for (int i=0; i<n; i++) R[2*i]=F[i]; // copies F values into even entries of R for (int i=3; i<r-3; i=i+2) R[i]=((-R[i-3]+9*R[i-1]+9*R[i+1]-R[i+3])/16); // computes intermediate odd values through cubit interpolation R[1]=(3*R[0]+6*R[2]-R[4])/8; R[r-2]=(3*R[r-1]+6*R[r-3]-R[r-5])/8; // computes first and last odd value using estimated dummy String [] SR = new String [r]; // allocate table of strings for (int i=0; i<r; i++) SR[i]=str(R[i]); // store string forms of R values in SR saveStrings("F.val",SR); // overwrite F.val with refeined values

  8. Exaggerate discrepancy Write the expression for C in terms of A and B d d A B C = d sd A B C =

  9. Exaggerate discrepancy of two plots void exaggerate (float s) { for (int i = 0; i<n; i++) { EF[i]=(s+1.)*F[i]-s*G[i]; EG[i]=(s+1.)*G[i]-s*F[i]; }; } What happens when s=0? What happens when s=1?

  10. Plot: Global variables color red; …. // declare colors but do not assign values yet // because we want to use the HSB color mode int n=1000; // cap on the number of values float [] F = new float [n]; // table F float [] G = new float [n]; // table G float [] EF = new float [n]; // table of exaggerated F float [] EG = new float [n]; // table of exaggerated G float s=1.0; // exaggeration factor boolean showExaggerated=false; // toggle normal/exaggerate mode boolean pulsing=false; // toggle pulsing mode

  11. Plot: setup (initialization code) void setup() { size(500, 400); // open graphic window (size in pixels) smooth(); strokeJoin(ROUND); strokeCap(ROUND); // want nice polylines colorMode(HSB,121); // color mode: Hue, Saturation, Brightness in [0..120] red = color(0, 120, 120); // …saturated, bright red String [] SF = loadStrings("F.val"); // reads array of strings from F.val n=SF.length; // sets the number of values in array for (int i=0; i<n; i++) F[i]=float(SF[i]); // store string forms of F values String [] SG = loadStrings("G.val"); // reads array of strings from G.val for (int i=0; i<n; i++) G[i]=float(SG[i]); // store string forms of G values exaggerate(s); // computes EF and EG exaggerating differences by factor s }

  12. Draw (redisplay loop) void draw() { background(50); // erase window using gray color strokeWeight(2); // set line width to 2 noFill(); // do not fill the interior of shapes if (pulsing) exaggerate(s*(2-cos(millis()/100.))); // if pulsing, exaggerate by a factor in [ 0 , 2s ] // computed using the current time in hundredths of milliseconds if (showExaggerated) {stroke(red); plot(EF); stroke(green); plot(EG);} else {stroke(orange); plot(F); stroke(cyan); plot(G); }; } void plot (float [] F) { // plot through n samples with values in F beginShape(); for (int i = 0; i<n; i++) vertex(i,height-F[i]); endShape(); } // y axis goes down, so we use height-F[i]

  13. User Interface (keyboard) void keyPressed() { // executed when a key is pressed if (key==' ') showExaggerated=!showExaggerated; // toggle normal/exagerated display mode if (key=='/') {pulsing=!pulsing;}; // toggle pulsing if (key=='.') s*=2; if (key==',') s/=2; // double / half the exaggeration factor if (key=='1') s=1; // resets s to 1 (mild exaggeration) exaggerate(s); // re-computes the exaggerated values };

  14. Results s=16 s=1

More Related