From b2c4efa974c3575e310339a72a5f10ad4e1aeba5 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 2 Jan 2016 19:48:51 +0100 Subject: AutoVisual/IGPFamily.pde: Fixing NullPointerException in setStrokeColor() and setFillColor(). Adding useStrokeColor() and useFillColor() to all drawing operations. Colorization now has to be set prior to drawing the element by calling setStrokeColor() and/or setFillColor() with a Float[] containing RGBA values. --- AutoVisual/IGPFamily.pde | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/AutoVisual/IGPFamily.pde b/AutoVisual/IGPFamily.pde index ff8d480..4434a79 100644 --- a/AutoVisual/IGPFamily.pde +++ b/AutoVisual/IGPFamily.pde @@ -14,6 +14,7 @@ class IGPFamily { IGPFamily(float x, float y, float d){ ellipseMode(CENTER); + rectMode(CENTER); colorMode(RGB, 1.0, 1.0, 1.0, 1.0); mid = new PVector(x, y); diameter = d; @@ -67,14 +68,14 @@ class IGPFamily { } void useStrokeColor(){ - if(strokeColor.length!=4 || strokeColor == null){ + if(this.strokeColor == null || this.strokeColor.length!=4){ strokeColor = defaultStrokeColor; } stroke(strokeColor[0], strokeColor[1], strokeColor[2], strokeColor[3]); } void useFillColor(){ - if(fillColor.length!=4 || fillColor == null){ + if(fillColor == null || fillColor.length!=4){ fillColor = defaultFillColor; } fill(fillColor[0], fillColor[1], fillColor[2], fillColor[3]); @@ -90,24 +91,20 @@ class IGPFamily { } void createSquare(PVector mid, float diameter){ + useStrokeColor(); + useFillColor(); rect(mid.x, mid.y, diameter, diameter); } void createOuterSquare() { - stroke(0.0, 0.0, 0.66, 0.4); - rectMode(CENTER); createSquare(mid, diameter); } void createInnerSquare() { - stroke(0.66, 0.66, 0.66, 0.4); - rectMode(CENTER); createSquare(mid, sqrt(sq(diameter)/2)); } void createInnerSquareTilted(float angle){ - rectMode(CENTER); - stroke(0.66, 0.66, 0.66, 0.4); translate(mid.x, mid.y); pushMatrix(); rotate(radians(angle)); @@ -117,22 +114,24 @@ class IGPFamily { } void createCircle(PVector v, float diameter) { + useStrokeColor(); + useFillColor(); ellipse(v.x, v.y, diameter, diameter); } void createAlphaCircle() { - stroke(1.0, 0.0, 0.0, 1.0); createCircle(mid, diameter); } void createConstructionCircles(){ - stroke(0.66, 0.66, 0.66, 0.4); for (PVector constructionCircle : constructionCircleCenters) { createCircle(constructionCircle, diameter); } } void createLine(PVector from, PVector to){ + useStrokeColor(); + useFillColor(); beginShape(LINES); vertex(from.x, from.y); vertex(to.x, to.y); @@ -140,7 +139,6 @@ class IGPFamily { } void createVerticalHorizontalConstructionLines(){ - //TODO: add for 16 parts createLine(alphaCircleVectors.get(0), alphaCircleVectors.get(6)); createLine(alphaCircleVectors.get(3), alphaCircleVectors.get(9)); } @@ -156,7 +154,8 @@ class IGPFamily { } void createInnerHexagon(){ - stroke(0.0, 0.0, 0.66, 0.4); + useStrokeColor(); + useFillColor(); beginShape(LINES); vertex(alphaCircleVectors.get(1).x, alphaCircleVectors.get(1).y); vertex(alphaCircleVectors.get(3).x, alphaCircleVectors.get(3).y); @@ -174,7 +173,8 @@ class IGPFamily { } void createInnerHexagonTilted(float angle){ - stroke(0.0, 0.0, 0.66, 0.4); + useStrokeColor(); + useFillColor(); translate(mid.x, mid.y); pushMatrix(); rotate(radians(angle)); @@ -197,12 +197,14 @@ class IGPFamily { } void createInnerTriangle(){ - stroke(0.0, 0.0, 0.66, 0.4); + useStrokeColor(); + useFillColor(); triangle(alphaCircleVectors.get(1).x, alphaCircleVectors.get(1).y, alphaCircleVectors.get(5).x, alphaCircleVectors.get(5).y, alphaCircleVectors.get(9).x, alphaCircleVectors.get(9).y); } void createInnerTriangleTilted(float angle){ - stroke(0.0, 0.0, 0.66, 0.4); + useStrokeColor(); + useFillColor(); translate(mid.x, mid.y); pushMatrix(); rotate(radians(angle)); @@ -253,7 +255,6 @@ class IGPFamily { } void displayConstructionLines() { - stroke(0.66, 0.66, 0.66, 0.4); createConstructionCircles(); createVerticalHorizontalConstructionLines(); } -- cgit v1.2.3-70-g09d2