Coder Social home page Coder Social logo

Comments (3)

acamposuribe avatar acamposuribe commented on May 23, 2024

Hey @jcquinlan

I don't know if I'm understanding your message correctly, but I think you might be able to do just what you need with the Position class: https://github.com/acamposuribe/p5.brush?tab=readme-ov-file#exposed-classes

The Position class lets you create a new coordinates object with new brush.Position(x,y), which you can then move through the flowfield, whatever distance you want. This is equivalent to how flowlines are drawn. The only thing is that the movement of Position objects goes in steps, and by default this step coincides with the currently active brush. Before folowing lines, you might want to make sure that the same brush is still active.

You can use the brush.Position class like this:

// Let's set the HB 
brush.set("HB", "black", 1)

// Let's draw a "horizontal" 0 degrees flowline starting at (10,30), of 100px length
brush.flowLine(10, 30, 100, 0)

// Let's say we want to find the coordinates in these path, every 10px
let coordinates = []

// We create a Position object in the starting coordinates
let pos = new brush.Position(10,30)

// We move 10px through the 0 degrees path
// It's important to notice that this movement is cumulative, that is,
// once the position has been moved, its coordinates are updated
for (let i = 0; i < 10; i++) {
   pos.moveTo(10, 0)
   coordinates.push([pos.x, pos.y])
}

// These are the 10 points through the flow path
console.log(coordinates)

I hope this helps!
(I'm pushing a small change to the code in order to make this work better, since I just found a small problem)

from p5.brush.

acamposuribe avatar acamposuribe commented on May 23, 2024

In any case, if what you want to do is draw a series of segments with different sizes and different directions, it's probably much easier to use the Plot class, that lets you create just that!
To be honest, the documentation for the three exposed classes is very minimal, but these are basically the core of the whole library. If you learn to use them, you can do almost everything

from p5.brush.

jcquinlan avatar jcquinlan commented on May 23, 2024

Circling back on this to say A.) thanks for pointing me in the right direction, as the Position class indeed allowed me to do what I was thinking originally, and B.) apologize for not having more thoroughly explored the docs before creating an issue!

I'll close the issue now, thanks for all your hard work!

from p5.brush.

Related Issues (15)

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.