+
+
@@ -60,9 +66,21 @@ export default {
viz: this.activeViz
}
this.seqVizPairs.push(bundle);
- this.activeSeq = {};
- this.activeViz = {};
- console.log(this.seqVizPairs);
+ this.clearActive();
+ },
+ drawBundle: function(seqVizBundle){
+ console.log(seqVizBundle)
+ this.activeSeq = seqVizBundle.seq;
+ this.activeViz = seqVizBundle.viz;
+ this.drawingActive = true;
+ },
+ closeCanvas: function() {
+ this.clearActive();
+ this.drawingActive = false;
+ },
+ clearActive: function() {
+ this.activeViz = {};
+ this.activeSeq = {};
}
},
data: function(){
@@ -88,7 +106,8 @@ export default {
sequences: sequences,
seqVizPairs: [],
activeViz: {},
- activeSeq: {}
+ activeSeq: {},
+ drawingActive: false
}
return state
}
diff --git a/src/vizualizers/vizualizerDefault.ts b/src/vizualizers/vizualizerDefault.ts
index 7f3ed843..0c2db464 100644
--- a/src/vizualizers/vizualizerDefault.ts
+++ b/src/vizualizers/vizualizerDefault.ts
@@ -10,7 +10,7 @@ export class VizualizerDefault implements VizualizerInterface{
ready = false;
sketch: p5 = new p5(sketch => {return sketch});
seq: SequenceInterface = new SequenceClassDefault(0, false);
- private isValid = false;
+ public isValid = false;
/***
Sets the sketch and the sequence to draw with
@@ -31,13 +31,20 @@ export class VizualizerDefault implements VizualizerInterface{
This checks that the params provided are within the bounds you need.
Simply assign params to settings (using the provided function) and validate them
Returns a ValidationStatus object (see VizualizerInterface.ts for details)
+
+ The default validation is always false, since it is automatically used by its children
+ so you are required to define a new validate function for every vizualizer.
*/
validate() {
+ this.assignParams();
+ this.isValid = false;
+ return new ValidationStatus(false, ["This is the default validation function. Please define one for this vizualizer"]);
+ }
+
+ assignParams(){
this.params.forEach(param => {
this.settings[param.name] = param.value;
});
- this.isValid = true;
- return new ValidationStatus(true);
}
setup(){
diff --git a/src/vizualizers/vizualizerDifferences.ts b/src/vizualizers/vizualizerDifferences.ts
index 330e62ef..ae3ba075 100644
--- a/src/vizualizers/vizualizerDifferences.ts
+++ b/src/vizualizers/vizualizerDifferences.ts
@@ -1,6 +1,7 @@
import {SequenceInterface} from "@/sequences/sequenceInterface";
import {VizualizerInterface, VizualizerParamsSchema, VizualizerSettings, VizualizerExportModule} from "@/vizualizers/vizualizerInterface";
import { VizualizerDefault } from './vizualizerDefault';
+import { ValidationStatus } from '@/shared/validationStatus';
/*
var list=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223];
@@ -31,6 +32,15 @@ class VizDifferences extends VizualizerDefault implements VizualizerInterface{
this.params.push(numberTermsTop, levelsParam);
}
+ validate() {
+ this.assignParams();
+
+ if(this.settings.number <= this.settings.levels) return new ValidationStatus(false, ["n must be greater than levels"]);
+
+ this.isValid = true;
+ return new ValidationStatus(true);
+ }
+
drawDifferences(n: number, levels: number, sequence: SequenceInterface) {
//changed background color to grey since you can't see what's going on
diff --git a/src/vizualizers/vizualizerInterface.ts b/src/vizualizers/vizualizerInterface.ts
index a0778888..7fd68fd1 100644
--- a/src/vizualizers/vizualizerInterface.ts
+++ b/src/vizualizers/vizualizerInterface.ts
@@ -44,17 +44,13 @@ export interface VizualizerSettings {
}
export interface VizualizerInterface {
+ isValid: boolean;
/**
* The parameters for the vizualizer to initialize.
* In addition to providing the information in the schema,
* these will be used as default params in the event the user does not specify any.
*/
params: VizualizerParamsSchema[];
- /**
- * The applied params. Mostly exists to simplify calling params, since we can
- * assign the param name to the settings key.
- */
- settings: VizualizerSettings;
/**
* A sequence instance that fulfills the sequence interface.
*/
@@ -67,7 +63,7 @@ export interface VizualizerInterface {
* Intialize is simply applying the configuration params to the vizualizer to prepare it to draw.
* @param config User set configuration settings. Generally if none are provided, the Vizualizer should use its own default
*/
- initialize(sketch: p5, seq: SequenceInterface, config?: VizualizerParamsSchema[]): void;
+ initialize(sketch: p5, seq: SequenceInterface): void;
/**
* Validates the cinfiguration
*/
diff --git a/src/vizualizers/vizualizerModFill.ts b/src/vizualizers/vizualizerModFill.ts
index a5298855..836ef7d3 100644
--- a/src/vizualizers/vizualizerModFill.ts
+++ b/src/vizualizers/vizualizerModFill.ts
@@ -2,9 +2,11 @@ import {SequenceInterface} from "@/sequences/sequenceInterface";
import {VizualizerDefault} from "@/vizualizers/vizualizerDefault";
import {VizualizerInterface, VizualizerParamsSchema, VizualizerSettings, VizualizerExportModule} from "@/vizualizers/vizualizerInterface";
import p5 from 'p5';
+import { ValidationStatus } from '@/shared/validationStatus';
//An example module
class VizModFill extends VizualizerDefault implements VizualizerInterface {
+ name = "Mod Fill";
settings: VizualizerSettings = {};
rectWidth = 0;
rectHeight = 0;
@@ -24,18 +26,22 @@ class VizModFill extends VizualizerDefault implements VizualizerInterface {
this.i = 0;
}
- initialize(sketch: p5, seq: SequenceInterface, config?: VizualizerParamsSchema[]) {
+ initialize(sketch: p5, seq: SequenceInterface){
this.sketch = sketch;
this.seq = seq;
- config = config !== undefined ? config : this.params;
- config.forEach(param => {
- this.settings[param.name] = param.value;
- });
this.ready = true;
}
+ validate(){
+ this.assignParams();
+ if(this.settings.modDimension > 0) return new ValidationStatus(true);
+ else if(this.settings.modDimension <= 0) return new ValidationStatus(false, ["Mod dimension must be positive"]);
+ else return new ValidationStatus(false, ["Please set a mod dimension"]);
+
+ }
+
drawNew(num: number, seq: SequenceInterface) {
const black = this.sketch.color(0);
this.sketch.fill(black);
diff --git a/src/vizualizers/vizualizerShiftCompare.ts b/src/vizualizers/vizualizerShiftCompare.ts
index 90b88cb1..54adf6fe 100644
--- a/src/vizualizers/vizualizerShiftCompare.ts
+++ b/src/vizualizers/vizualizerShiftCompare.ts
@@ -1,18 +1,40 @@
import p5 from "p5";
import { VizualizerDefault } from './vizualizerDefault';
-import { VizualizerInterface, VizualizerExportModule } from './vizualizerInterface';
+import { VizualizerInterface, VizualizerExportModule, VizualizerParamsSchema } from './vizualizerInterface';
+import { ValidationStatus } from '@/shared/validationStatus';
+import { SequenceInterface } from '@/sequences/sequenceInterface';
class VizShiftCompare extends VizualizerDefault implements VizualizerInterface {
- Name = "Shift Compare";
- MOD= 2;
- img: p5.Image;
+ name = "Shift Compare";
+ private img: p5.Image;
+ params = [new VizualizerParamsSchema(
+ "mod",
+ "number",
+ "Mod factor",
+ true,
+ 2,
+ "The shift that will be applied"
+ )];
- constructor() {
+ constructor(){
super();
+
this.img = this.sketch.createImage(this.sketch.width, this.sketch.height);
this.img.loadPixels(); // Enables pixel-level editing.
}
+ initialize(sketch: p5, seq: SequenceInterface){
+ this.sketch = sketch;
+ this.seq = seq;
+
+ }
+
+ validate() {
+ this.assignParams();
+ this.isValid = true;
+ return new ValidationStatus(true);
+ }
+
setup() {
console.log(this.sketch.height, this.sketch.width);
}
@@ -30,18 +52,19 @@ class VizShiftCompare extends VizualizerDefault implements VizualizerInterface {
draw() { //This will be called everytime to draw
// Ensure mouse coordinates are sane.
// Mouse coordinates look they're floats by default.
+ let mod = Number(this.settings.mod);
const d = this.sketch.pixelDensity();
const mx = this.clip(Math.round(this.sketch.mouseX), 0, this.sketch.width);
const my = this.clip(Math.round(this.sketch.mouseY), 0, this.sketch.height);
if (this.sketch.key == 'ArrowUp') {
- this.MOD += 1;
+ mod += 1;
this.sketch.key = '';
- console.log("UP PRESSED, NEW MOD: " + this.MOD);
+ console.log("UP PRESSED, NEW MOD: " + this.settings.mod);
} else if (this.sketch.key == 'ArrowDown') {
- this.MOD -= 1;
+ mod -= 1;
this.sketch.key = '';
- console.log("DOWN PRESSED, NEW MOD: " + this.MOD);
+ console.log("DOWN PRESSED, NEW MOD: " + mod);
} else if (this.sketch.key == 'ArrowRight') {
console.log(console.log("MX: " + mx + " MY: " + my));
}
@@ -51,7 +74,7 @@ class VizShiftCompare extends VizualizerDefault implements VizualizerInterface {
for (let i = 0; i < d; i++) {
for (let j = 0; j < d; j++) {
const index = 4 * ((y * d + j) * this.sketch.width * d + (x * d + i));
- if (this.seq.getElement(x) % (this.MOD) == this.seq.getElement(y) % (this.MOD)) {
+ if (this.seq.getElement(x) % (mod) == this.seq.getElement(y) % (mod)) {
this.img.pixels[index] = 255;
this.img.pixels[index + 1] = 255;
this.img.pixels[index + 2] = 255;
diff --git a/src/vizualizers/vizualizerTurtle.ts b/src/vizualizers/vizualizerTurtle.ts
index bd5e8ecd..7bf8082f 100644
--- a/src/vizualizers/vizualizerTurtle.ts
+++ b/src/vizualizers/vizualizerTurtle.ts
@@ -87,7 +87,12 @@ class VisualizerTurtle extends VizualizerDefault implements VizualizerInterface
initialize(sketch: p5, seq: SequenceInterface){
this.sketch = sketch;
- this.seq = seq;
+ this.seq = seq;
+
+ this.currentIndex = 0;
+ this.orientation = 0;
+ this.X = 0;
+ this.Y = 0;
console.log('initializing turtle');
for (let i = 0; i < this.domain.length; i++) {
@@ -98,9 +103,7 @@ class VisualizerTurtle extends VizualizerDefault implements VizualizerInterface
}
validate() {
- this.params.forEach(param => {
- this.settings[param.name] = param.value;
- });
+ this.assignParams();
const domain = String(this.settings.domain).split(',');
const range = String(this.settings.range).split(',');
@@ -112,7 +115,7 @@ class VisualizerTurtle extends VizualizerDefault implements VizualizerInterface
status.isValid = false
status.errors.push("Domain and range must have the same number of entries");
}
-
+ this.isValid = true;
return status;
}
diff --git a/todo.md b/todo.md
index f1a49548..fa06f7c6 100644
--- a/todo.md
+++ b/todo.md
@@ -1,13 +1,13 @@
High Priority
-- [ ] Consider removing settings from the interface
-- [ ] Consider providing a defaultViz function for assigning params to settings
-- [ ] Enable blow-up of the canvas
-- [ ] Fix mod fill and shift compare vizualizers
- [ ] Import/Export settings for seq and viz via JSON
- [ ] "Add New +" sequence button allows adding new sequences to choose from
Done
+- [x] Enable blow-up of the canvas
+- [x] Fix mod fill and shift compare vizualizers
+- [x] Consider providing a defaultViz function for assigning params to settings
+- [x] Consider removing settings from the interface
- [x] Generate thumbnails
- [x] Implement error checking/param conditions for seqs and vizs
- [x] Implement seq/viz bundles and storing configurations