| versions | 0135+ |
|---|---|
| contributors | mflux |
| started on | 2009-09-25 16:58 |
Ever notice how strokeweight stops working after you give it a certain size? It's like lines refuse to become obese!
With this method you can draw as wide a line as you please. It will hijack Processing's stroke weight and draw a line with an actual rectangle.
This method could be further improved by using circles for stroke caps and such. The rest is up to your imagination.
Note: you can probably shorten this code using processing's new pushStyle() / popStyle(). This was done the oldschool way.
/** fatline taken from http://processinghacks.com/hacks:fatline @author mflux */ // the goods void fatLine(float x1, float y1, float x2, float y2){ float distance = dist(x1, y1, x2, y2); float angle = 360-atan2((y2-y1),x2-x1) ; boolean originalStroke = g.stroke; int originalStrokeColor = g.strokeColor; float originalStrokeWeight = g.strokeWeight; boolean originalFill = g.fill; int originalFillColor = g.fillColor; float thickness = originalStrokeWeight; stroke(originalStrokeColor); strokeWeight(1); fill(originalStrokeColor); pushMatrix(); translate(x1,y1); rotate(360 - angle); rect(0, - (thickness / 2 ), distance, thickness); popMatrix(); g.stroke = originalStroke; g.strokeColor = originalStrokeColor; g.strokeWeight = originalStrokeWeight; g.fill = originalFill; g.fillColor = originalFillColor; } // the example void setup(){ size(800,800); } void draw(){ background(255); stroke(0xFF70E320); strokeWeight(100); fatLine(width-mouseX,height-mouseY, mouseX, mouseY); }