Skip to content

Instantly share code, notes, and snippets.

View dipamsen's full-sized avatar
🙂
Active

Dipam Sen dipamsen

🙂
Active
  • India
  • 11:21 (UTC +05:30)
View GitHub Profile
@dipamsen
dipamsen / p5.interactivity.js
Created January 1, 2023 06:32
p5 Interactivity lib for zooming and navigating an infinite canvas
p5.prototype._initVals = function () {
this.int_zoom = 1;
this.int_offset = this.createVector(0, 0);
this.mouseWheel = mouseWheel1.bind(this)
this.mouseDragged = mouseDragged1.bind(this)
};
p5.prototype.registerMethod('init', p5.prototype._initVals)
// MouseDrag - movable canvas
// p5.js
// function draw()
// translate(offset)
// ..
// }
function mouseDragged(event) {
offset.add(event.movementX * 0.9, event.movementY * 0.9)
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const glob = promisify(require('glob'));
/**
* Searches for `index.json` files in a given directory and returns an array of parsed files.
* @param {string} dir Name of directory to search for files
* @param {?any[]} arrayOfFiles Array to store the parsed JSON files
* @returns {any[]}
@dipamsen
dipamsen / documentation.md
Created October 26, 2022 09:47
Reference for the p5.js Web Editor API

p5.js Web Editor API

Some Important Points:

  • Only the success responses are mentioned below. For each of the following, in case of an error, an error message will be present in the response, in the format
    {

"message": "error message"

@dipamsen
dipamsen / README.md
Last active October 26, 2022 09:14
Coding Train Description Generator
@dipamsen
dipamsen / README.md
Last active February 15, 2021 13:45
This is a simple program that generates a random walk visualization for laser etching on train whistles. Ported from CodingTrain/Random-Whistle

How to test directly:

  1. download these files
  2. npm install p5 canvas jsdom
  3. node sketch.js <any-random-seed-here>
  4. randomwalk will be saved as walk.png
const w = 400, h = 400
setupWindow(w, h)
const p5 = require("p5")
new p5(p => {
// Declare sketch variables here
p.setup = () => {
p.createCanvas(w, h)
// setup function
const w = 400, h = 400
setupWindow(w, h)
// import required even though the variable "p5" will not be used anywhere
const p5 = require("p5")
// Declare sketch variables here
function setup() {
createCanvas(w, h);

Using p5.js in Node - all "window" variables used by p5

These are the mandatory window properties accessed by p5.js on import, and what can be used instead:

window.requestAnimationFrame

By default, there is no requestAnimationFrame in node. p5 has a polyfill for requestAnimationFrame for older browsers, so we don't need to implement anything.

window.setTimeout = global.setTimeout