diff --git a/src/core/constants.js b/src/core/constants.js index 8900741a4d..241e67066a 100644 --- a/src/core/constants.js +++ b/src/core/constants.js @@ -86,121 +86,546 @@ export const WAIT = 'wait'; // TRIGONOMETRY /** - * HALF_PI is a mathematical constant with the value - * 1.57079632679489661923. It is half the ratio of the - * circumference of a circle to its diameter. It is useful in - * combination with the trigonometric functions sin() and cos(). + * A `Number` constant that's approximately 1.5708. + * + * `HALF_PI` is half the value of the mathematical constant π. It's useful for + * many tasks that involve rotation and oscillation. For example, calling + * `rotate(HALF_PI)` rotates the coordinate system `HALF_PI` radians, which is + * a quarter turn (90˚). + * + * Note: `TWO_PI` radians equals 360˚, `PI` radians equals 180˚, `HALF_PI` + * radians equals 90˚, and `QUARTER_PI` radians equals 45˚. * * @property {Number} HALF_PI * @final * * @example - *
- * arc(50, 50, 80, 80, 0, HALF_PI);
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Draw an arc from 0 to HALF_PI.
+ * arc(50, 50, 80, 80, 0, HALF_PI);
+ *
+ * describe('The bottom-right quarter of a circle drawn in white on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Draw a line.
+ * line(0, 0, 40, 0);
+ *
+ * // Rotate a quarter turn.
+ * rotate(HALF_PI);
+ *
+ * // Draw the same line, rotated.
+ * line(0, 0, 40, 0);
+ *
+ * describe('Two black lines on a gray background. One line extends from the center to the right. The other line extends from the center to the bottom.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A red circle and a blue circle oscillate from left to right on a gray background. The red circle appears to chase the blue circle.'
+ * );
+ * }
*
- * @alt
- * 80×80 white quarter-circle with curve toward bottom right of canvas.
+ * function draw() {
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Calculate the x-coordinates.
+ * let x1 = 40 * sin(frameCount * 0.05);
+ * let x2 = 40 * sin(frameCount * 0.05 + HALF_PI);
+ *
+ * // Style the oscillators.
+ * noStroke();
+ *
+ * // Draw the red oscillator.
+ * fill(255, 0, 0);
+ * circle(x1, 0, 20);
+ *
+ * // Draw the blue oscillator.
+ * fill(0, 0, 255);
+ * circle(x2, 0, 20);
+ * }
+ *
+ *
- * arc(50, 50, 80, 80, 0, PI);
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Draw an arc from 0 to PI.
+ * arc(50, 50, 80, 80, 0, PI);
+ *
+ * describe('The bottom half of a circle drawn in white on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Draw a line.
+ * line(0, 0, 40, 0);
*
- * @alt
- * white half-circle with curve toward bottom of canvas.
+ * // Rotate a half turn.
+ * rotate(PI);
+ *
+ * // Draw the same line, rotated.
+ * line(0, 0, 40, 0);
+ *
+ * describe('A horizontal black line on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A red circle and a blue circle oscillate from left to right on a gray background. The circles drift apart, then meet in the middle, over and over again.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Calculate the x-coordinates.
+ * let x1 = 40 * sin(frameCount * 0.05);
+ * let x2 = 40 * sin(frameCount * 0.05 + PI);
+ *
+ * // Style the oscillators.
+ * noStroke();
+ *
+ * // Draw the red oscillator.
+ * fill(255, 0, 0);
+ * circle(x1, 0, 20);
+ *
+ * // Draw the blue oscillator.
+ * fill(0, 0, 255);
+ * circle(x2, 0, 20);
+ * }
+ *
+ *
- * arc(50, 50, 80, 80, 0, QUARTER_PI);
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Draw an arc from 0 to QUARTER_PI.
+ * arc(50, 50, 80, 80, 0, QUARTER_PI);
+ *
+ * describe('A one-eighth slice of a circle drawn in white on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Draw a line.
+ * line(0, 0, 40, 0);
+ *
+ * // Rotate an eighth turn.
+ * rotate(QUARTER_PI);
+ *
+ * // Draw the same line, rotated.
+ * line(0, 0, 40, 0);
+ *
+ * describe('Two black lines that form a "V" opening towards the bottom-right corner of a gray square.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A red circle and a blue circle oscillate from left to right on a gray background. The red circle appears to chase the blue circle.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Calculate the x-coordinates.
+ * let x1 = 40 * sin(frameCount * 0.05);
+ * let x2 = 40 * sin(frameCount * 0.05 + QUARTER_PI);
+ *
+ * // Style the oscillators.
+ * noStroke();
*
- * @alt
- * white eighth-circle rotated about 40 degrees with curve bottom right canvas.
+ * // Draw the red oscillator.
+ * fill(255, 0, 0);
+ * circle(x1, 0, 20);
+ *
+ * // Draw the blue oscillator.
+ * fill(0, 0, 255);
+ * circle(x2, 0, 20);
+ * }
+ *
+ *
- * arc(50, 50, 80, 80, 0, TAU);
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Draw an arc from 0 to TAU.
+ * arc(50, 50, 80, 80, 0, TAU);
+ *
+ * describe('A white circle drawn on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Draw a line.
+ * line(0, 0, 40, 0);
+ *
+ * // Rotate a full turn.
+ * rotate(TAU);
+ *
+ * // Style the second line.
+ * strokeWeight(5);
+ *
+ * // Draw the same line, shorter and rotated.
+ * line(0, 0, 20, 0);
+ *
+ * describe(
+ * 'Two horizontal black lines on a gray background. A thick line extends from the center toward the right. A thin line extends from the end of the thick line.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A red circle with a blue center oscillates from left to right on a gray background.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Calculate the x-coordinates.
+ * let x1 = 40 * sin(frameCount * 0.05);
+ * let x2 = 40 * sin(frameCount * 0.05 + TAU);
+ *
+ * // Style the oscillators.
+ * noStroke();
+ *
+ * // Draw the red oscillator.
+ * fill(255, 0, 0);
+ * circle(x1, 0, 20);
+ *
+ * // Draw the blue oscillator, smaller.
+ * fill(0, 0, 255);
+ * circle(x2, 0, 10);
+ * }
+ *
+ *
- * arc(50, 50, 80, 80, 0, TWO_PI);
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Draw an arc from 0 to TWO_PI.
+ * arc(50, 50, 80, 80, 0, TWO_PI);
+ *
+ * describe('A white circle drawn on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Draw a line.
+ * line(0, 0, 40, 0);
+ *
+ * // Rotate a full turn.
+ * rotate(TWO_PI);
+ *
+ * // Style the second line.
+ * strokeWeight(5);
+ *
+ * // Draw the same line, shorter and rotated.
+ * line(0, 0, 20, 0);
+ *
+ * describe(
+ * 'Two horizontal black lines on a gray background. A thick line extends from the center toward the right. A thin line extends from the end of the thick line.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A red circle with a blue center oscillates from left to right on a gray background.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
*
- * @alt
- * 80×80 white ellipse shape in center of canvas.
+ * // Calculate the x-coordinates.
+ * let x1 = 40 * sin(frameCount * 0.05);
+ * let x2 = 40 * sin(frameCount * 0.05 + TWO_PI);
+ *
+ * // Style the oscillators.
+ * noStroke();
+ *
+ * // Draw the red oscillator.
+ * fill(255, 0, 0);
+ * circle(x1, 0, 20);
+ *
+ * // Draw the blue oscillator, smaller.
+ * fill(0, 0, 255);
+ * circle(x2, 0, 10);
+ * }
+ *
+ *
+ *
+ *
* function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Draw a red arc from 0 to HALF_PI radians.
+ * fill(255, 0, 0);
+ * arc(50, 50, 80, 80, 0, HALF_PI);
+ *
+ * // Use degrees.
* angleMode(DEGREES);
+ *
+ * // Draw a blue arc from 90˚ to 180˚.
+ * fill(0, 0, 255);
+ * arc(50, 50, 80, 80, 90, 180);
+ *
+ * describe('The bottom half of a circle drawn on a gray background. The bottom-right quarter is red. The bottom-left quarter is blue.');
* }
- *
+ *
+ *
+ *
+ *
* function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use degrees.
+ * angleMode(DEGREES);
+ *
+ * // Draw a red arc from 0˚ to 90˚.
+ * fill(255, 0, 0);
+ * arc(50, 50, 80, 80, 0, 90);
+ *
+ * // Use radians.
* angleMode(RADIANS);
+ *
+ * // Draw a blue arc from HALF_PI to PI.
+ * fill(0, 0, 255);
+ * arc(50, 50, 80, 80, HALF_PI, PI);
+ *
+ * describe('The bottom half of a circle drawn on a gray background. The bottom-right quarter is red. The bottom-left quarter is blue.');
* }
- *
+ *
+ *