diff --git a/src/core/attributes.js b/src/core/attributes.js index f1ff70773b..dde369676b 100644 --- a/src/core/attributes.js +++ b/src/core/attributes.js @@ -310,6 +310,70 @@ p5.prototype.strokeJoin = function(join) { return this; }; +/** + * Sets the line dash pattern used when drawing lines, + * using an array of values which specify alternating lengths of lines and gaps + * which describe the pattern. + * If the argument is omitted, the function just returns the current line dash setting. + * + * @method lineDash + * @param {Number[]} [segments] An array of numbers which specify distances to alternately draw a line and a gap. + * If the number of elements in the array is odd, the elements of the array get copied and concatenated. + * For example, (5, 15, 25) will become (5, 15, 25, 5, 15, 25). + * If the array is empty, the line dash list is cleared and line strokes return to being solid. + * @return {Number[]} The current line dash setting. + * @example + *
+ * strokeWeight(2);
+ *
+ * // A simple pattern:
+ * // Stroke 5 pixels and leave 5 pixels of spacing
+ * lineDash([5]);
+ *
+ * line(10, 10, 10, 90);
+ *
+ * fill(255, 0, 0);
+ * rect(30, 20, 60, 60);
+ *
+ *
+ * strokeWeight(2);
+ * stroke(255, 0, 0);
+ *
+ * // A more complex pattern:
+ * // Stroke 10 pixels, leave 5 pixels of spacing, stroke 2 pixels, leave 5 pixels of spacing and repeat
+ * lineDash([10, 5, 2, 5]);
+ *
+ * ellipse(width / 2, height / 2, 80);
+ *
+ *
+ * stroke(255, 255, 0);
+ *
+ * lineDash([10]);
+ * line(10, height / 3, 90, height / 3);
+ *
+ * // Go back to solid lines
+ * lineDash([]);
+ * line(10, 2 / 3 * height, 90, 2 / 3 * height);
+ *
+ *