class Segment { float x1, y1, x2, y2; float normX, normY; float centerX, centerY; Note note; Segment(float x1, float y1, float x2, float y2) { setPoints(x1, y1, x2, y2); note = new Note(40 + int(random(80)), 127, 200); } void setPoints(float x1, float y1, float x2, float y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; calculateNormal(); } void calculateNormal() { normX = y2 - y1; normY = -(x2 - x1); float maxi = sqrt(sq(normX) + sq(normY)); normX = norm(normX, 0, maxi); normY = norm(normY, 0, maxi); centerX = x1 + (x2-x1)/2; centerY = y1 + (y2-y1)/2; } void display() { stroke(0); line(x1, y1, x2, y2); if (DEBUG) { stroke(200); line(centerX, centerY, centerX + normX*20, centerY + normY*20); } } }