From ec4a232fe72f221bef675c8ef099e2828f366a3a Mon Sep 17 00:00:00 2001 From: Jenny Lin Date: Thu, 20 Jul 2023 11:58:24 -0400 Subject: [PATCH] operation for making a sierpinski square --- .../core/operations/sierpinski/sierpinski.ts | 141 ++++++++++++++++++ src/app/core/provider/operation.service.ts | 2 + src/assets/json/op_classifications.json | 3 +- src/assets/json/op_descriptions.json | 8 +- 4 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 src/app/core/operations/sierpinski/sierpinski.ts diff --git a/src/app/core/operations/sierpinski/sierpinski.ts b/src/app/core/operations/sierpinski/sierpinski.ts new file mode 100644 index 000000000..dfcb891bc --- /dev/null +++ b/src/app/core/operations/sierpinski/sierpinski.ts @@ -0,0 +1,141 @@ +import { NumParam, BoolParam, Operation, OperationInlet, OpInput, OpParamVal, Cell } from "../../model/datatypes"; +import { getCol, initDraftFromDrawdown, updateWarpSystemsAndShuttles, updateWeftSystemsAndShuttles, warps } from "../../model/drafts"; +import { getAllDraftsAtInlet, getInputDraft, getOpParamValById, parseDraftNames } from "../../model/operations"; +import { Sequence } from "../../model/sequence"; + +/** + * this will be the default function going forward, as the others will be removed. + */ + +const name = "sierpinski"; +const old_names = []; + +//PARAMS + +const amt_size:NumParam = + {name: 'size', + type: 'number', + min: 1, + max: 1000, + value: 10, + dx: 'size of the square' + } + +const amt_recur:NumParam = + {name: 'recursion depth', + type: 'number', + min: 1, + max: 10, + value: 2, + dx: 'how many holes you punch (recursively)' + } + +const facing: BoolParam = + {name: 'facing', + type: 'boolean', + falsestate: "weft facing", + truestate: "warp facing", + value: 0, + dx: '' + } + +const params = [amt_size, amt_recur, facing]; + +//INLETS +/*const draft_inlet: OperationInlet = { + name: 'draft', + type: 'static', + value: null, + dx: 'the draft to shift', + uses: "draft", + num_drafts: 1 + }*/ + + const inlets = []; + + +function punch_hole(draft: Array>, x:number, y:number, x_dim:number, y_dim:number, depth:number) { + console.log("x: " + x + " y: "+y+" xdim: "+x_dim + " ydim: "+y_dim + " depth: "+depth); + if (x_dim < 3 || y_dim < 3 || depth < 1) { //too small to punch hole + return; + } + //Just going to assume everything in that region is one value for now + const bg = draft[x][y].is_up; + const hole = !bg; + + + let out_x = (x_dim % 3 == 2) ? Math.ceil(x_dim/3) : Math.floor(x_dim/3); + let mid_x = x_dim-2*out_x; + let out_y = (y_dim % 3 == 2) ? Math.ceil(y_dim/3) : Math.floor(y_dim/3); + let mid_y = y_dim-2*out_y; + + + + let x_corners = [x, x+out_x, x+out_x+mid_x]; + let y_corners = [y, y+out_y, y+out_y+mid_y]; + + + //punch out middle square + for (let i=x_corners[1]; i, op_inputs: Array) => { + + //let input_draft = getInputDraft(op_inputs); + let amt_size = getOpParamValById(0, op_params); + let amt_recur = getOpParamValById(1, op_params); + let facing = getOpParamValById(2, op_params); + + //if(input_draft == null) return Promise.resolve([]); + + /*let warp_systems = new Sequence.OneD(input_draft.colSystemMapping).shift(-amt_x); + + let warp_mats = new Sequence.OneD(input_draft.colShuttleMapping).shift(-amt_x); + + let weft_systems = new Sequence.OneD(input_draft.rowSystemMapping).shift(-amt_y); + + let weft_materials = new Sequence.OneD(input_draft.rowShuttleMapping).shift(-amt_y);*/ + + let init = new Sequence.TwoD(); + init.setBlank(facing ? 1 : 0).fill(amt_size, amt_size); + let pattern_data = init.export(); + + punch_hole(pattern_data, 0, 0, amt_size, amt_size, amt_recur); + + console.log(pattern_data); + + let d = initDraftFromDrawdown(pattern_data); + + + + return Promise.resolve([d]); +} + +const generateName = (param_vals: Array, op_inputs: Array) : string => { + let amt_x = getOpParamValById(0, param_vals); + let amt_y = getOpParamValById(1, param_vals); + let drafts = getAllDraftsAtInlet(op_inputs, 0); + return 'sierpinski'+amt_x+'/'+amt_y; +} + + +export const sierpinski: Operation = {name, old_names, params, inlets, perform, generateName}; + diff --git a/src/app/core/provider/operation.service.ts b/src/app/core/provider/operation.service.ts index 08f08f3fe..25070d40a 100644 --- a/src/app/core/provider/operation.service.ts +++ b/src/app/core/provider/operation.service.ts @@ -41,6 +41,7 @@ import { set } from '../operations/set/set'; import { shaded_satin } from '../operations/shaded_satin/shaded_satin'; import { shiftx } from '../operations/shiftx/shiftx'; import { shifty } from '../operations/shifty/shifty'; +import { sierpinski } from '../operations/sierpinski/sierpinski'; import { slope } from '../operations/slope/slope'; import { spliceinwarps } from '../operations/spliceinwarps/spliceinwarps'; import { splicein } from '../operations/spliceinwefts/spliceinwefts'; @@ -127,6 +128,7 @@ export class OperationService { this.ops.push(flipy); this.ops.push(shiftx); this.ops.push(shifty); + this.ops.push(sierpinski); this.ops.push(layer); this.ops.push(selvedge); this.ops.push(bindweftfloats); diff --git a/src/assets/json/op_classifications.json b/src/assets/json/op_classifications.json index ec22f690f..3d3a02e09 100644 --- a/src/assets/json/op_classifications.json +++ b/src/assets/json/op_classifications.json @@ -16,6 +16,7 @@ "tree", "combos", "bwimagemap", + "sierpinski", "sine", "sawtooth", "satinish" @@ -123,4 +124,4 @@ ] -} \ No newline at end of file +} diff --git a/src/assets/json/op_descriptions.json b/src/assets/json/op_descriptions.json index d11ed82ca..c05adeebc 100644 --- a/src/assets/json/op_descriptions.json +++ b/src/assets/json/op_descriptions.json @@ -66,6 +66,12 @@ "displayname": "shift", "description": "Generates an output that is shifted to the left and top by the number of warp ends and weft pics specified in the parameters.", "application": "Creates a version of a draft that is structurally identical, but has the placement of interlacements fine tuned in relation to other structures" + }, + { + "name":"sierpinski", + "displayname": "sierpinski", + "description": "Make a sierpinski square", + "application": "Make a sierpinski square (fun)" }, { "name":"slope", @@ -506,4 +512,4 @@ -} \ No newline at end of file +}