Skip to content

Instantly share code, notes, and snippets.

View dipamsen's full-sized avatar
🙂
Active

Dipam Sen dipamsen

🙂
Active
  • India
  • 06:08 (UTC +05:30)
View GitHub Profile
// Typescript Declaration File for Node Chess module
// https://www.npmjs.com/package/chess
declare namespace Chess {
export function create(opts?: { PGN: boolean }): AlgebraicGameClient
export function createSimple(): SimpleGameClient
interface AlgebraicGameClient {
/** The Game object, which includes the board and move history. */
game: Game

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

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);
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
@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
@dipamsen
dipamsen / README.md
Last active October 26, 2022 09:14
Coding Train Description Generator
@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"

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[]}
// MouseDrag - movable canvas
// p5.js
// function draw()
// translate(offset)
// ..
// }
function mouseDragged(event) {
offset.add(event.movementX * 0.9, event.movementY * 0.9)