mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-26 01:44:03 +02:00
datasets for sketches
This commit is contained in:
@@ -38,10 +38,17 @@ class BaseAPI {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
constructor(uid, width = 200, height = 200, canvasBuildFunction) {
|
||||
constructor(
|
||||
uid,
|
||||
width = 200,
|
||||
height = 200,
|
||||
canvasBuildFunction, // Only used during image generation, not used in the browser
|
||||
customDataSet // " "
|
||||
) {
|
||||
if (uid) {
|
||||
this.element = window[uid];
|
||||
delete window[uid];
|
||||
this.dataset = this.element.dataset;
|
||||
}
|
||||
if (canvasBuildFunction) {
|
||||
const { canvas, ctx } = canvasBuildFunction(width, height);
|
||||
@@ -51,6 +58,13 @@ class BaseAPI {
|
||||
} else {
|
||||
this.canvas = document.createElement(`canvas`);
|
||||
}
|
||||
if (!this.dataset) {
|
||||
if (customDataSet) {
|
||||
this.dataset = customDataSet;
|
||||
} else {
|
||||
this.dataset = {};
|
||||
}
|
||||
}
|
||||
this.HATCHING = hatch(canvasBuildFunction);
|
||||
this.addListeners();
|
||||
this.setSize(width, height);
|
||||
|
@@ -138,6 +138,19 @@ class GraphicsAPI extends BaseAPI {
|
||||
points.forEach((p) => this.movable.push(p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a parameter specified via data-attribute
|
||||
*/
|
||||
getParameter(name, fallback) {
|
||||
let val = this.dataset[name];
|
||||
if (val) {
|
||||
let asFloat = parseFloat(val);
|
||||
if (val == asFloat) return asFloat;
|
||||
return val;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up a slider to control a named, numerical property in the sketch.
|
||||
*
|
||||
|
@@ -1,3 +1,24 @@
|
||||
// TODO: FIXME: finish writing out this functionality
|
||||
|
||||
/**
|
||||
|
||||
Scope 0:
|
||||
|
||||
check for variable declaration/assignment, as well as function
|
||||
declarations _without_ the `function` keyword
|
||||
|
||||
Scope 1+:
|
||||
|
||||
check any not-namespaced function calls to see whether they map
|
||||
to any API functions. If they do, they should be prefixed with
|
||||
`this.`
|
||||
|
||||
check any not-namespaced var references to see whether they map
|
||||
to any predefined API vars. If they do, they should be prefixed
|
||||
with `this.`
|
||||
|
||||
**/
|
||||
|
||||
function splitSymbols(v) {
|
||||
if (v.match(/\w/)) return v;
|
||||
return v.split(``);
|
||||
@@ -20,12 +41,12 @@ class Lexer {
|
||||
this.parseVariable(token);
|
||||
}
|
||||
|
||||
// ...
|
||||
// skip over strings so we don't treat them as active content
|
||||
else if ([`'`, `"`, "`"].includes(token)) {
|
||||
this.parseString(token);
|
||||
}
|
||||
|
||||
// ...
|
||||
// figure out if
|
||||
else if (token === `(`) {
|
||||
let functor,
|
||||
i = 2;
|
||||
|
Reference in New Issue
Block a user