Created
March 1, 2016 13:43
-
-
Save SageStarCodes/47a1dab8ca5f1fbb7615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.d3add3d.d3processingutils; | |
import processing.core.PApplet; | |
public class TwoDimensionalLineGraph { | |
private PApplet parent; | |
private float[] values; | |
private int spcx, spcy, startx, starty; | |
private boolean drawGrid; | |
/** | |
* | |
* @param p | |
* @param arr | |
* @param spacingx | |
* @param spacingy | |
* @param xstart | |
* @param ystart | |
* @param grid | |
*/ | |
public TwoDimensionalLineGraph(PApplet p, float[] arr, int spacingx, int spacingy, int xstart, int ystart, boolean grid) { | |
this.parent = p; | |
this.values = arr; | |
this.spcx = spacingx; | |
this.spcy = spacingy; | |
this.startx = xstart; | |
this.starty = ystart; | |
this.drawGrid = grid; | |
} | |
public void drawGraph() { | |
//draw grid | |
if (drawGrid) { | |
parent.stroke(255,50.0f); | |
parent.strokeWeight(0.0f); | |
for (int i=1; i < 101; i++) { | |
parent.line(startx, starty+(spcy*i), this.values.length*spcx, starty+(spcy*i)); | |
} | |
for (int i=1; i < this.values.length; i++) { | |
parent.line(startx+(spcx*i), starty, startx+(spcx*i), starty+(spcy*this.values.length)); | |
} | |
} | |
//draw values | |
parent.stroke(255,255.0f); | |
parent.strokeWeight(2.0f); | |
for (int j=0; j < this.values.length-1; j++) { | |
parent.line(startx+(spcx*j), starty+(this.values[j]*10*spcy), startx+(spcx*(j+1)), starty+(this.values[j+1]*10*spcy)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment