janpaul123 / paperprograms

Run Javascript on pieces of paper!
https://paperprograms.org
MIT License
484 stars 55 forks source link

Multiple whiskers #62

Closed paulsonnentag closed 6 years ago

paulsonnentag commented 6 years ago

Summary API Changes

as discussed in original issue: #49

Creation / Removal of whiskers

Currently, the API is missing a way to remove whiskers again. I would like to add a whisker only if the paper has something connected to the output. The program can change audio nodes dynamically so it should be possible to remove whiskers again if there is no longer anything connected to the sound output.

var whisker = await paper.get('whisker', {
  direction,      // "up" (default), "down", "left", "right"
  whiskerLength,  // as fraction of the side (default 0.7)
  requiredData,   // array of data fields that must be present in the other paper
  paperNumber,    // paper number to do this for (default is own paper number)
});

// destroy
whisker.destroy();

Different whisker color

If a paper has multiple whiskers it would be nice if you could change the color of the whisker to differentiate them better. Instead of a color change the "connected" state is indicated by the moving dot animation. If the paper is not connected a static line is rendered without the moving dot.

var whisker = await paper.get('whisker', {
  direction: "up",
  color: "blue", // new color attribute (default: red)
  requiredData: [ "frequency" ]
});

Separate event handlers for placement and removal of papers

I think it would be cleaner to have two separate events for when a paper is placed and when it's removed. This makes it easier to explain the API. It's not necessary to check for null and in the removed paper event handler we can also pass in the information about the paper which was removed.

whisker.on("paperAdded" ({paperNumber, paperObj}) => { /* do something */ })
whisker.on("paperRemoved", ({paperNumber, paperObj}) => { /* do something */})
janpaul123 commented 6 years ago

Let me know when you're happy with the PR, then I'll merge it. 👍

paulsonnentag commented 6 years ago

Ready to merge

janpaul123 commented 6 years ago

Sorry for the late response 😞; and now it looks like there's a merge conflict. Let me know when it's resolved and I'll merge!

paulsonnentag commented 6 years ago

I've resolved the merge conflicts now