Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/math/noise.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ function noise(p5, fn){
* three dimensions. These dimensions can be thought of as space, as in
* `noise(x, y, z)`, or space and time, as in `noise(x, y, t)`.
*
* @method noise
* @param {Number} x x-coordinate in noise space.
* @param {Number} [y] y-coordinate in noise space.
* @param {Number} [z] z-coordinate in noise space.
* @return {Number} Perlin noise value at specified coordinates.
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -89,8 +83,9 @@ function noise(p5, fn){
* strokeWeight(5);
* point(x, y);
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -115,8 +110,9 @@ function noise(p5, fn){
* strokeWeight(5);
* point(x, y);
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -138,8 +134,9 @@ function noise(p5, fn){
* // Draw the line.
* line(x, 0, x, y);
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -166,8 +163,9 @@ function noise(p5, fn){
* line(x, 0, x, y);
* }
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand Down Expand Up @@ -196,8 +194,9 @@ function noise(p5, fn){
*
* describe('A gray cloudy pattern.');
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand Down Expand Up @@ -227,10 +226,11 @@ function noise(p5, fn){
* }
* }
* }
* ```
*
* `noise()` can also be used in shaders with p5.strands, where it returns
* values in the range 0 to 1. The following example uses `noise()` to create
* a cloud-like texture effect in a filter shader.
* values in the range 0 to 1. The example below uses `noise()` inside a
* filter shader to create a cloud-like texture effect:
*
* ```js example
* let myFilter;
Expand All @@ -257,6 +257,12 @@ function noise(p5, fn){
* filter(myFilter);
* }
* ```
*
* @method noise
* @param {Number} x x-coordinate in noise space.
* @param {Number} [y] y-coordinate in noise space.
* @param {Number} [z] z-coordinate in noise space.
* @return {Number} Perlin noise value at specified coordinates.
*/
fn.noise = function(x, y = 0, z = 0) {
if (perlin == null) {
Expand Down Expand Up @@ -501,4 +507,4 @@ export default noise;

if(typeof p5 !== 'undefined'){
noise(p5, p5.prototype);
}
}
28 changes: 17 additions & 11 deletions src/math/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ function random(p5, fn){
* For example, calling `random(-5, 10.2)` returns values from -5 up to but
* not including 10.2.
*
* @method random
* @param {Number} [min] lower bound (inclusive).
* @param {Number} [max] upper bound (exclusive).
* @return {Number} random number.
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -126,8 +121,9 @@ function random(p5, fn){
*
* describe('A black dot appears in a random position on a gray square.');
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -143,8 +139,9 @@ function random(p5, fn){
*
* describe('A black dot appears in a random position on a gray square.');
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -165,8 +162,9 @@ function random(p5, fn){
*
* describe('An animal face is displayed at random. Either a lion, tiger, or bear.');
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -187,8 +185,9 @@ function random(p5, fn){
* strokeWeight(5);
* point(x, y);
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -209,8 +208,9 @@ function random(p5, fn){
* strokeWeight(5);
* point(x, y);
* }
* ```
*
* @example
* ```js example
* let x = 50;
* let y = 50;
*
Expand All @@ -230,6 +230,7 @@ function random(p5, fn){
* // Draw the point.
* point(x, y);
* }
* ```
*
* `random()` can also be used in shaders with p5.strands. The following example
* uses `random()` to create varying colors on a shape.
Expand Down Expand Up @@ -259,6 +260,11 @@ function random(p5, fn){
* sphere(30);
* }
* ```
*
* @method random
* @param {Number} [min] lower bound (inclusive).
* @param {Number} [max] upper bound (exclusive).
* @return {Number} random number.
*/
/**
* @method random
Expand Down
17 changes: 11 additions & 6 deletions src/utilities/time_date.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ function timeDate(p5, fn){
* sketch includes asynchronous loading using `async`/`await`, then
* `millis()` begins tracking time as soon as the asynchronous code
* starts running.
* @method millis
* @return {Number} number of milliseconds since starting the sketch.
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -132,8 +130,9 @@ function timeDate(p5, fn){
* `The text 'Startup time: ${round(ms, 2)} ms' written in black on a gray background.`
* );
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -154,8 +153,9 @@ function timeDate(p5, fn){
* // Display how long the sketch has run.
* text(`Running time: ${nf(s, 1, 1)} sec`, 5, 50, 90);
* }
* ```
*
* @example
* ```js example
* function setup() {
* createCanvas(100, 100);
*
Expand All @@ -174,8 +174,9 @@ function timeDate(p5, fn){
* // Draw the circle.
* circle(x, 50, 30);
* }
* ```
*
* @example
* ```js example
* async function setup() {
* // Load the GeoJSON.
* await loadJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson');
Expand All @@ -198,6 +199,7 @@ function timeDate(p5, fn){
* `The text "It took ${round(ms, 2)} ms to load the data" written in black on a gray background.`
* );
* }
* ```
*
* `millis()` can also be used in shaders with p5.strands. The following example
* uses `millis()` to create time-based color transitions on a shape.
Expand Down Expand Up @@ -228,6 +230,9 @@ function timeDate(p5, fn){
* sphere(30);
* }
* ```
*
* @method millis
* @return {Number} number of milliseconds since starting the sketch.
*/
fn.millis = function() {
if (this._millisStart === -1) {
Expand Down
Loading