Code Monkey home page Code Monkey logo

p5.range's Introduction

p5.range

An add-on for p5.js with a range function, offering an alternative way to repeat steps from standard for and while loops.

The function's design aims to simplify syntax and prevent infinite loops. It works similarly to Python's range function.

Installation

p5 Editor Template

You can use this template by signing in to the editor, opening the template, and clicking File > Duplicate.

Script Tag

On an existing p5 sketch, you can add the range add-on by editing the index.html file and adding the following script tag:

<script src="https://cdn.jsdelivr.net/gh/calebfoss/p5.range@latest/p5.range.js"></script>

Example index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/p5.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/addons/p5.sound.min.js"></script>
        <script src="https://cdn.jsdelivr.net/gh/calebfoss/p5.range@latest/p5.range.js"></script>
        <link rel="stylesheet" type="text/css" href="style.css">
        <meta charset="utf-8" />
</head> <body> <main> </main> <script src="sketch.js"></script> </body> </html>

Functions

range(stop)object

Creates an iterator, which is an object that produces a sequence of values. This may be used in a for...of loop.

range(start, stop, [increment])object

range(stop) ⇒ object

Creates an iterator, which is an object that produces a sequence of values. This may be used in a for...of loop.

Kind: global function
Returns: object - Iterator that returns values from 0 to stop with each value 1 apart.

Param Type Description
stop number when the range reaches or goes past this value, it will stop returning values

Example

for(let i of range(100)) {
 circle(random(width), random(height), random(100));
}
describe("100 circles with random sizes and positions.")

range(start, stop, [increment]) ⇒ object

Kind: global function
Returns: object - Iterator that returns values from start to stop with each value increment apart.

Param Type Description
start number initial value
stop number when the range reaches or goes past this value, it will stop returning values
[increment] number change between each value (default is 1 or -1 depending on whether stop is greater than or less than start) (Optional)

Example

for(let x of range(25, width, 50)) {
 circle(x, height / 2, 50);
}
describe("A row of circles spanning the width of " +
"the canvas halfway down the canvas.");

p5.range's People

Contributors

calebfoss avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.