mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
Golden Ratio script
This commit is contained in:
604
ea-scripts/Golden Ratio.md
Normal file
604
ea-scripts/Golden Ratio.md
Normal file
@@ -0,0 +1,604 @@
|
||||
/*
|
||||
The script performs two different functions depending on the elements selected in the view.
|
||||
1) In case you select text elements, the script will cycle through a set of font scales. First the 2 larger fonts following the Fibonacci sequence (fontsize * φ; fonsize * φ^2), then the 2 smaller fonts (fontsize / φ; fontsize / φ^2), finally the original size, followed again by the 2 larger fonts. If you wait 2 seconds, the sequence clears and starts from which ever font size you are on. So if you want the 3rd larges font, then toggle twice, wait 2 sec, then toggle again.
|
||||
2) In case you select a single rectangle, the script will open the "Golden Grid", "Golden Spiral" window, where you can set up the type of grid or spiral you want to insert into the document.
|
||||
|
||||

|
||||
|
||||
Gravitational point of spiral: $$\left[x,y\right]=\left[ x + \frac{{\text{width} \cdot \phi^2}}{{\phi^2 + 1}}\;, \; y + \frac{{\text{height} \cdot \phi^2}}{{\phi^2 + 1}} \right]$$
|
||||
Dimensions of inner rectangles in case of Double Spiral: $$[width, height] = \left[\frac{width\cdot(\phi^2+1)}{2\phi^2}\;, \;\frac{height\cdot(\phi^2+1)}{2\phi^2}\right]$$
|
||||
|
||||
```js*/
|
||||
const phi = (1 + Math.sqrt(5)) / 2; // Golden Ratio (φ)
|
||||
const inversePhi = (1-1/phi);
|
||||
const pointsPerCurve = 20; // Number of points per curve segment
|
||||
const ownerWindow = ea.targetView.ownerWindow;
|
||||
const hostLeaf = ea.targetView.leaf;
|
||||
let dirty = false;
|
||||
const ids = [];
|
||||
|
||||
const textEls = ea.getViewSelectedElements().filter(el=>el.type === "text");
|
||||
let rect = ea.getViewSelectedElements().length === 1 ? ea.getViewSelectedElement() : null;
|
||||
if(!rect || rect.type !== "rectangle") {
|
||||
//Fontsize cycle
|
||||
if(textEls.length>0) {
|
||||
if(window.excalidrawGoldenRatio) {
|
||||
clearTimeout(window.excalidrawGoldenRatio?.timer);
|
||||
} else {
|
||||
window.excalidrawGoldenRatio = {timer: null, cycle:-1};
|
||||
}
|
||||
window.excalidrawGoldenRatio.timer = setTimeout(()=>{delete window.excalidrawGoldenRatio;},2000);
|
||||
window.excalidrawGoldenRatio.cycle = (window.excalidrawGoldenRatio.cycle+1)%5;
|
||||
|
||||
ea.copyViewElementsToEAforEditing(textEls);
|
||||
ea.getElements().forEach(el=> {
|
||||
el.fontSize = window.excalidrawGoldenRatio.cycle === 2
|
||||
? el.fontSize / Math.pow(phi,4)
|
||||
: el.fontSize * phi;
|
||||
const font = ExcalidrawLib.getFontString(el);
|
||||
const lineHeight = ExcalidrawLib.getDefaultLineHeight(el.fontFamily);
|
||||
const {width, height, baseline} = ExcalidrawLib.measureText(el.originalText, font, lineHeight);
|
||||
el.width = width;
|
||||
el.height = height;
|
||||
el.baseline = baseline;
|
||||
});
|
||||
ea.addElementsToView();
|
||||
return;
|
||||
}
|
||||
new Notice("Select text elements, or a select a single rectangle");
|
||||
return;
|
||||
}
|
||||
ea.copyViewElementsToEAforEditing([rect]);
|
||||
rect = ea.getElement(rect.id);
|
||||
ids.push(rect.id);
|
||||
ea.style.strokeColor = rect.strokeColor;
|
||||
ea.style.strokeWidth = rect.strokeWidth;
|
||||
ea.style.roughness = rect.roughness;
|
||||
let {x,y,width,height} = rect;
|
||||
|
||||
// --------------------------------------------
|
||||
// Load Settings
|
||||
// --------------------------------------------
|
||||
let settings = ea.getScriptSettings();
|
||||
if(!settings["Horizontal Grid"]) {
|
||||
settings = {
|
||||
"Horizontal Grid" : {
|
||||
value: "left-right",
|
||||
valueset: ["none","letf-right","right-left","center-out","center-in"]
|
||||
},
|
||||
"Vertical Grid": {
|
||||
value: "none",
|
||||
valueset: ["none","top-down","bottom-up","center-out","center-in"]
|
||||
},
|
||||
"Size": {
|
||||
value: "6",
|
||||
valueset: ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"]
|
||||
},
|
||||
"Aspect Choice": {
|
||||
value: "none",
|
||||
valueset: ["none","adjust-width","adjust-height"]
|
||||
},
|
||||
"Type": "grid",
|
||||
"Spiral Orientation": {
|
||||
value: "top-left",
|
||||
valueset: ["double","top-left","top-right","bottom-right","bottom-left"]
|
||||
},
|
||||
"Lock Elements": false,
|
||||
"Send to Back": false,
|
||||
"Update Style": false,
|
||||
"Bold Spiral": false,
|
||||
};
|
||||
await ea.setScriptSettings(settings);
|
||||
}
|
||||
|
||||
let hDirection = settings["Horizontal Grid"].value;
|
||||
let vDirection = settings["Vertical Grid"].value;
|
||||
let aspectChoice = settings["Aspect Choice"].value;
|
||||
let type = settings["Type"];
|
||||
let spiralOrientation = settings["Spiral Orientation"].value;
|
||||
let lockElements = settings["Lock Elements"];
|
||||
let sendToBack = settings["Send to Back"];
|
||||
let size = parseInt(settings["Size"].value);
|
||||
let updateStyle = settings["Update Style"];
|
||||
let boldSpiral = settings["Bold Spiral"];
|
||||
|
||||
// --------------------------------------------
|
||||
// Grid
|
||||
// --------------------------------------------
|
||||
const calculateGoldenSum = (baseOfGoldenGrid, pow) => {
|
||||
const ratio = 1 / phi;
|
||||
const geometricSum = baseOfGoldenGrid * ((1 - Math.pow(ratio, pow)) / (1 - ratio));
|
||||
return geometricSum;
|
||||
};
|
||||
|
||||
const findBaseForGoldenGrid = (targetValue, n, scenario) => {
|
||||
const ratio = 1 / phi;
|
||||
if (scenario === "center-out") {
|
||||
return targetValue * (2-2*ratio) / (1 + ratio + 2*Math.pow(ratio,n));
|
||||
} else if (scenario === "center-in") {
|
||||
return targetValue*2*(1-ratio)*Math.pow(phi,n-1) /(2*Math.pow(phi,n-1)*(1-Math.pow(ratio,n))-1+ratio);
|
||||
} else {
|
||||
return targetValue * (1-ratio)/(1-Math.pow(ratio,n));
|
||||
}
|
||||
}
|
||||
|
||||
const calculateOffsetVertical = (scenario, base) => {
|
||||
if (scenario === "center-out") return base / 2;
|
||||
if (scenario === "center-in") return base / Math.pow(phi, size + 1) / 2;
|
||||
return 0;
|
||||
};
|
||||
|
||||
const horizontal = (direction, scenario) => {
|
||||
const base = findBaseForGoldenGrid(width, size + 1, scenario);
|
||||
const totalGridWidth = calculateGoldenSum(base, size + 1);
|
||||
|
||||
for (i = 1; i <= size; i++) {
|
||||
const offset =
|
||||
scenario === "center-out"
|
||||
? totalGridWidth - calculateGoldenSum(base, i)
|
||||
: calculateGoldenSum(base, size + 1 - i);
|
||||
|
||||
const x2 =
|
||||
direction === "left"
|
||||
? x + offset
|
||||
: x + width - offset;
|
||||
|
||||
ids.push(
|
||||
ea.addLine([
|
||||
[x2, y],
|
||||
[x2, y + height],
|
||||
])
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const vertical = (direction, scenario) => {
|
||||
const base = findBaseForGoldenGrid(height, size + 1, scenario);
|
||||
const totalGridWidth = calculateGoldenSum(base, size + 1);
|
||||
|
||||
for (i = 1; i <= size; i++) {
|
||||
const offset =
|
||||
scenario === "center-out"
|
||||
? totalGridWidth - calculateGoldenSum(base, i)
|
||||
: calculateGoldenSum(base, size + 1 - i);
|
||||
|
||||
const y2 =
|
||||
direction === "top"
|
||||
? y + offset
|
||||
: y + height - offset;
|
||||
|
||||
ids.push(
|
||||
ea.addLine([
|
||||
[x, y2],
|
||||
[x+width, y2],
|
||||
])
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const centerHorizontal = (scenario) => {
|
||||
width = width / 2;
|
||||
horizontal("left", scenario);
|
||||
x += width;
|
||||
horizontal("right", scenario);
|
||||
x -= width;
|
||||
width = 2*width;
|
||||
|
||||
};
|
||||
|
||||
const centerVertical = (scenario) => {
|
||||
height = height / 2;
|
||||
vertical("top", scenario);
|
||||
y += height;
|
||||
vertical("bottom", scenario);
|
||||
y -= height;
|
||||
height = 2*height;
|
||||
};
|
||||
|
||||
const drawGrid = () => {
|
||||
switch(hDirection) {
|
||||
case "none": break;
|
||||
case "left-right": horizontal("left"); break;
|
||||
case "right-left": horizontal("right"); break;
|
||||
case "center-out": centerHorizontal("center-out"); break;
|
||||
case "center-in": centerHorizontal("center-in"); break;
|
||||
}
|
||||
switch(vDirection) {
|
||||
case "none": break;
|
||||
case "top-down": vertical("top"); break;
|
||||
case "bottom-up": vertical("bottom"); break;
|
||||
case "center-out": centerVertical("center-out"); break;
|
||||
case "center-in": centerVertical("center-in"); break;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
// Draw Spiral
|
||||
// --------------------------------------------
|
||||
const drawSpiral = () => {
|
||||
let nextX, nextY, nextW, nextH;
|
||||
let spiralPoints = [];
|
||||
let curveEndX, curveEndY, curveX, curveY;
|
||||
|
||||
const phaseShift = {
|
||||
"bottom-right": 0,
|
||||
"bottom-left": 2,
|
||||
"top-left": 2,
|
||||
"top-right": 0,
|
||||
}[spiralOrientation];
|
||||
|
||||
let curveStartX = {
|
||||
"bottom-right": x,
|
||||
"bottom-left": x+width,
|
||||
"top-left": x+width,
|
||||
"top-right": x,
|
||||
}[spiralOrientation];
|
||||
|
||||
let curveStartY = {
|
||||
"bottom-right": y+height,
|
||||
"bottom-left": y+height,
|
||||
"top-left": y,
|
||||
"top-right": y,
|
||||
}[spiralOrientation];
|
||||
|
||||
const mirror = spiralOrientation === "bottom-left" || spiralOrientation === "top-right";
|
||||
for (let i = phaseShift; i < size+phaseShift; i++) {
|
||||
const curvePhase = i%4;
|
||||
const linePhase = mirror?[0,3,2,1][curvePhase]:curvePhase;
|
||||
const longHorizontal = width/phi;
|
||||
const shortHorizontal = width*inversePhi;
|
||||
const longVertical = height/phi;
|
||||
const shortVertical = height*inversePhi;
|
||||
switch(linePhase) {
|
||||
case 0: //right
|
||||
nextX = x + longHorizontal;
|
||||
nextY = y;
|
||||
nextW = shortHorizontal;
|
||||
nextH = height;
|
||||
break;
|
||||
case 1: //down
|
||||
nextX = x;
|
||||
nextY = y + longVertical;
|
||||
nextW = width;
|
||||
nextH = shortVertical;
|
||||
break;
|
||||
case 2: //left
|
||||
nextX = x;
|
||||
nextY = y;
|
||||
nextW = shortHorizontal;
|
||||
nextH = height;
|
||||
break;
|
||||
case 3: //up
|
||||
nextX = x;
|
||||
nextY = y;
|
||||
nextW = width;
|
||||
nextH = shortVertical;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(curvePhase) {
|
||||
case 0: //right
|
||||
curveEndX = nextX;
|
||||
curveEndY = mirror ? nextY + nextH : nextY;
|
||||
break;
|
||||
case 1: //down
|
||||
curveEndX = nextX + nextW;
|
||||
curveEndY = mirror ? nextY + nextH : nextY;
|
||||
break;
|
||||
case 2: //left
|
||||
curveEndX = nextX + nextW;
|
||||
curveEndY = mirror ? nextY : nextY + nextH;
|
||||
break;
|
||||
case 3: //up
|
||||
curveEndX = nextX;
|
||||
curveEndY = mirror ? nextY : nextY + nextH;
|
||||
break;
|
||||
}
|
||||
|
||||
// Add points for the curve segment
|
||||
|
||||
for (let j = 0; j <= pointsPerCurve; j++) {
|
||||
const t = j / pointsPerCurve;
|
||||
const angle = -Math.PI / 2 * t;
|
||||
|
||||
switch(curvePhase) {
|
||||
case 0:
|
||||
curveX = curveEndX + (curveStartX - curveEndX) * Math.cos(angle);
|
||||
curveY = curveStartY + (curveStartY - curveEndY) * Math.sin(angle);
|
||||
break;
|
||||
case 1:
|
||||
curveX = curveStartX + (curveStartX - curveEndX) * Math.sin(angle);
|
||||
curveY = curveEndY + (curveStartY - curveEndY) * Math.cos(angle);
|
||||
break;
|
||||
case 2:
|
||||
curveX = curveEndX + (curveStartX - curveEndX) * Math.cos(angle);
|
||||
curveY = curveStartY + (curveStartY - curveEndY) * Math.sin(angle);
|
||||
break;
|
||||
case 3:
|
||||
curveX = curveStartX + (curveStartX - curveEndX) * Math.sin(angle);
|
||||
curveY = curveEndY + (curveStartY - curveEndY) * Math.cos(angle);
|
||||
break;
|
||||
}
|
||||
spiralPoints.push([curveX, curveY]);
|
||||
}
|
||||
x = nextX;
|
||||
y = nextY;
|
||||
curveStartX = curveEndX;
|
||||
curveStartY = curveEndY;
|
||||
width = nextW;
|
||||
height = nextH;
|
||||
switch(linePhase) {
|
||||
case 0: ids.push(ea.addLine([[x,y],[x,y+height]]));break;
|
||||
case 1: ids.push(ea.addLine([[x,y],[x+width,y]]));break;
|
||||
case 2: ids.push(ea.addLine([[x+width,y],[x+width,y+height]]));break;
|
||||
case 3: ids.push(ea.addLine([[x,y+height],[x+width,y+height]]));break;
|
||||
}
|
||||
}
|
||||
const strokeWidth = ea.style.strokeWidth;
|
||||
ea.style.strokeWidth = strokeWidth * (boldSpiral ? 3 : 1)
|
||||
ids.push(ea.addLine(spiralPoints));
|
||||
ea.style.strokeWidth = strokeWidth;
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
// Update Aspect Ratio
|
||||
// --------------------------------------------
|
||||
const updateAspectRatio = () => {
|
||||
switch(aspectChoice) {
|
||||
case "none": break;
|
||||
case "adjust-width": rect.width = rect.height/phi; break;
|
||||
case "adjust-height": rect.height = rect.width/phi; break;
|
||||
}
|
||||
({x,y,width,height} = rect);
|
||||
}
|
||||
// --------------------------------------------
|
||||
// UI
|
||||
// --------------------------------------------
|
||||
draw = async () => {
|
||||
if(updateStyle) {
|
||||
ea.style.strokeWidth = 0.5; rect.strokeWidth;
|
||||
ea.style.roughness = 0; rect.roughness;
|
||||
ea.style.roundness = null;
|
||||
rect.strokeWidth = 0.5;
|
||||
rect.roughness = 0;
|
||||
rect.roundness = null;
|
||||
}
|
||||
updateAspectRatio();
|
||||
switch(type) {
|
||||
case "grid": drawGrid(); break;
|
||||
case "spiral":
|
||||
if(spiralOrientation === "double") {
|
||||
wInner = width * (Math.pow(phi,2)+1)/(2*Math.pow(phi,2));
|
||||
hInner = height * (Math.pow(phi,2)+1)/(2*Math.pow(phi,2));
|
||||
x2 = width - wInner + x;
|
||||
y2 = height - hInner + y;
|
||||
width = wInner;
|
||||
height = hInner;
|
||||
ids.push(ea.addRect(x,y,width,height));
|
||||
spiralOrientation = "bottom-right";
|
||||
drawSpiral();
|
||||
x = x2;
|
||||
y = y2;
|
||||
width = wInner;
|
||||
height = hInner;
|
||||
ids.push(ea.addRect(x,y,width,height));
|
||||
spiralOrientation = "top-left";
|
||||
drawSpiral();
|
||||
} else {
|
||||
drawSpiral();
|
||||
}
|
||||
break;
|
||||
}
|
||||
ea.addToGroup(ids);
|
||||
lockElements && ea.getElements().forEach(el=>{el.locked = true;});
|
||||
await ea.addElementsToView(false,false,!sendToBack);
|
||||
!lockElements && ea.selectElementsInView(ea.getViewElements().filter(el => ids.includes(el.id)));
|
||||
}
|
||||
|
||||
const modal = new ea.obsidian.Modal(app);
|
||||
|
||||
const fragWithHTML = (html) => createFragment((frag) => (frag.createDiv().innerHTML = html));
|
||||
|
||||
const keydownListener = (e) => {
|
||||
if(hostLeaf !== app.workspace.activeLeaf) return;
|
||||
if(hostLeaf.width === 0 && hostLeaf.height === 0) return;
|
||||
if(e.key === "Enter" && (e.ctrlKey || e.shiftKey || e.metaKey || e.altKey)) {
|
||||
e.preventDefault();
|
||||
modal.close();
|
||||
draw()
|
||||
}
|
||||
}
|
||||
ownerWindow.addEventListener('keydown',keydownListener);
|
||||
|
||||
modal.onOpen = async () => {
|
||||
const contentEl = modal.contentEl;
|
||||
contentEl.createEl("h1", {text: "Golden Ratio"});
|
||||
|
||||
new ea.obsidian.Setting(contentEl)
|
||||
.setName("Adjust Rectangle Aspect Ratio to Golden Ratio")
|
||||
.addDropdown(dropdown=>dropdown
|
||||
.addOption("none","None")
|
||||
.addOption("adjust-width","Adjust Width")
|
||||
.addOption("adjust-height","Adjust Height")
|
||||
.setValue(aspectChoice)
|
||||
.onChange(value => {
|
||||
aspectChoice = value;
|
||||
dirty = true;
|
||||
})
|
||||
);
|
||||
|
||||
new ea.obsidian.Setting(contentEl)
|
||||
.setName("Change Line Style To: thin, architect, sharp")
|
||||
.addToggle(toggle=>
|
||||
toggle
|
||||
.setValue(updateStyle)
|
||||
.onChange(value => {
|
||||
dirty = true;
|
||||
updateStyle = value;
|
||||
})
|
||||
)
|
||||
|
||||
let sizeEl;
|
||||
new ea.obsidian.Setting(contentEl)
|
||||
.setName("Number of lines")
|
||||
.addSlider(slider => slider
|
||||
.setLimits(2, 20, 1)
|
||||
.setValue(size)
|
||||
.onChange(value => {
|
||||
sizeEl.innerText = ` ${value.toString()}`;
|
||||
size = value;
|
||||
dirty = true;
|
||||
}),
|
||||
)
|
||||
.settingEl.createDiv("", el => {
|
||||
sizeEl = el;
|
||||
el.style.minWidth = "2.3em";
|
||||
el.style.textAlign = "right";
|
||||
el.innerText = ` ${size.toString()}`;
|
||||
});
|
||||
|
||||
new ea.obsidian.Setting(contentEl)
|
||||
.setName("Lock Rectangle and Gridlines")
|
||||
.addToggle(toggle=>
|
||||
toggle
|
||||
.setValue(lockElements)
|
||||
.onChange(value => {
|
||||
dirty = true;
|
||||
lockElements = value;
|
||||
})
|
||||
)
|
||||
|
||||
new ea.obsidian.Setting(contentEl)
|
||||
.setName("Send to Back")
|
||||
.addToggle(toggle=>
|
||||
toggle
|
||||
.setValue(sendToBack)
|
||||
.onChange(value => {
|
||||
dirty = true;
|
||||
sendToBack = value;
|
||||
})
|
||||
)
|
||||
|
||||
let bGrid, bSpiral;
|
||||
let sHGrid, sVGrid, sSpiral, sBoldSpiral;
|
||||
const showGridSettings = (value) => {
|
||||
value
|
||||
? (bGrid.setCta(), bSpiral.removeCta())
|
||||
: (bGrid.removeCta(), bSpiral.setCta());
|
||||
sHGrid.settingEl.style.display = value ? "" : "none";
|
||||
sVGrid.settingEl.style.display = value ? "" : "none";
|
||||
sSpiral.settingEl.style.display = !value ? "" : "none";
|
||||
sBoldSpiral.settingEl.style.display = !value ? "" : "none";
|
||||
}
|
||||
|
||||
new ea.obsidian.Setting(contentEl)
|
||||
.setName(fragWithHTML("<h3>Output Type</h3>"))
|
||||
.addButton(button => {
|
||||
bGrid = button;
|
||||
button
|
||||
.setButtonText("Grid")
|
||||
.setCta(type === "grid")
|
||||
.onClick(event => {
|
||||
type = "grid";
|
||||
showGridSettings(true);
|
||||
dirty = true;
|
||||
})
|
||||
})
|
||||
.addButton(button => {
|
||||
bSpiral = button;
|
||||
button
|
||||
.setButtonText("Spiral")
|
||||
.setCta(type === "spiral")
|
||||
.onClick(event => {
|
||||
type = "spiral";
|
||||
showGridSettings(false);
|
||||
dirty = true;
|
||||
})
|
||||
});
|
||||
|
||||
sSpiral = new ea.obsidian.Setting(contentEl)
|
||||
.setName("Spiral Orientation")
|
||||
.addDropdown(dropdown=>dropdown
|
||||
.addOption("double","Double")
|
||||
.addOption("top-left","Top left")
|
||||
.addOption("top-right","Top right")
|
||||
.addOption("bottom-right","Bottom right")
|
||||
.addOption("bottom-left","Bottom left")
|
||||
.setValue(spiralOrientation)
|
||||
.onChange(value => {
|
||||
spiralOrientation = value;
|
||||
dirty = true;
|
||||
})
|
||||
);
|
||||
|
||||
sBoldSpiral = new ea.obsidian.Setting(contentEl)
|
||||
.setName("Spiral with Bold Line")
|
||||
.addToggle(toggle=>
|
||||
toggle
|
||||
.setValue(boldSpiral)
|
||||
.onChange(value => {
|
||||
dirty = true;
|
||||
boldSpiral = value;
|
||||
})
|
||||
)
|
||||
|
||||
sHGrid = new ea.obsidian.Setting(contentEl)
|
||||
.setName("Horizontal Grid")
|
||||
.addDropdown(dropdown=>dropdown
|
||||
.addOption("none","None")
|
||||
.addOption("left-right","Left to right")
|
||||
.addOption("right-left","Right to left")
|
||||
.addOption("center-out","Center out")
|
||||
.addOption("center-in","Center in")
|
||||
.setValue(hDirection)
|
||||
.onChange(value => {
|
||||
hDirection = value;
|
||||
dirty = true;
|
||||
})
|
||||
);
|
||||
|
||||
sVGrid = new ea.obsidian.Setting(contentEl)
|
||||
.setName("Vertical Grid")
|
||||
.addDropdown(dropdown=>dropdown
|
||||
.addOption("none","None")
|
||||
.addOption("top-down","Top down")
|
||||
.addOption("bottom-up","Bootom up")
|
||||
.addOption("center-out","Center out")
|
||||
.addOption("center-in","Center in")
|
||||
.setValue(vDirection)
|
||||
.onChange(value => {
|
||||
vDirection = value;
|
||||
dirty = true;
|
||||
})
|
||||
);
|
||||
|
||||
showGridSettings(type === "grid");
|
||||
new ea.obsidian.Setting(contentEl)
|
||||
.addButton(button => button
|
||||
.setButtonText("Run")
|
||||
.setCta(true)
|
||||
.onClick(async (event) => {
|
||||
draw();
|
||||
modal.close();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
modal.onClose = () => {
|
||||
if(dirty) {
|
||||
settings["Horizontal Grid"].value = hDirection;
|
||||
settings["Vertical Grid"].value = vDirection;
|
||||
settings["Size"].value = size.toString();
|
||||
settings["Aspect Choice"].value = aspectChoice;
|
||||
settings["Type"] = type;
|
||||
settings["Spiral Orientation"].value = spiralOrientation;
|
||||
settings["Lock Elements"] = lockElements;
|
||||
settings["Send to Back"] = sendToBack;
|
||||
settings["Update Style"] = updateStyle;
|
||||
settings["Bold Spiral"] = boldSpiral;
|
||||
ea.setScriptSettings(settings);
|
||||
}
|
||||
ownerWindow.removeEventListener('keydown',keydownListener);
|
||||
}
|
||||
|
||||
modal.open();
|
||||
1
ea-scripts/Golden Ratio.svg
Normal file
1
ea-scripts/Golden Ratio.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 642.8 373.7"><path fill="none" stroke-linecap="round" stroke-width="4" d="M5 5h633M5 5h633m0 0v364m0-364v364m0 0H5m633 0H5m0 0V5m0 364V5m242 0v364m0-364v364M5 144h242M5 144h242M154 5v139m0-139v139m0-53h93m-93 0h93m-57 0v53m0-53v53m-36-33h36m-36 0h36m-14-20v20m0-20v20m0-8h14m-14 0h14"/><path fill="none" stroke-linecap="round" stroke-width="12" d="m638 5-5 57m5-57-5 57m0 0-14 55m14-55-14 55m0 0-24 53m24-53-24 53m0 0-32 49m32-49-32 49m0 0-40 43m40-43-40 43m0 0-46 37m46-37-46 37m0 0-53 30m53-30-53 30m0 0-56 22m56-22-56 22m0 0-60 13m60-13-60 13m0 0-61 5m61-5-61 5m0 0s0 0 0 0m0 0s0 0 0 0m0 0-38-3m38 3-38-3m0 0-37-8m37 8-37-8m0 0-35-14m35 14-35-14m0 0-32-18m32 18-32-18m0 0-29-23m29 23-29-23m0 0-25-27m25 27-25-27m0 0-20-30m20 30-20-30m0 0-14-33m14 33-14-33m0 0-9-34m9 34-9-34m0 0-3-35m3 35-3-35m0 0s0 0 0 0m0 0s0 0 0 0m0 0 2-22m-2 22 2-22m0 0 5-21m-5 21 5-21m0 0 9-20m-9 20 9-20m0 0 13-19M21 81l13-19m0 0 15-16M34 62l15-16m0 0 18-14M49 46l18-14m0 0 20-12M67 32c4-3 8-6 20-12m0 0 21-8m-21 8 21-8m0 0 23-5m-23 5 23-5m0 0 23-2m-23 2 23-2m0 0s0 0 0 0m0 0s0 0 0 0m0 0 15 1m-15-1 15 1m0 0 14 3m-14-3 14 3m0 0 13 5m-13-5 13 5m0 0 13 7m-13-7 13 7m0 0 11 9m-11-9 11 9m0 0 9 10m-9-10 9 10m0 0 8 12m-8-12 8 12m0 0 5 12m-5-12 5 12m0 0 4 13m-4-13 4 13m0 0 1 14m-1-14 1 14m0 0s0 0 0 0m0 0s0 0 0 0m0 0-1 8m1-8-1 8m0 0-2 8m2-8-2 8m0 0-4 8m4-8-4 8m0 0-4 7m4-7-4 7m0 0-6 6m6-6-6 6m0 0-7 6m7-6-7 6m0 0-7 4m7-4-7 4m0 0-9 3m9-3-9 3m0 0-8 2m8-2-8 2m0 0-9 1m9-1-9 1m0 0s0 0 0 0m0 0s0 0 0 0m0 0h-6m6 0h-6m0 0-5-2m5 2-5-2m0 0-5-2m5 2-5-2m0 0-5-2m5 2-5-2m0 0-4-4m4 4-4-4m0 0-4-4m4 4-4-4m0 0-3-4m3 4-3-4m0 0-2-5m2 5-2-5m0 0-1-5m1 5-1-5m0 0-1-5m1 5-1-5m0 0s0 0 0 0m0 0s0 0 0 0m0 0 1-3m-1 3 1-3m0 0v-3m0 3v-3m0 0 2-3m-2 3 2-3m0 0 2-3m-2 3 2-3m0 0 2-2m-2 2 2-2m0 0 2-2m-2 2 2-2m0 0 3-2m-3 2 3-2m0 0 3-1m-3 1 3-1m0 0 4-1m-4 1 4-1m0 0h3m-3 0h3m0 0s0 0 0 0m0 0s0 0 0 0m0 0h2m-2 0h2m0 0h2m-2 0h2m0 0 2 1m-2-1 2 1m0 0 2 1m-2-1 2 1m0 0 2 2m-2-2 2 2m0 0 1 1m-1-1 1 1m0 0 1 2m-1-2 1 2m0 0 1 2m-1-2 1 2m0 0v1m0-1v1m0 0 1 2m-1-2 1 2"/></svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
File diff suppressed because one or more lines are too long
@@ -44,6 +44,7 @@ I would love to include your contribution in the script library. If you have a s
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Fixed%20spacing.svg"/></div>|[[#Fixed spacing]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Fixed%20vertical%20distance%20between%20centers.svg"/></div>|[[#Fixed vertical distance between centers]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Fixed%20vertical%20distance.svg"/></div>|[[#Fixed vertical distance]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Golden%20Ratio.svg"/></div>|[[#Golden Ratio]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Grid%20Selected%20Images.svg"/></div>|[[#Grid selected images]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Mindmap%20format.svg"/></div>|[[#Mindmap format]]|
|
||||
|<div><img src="https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Zoom%20to%20Fit%20Selected%20Elements.svg"/></div>|[[#Zoom to Fit Selected Elements]]|
|
||||
@@ -348,6 +349,14 @@ https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea
|
||||
```
|
||||
<table><tr valign='top'><td class="label">Author</td><td class="data"><a href='https://github.com/zsviczian'>@zsviczian</a></td></tr><tr valign='top'><td class="label">Source</td><td class="data"><a href='https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Folder%20Note%20Core%20-%20Make%20Current%20Drawing%20a%20Folder.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">This script adds the `Folder Note Core: Make current document folder note` function to Excalidraw drawings. Running this script will convert the active Excalidraw drawing into a folder note. If you already have embedded images in your drawing, those attachments will not be moved when the folder note is created. You need to take care of those attachments separately, or convert the drawing to a folder note prior to adding the attachments. The script requires the <a href="https://github.com/aidenlx/folder-note-core" target="_blank">Folder Note Core</a> plugin.</td></tr></table>
|
||||
|
||||
## Golden Ratio
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Golden%20Ratio.md
|
||||
```
|
||||
<table><tr valign='top'><td class="label">Author</td><td class="data"><a href='https://github.com/zsviczian'>@zsviczian</a></td></tr><tr valign='top'><td class="label">Source</td><td class="data"><a href='https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Golden%20Ratio.md'>File on GitHub</a></td></tr><tr valign='top'><td class="label">Description</td><td class="data">The script performs two different functions depending on the elements selected in the view.<br>
|
||||
1) In case you select text elements, the script will cycle through a set of font scales. First the 2 larger fonts following the Fibonacci sequence (fontsize * φ; fonsize * φ^2), then the 2 smaller fonts (fontsize / φ; fontsize / φ^2), finally the original size, followed again by the 2 larger fonts. If you wait 2 seconds, the sequence clears and starts from which ever font size you are on. So if you want the 3rd larges font, then toggle twice, wait 2 sec, then toggle again.<br>
|
||||
2) In case you select a single rectangle, the script will open the "Golden Grid", "Golden Spiral" window, where you can set up the type of grid or spiral you want to insert into the document.<br><img src='https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/golden-ratio.jpg'></td></tr></table>
|
||||
|
||||
## Grid selected images
|
||||
```excalidraw-script-install
|
||||
https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Grid%20Selected%20Images.md
|
||||
|
||||
Reference in New Issue
Block a user