Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nay-cat authored Apr 8, 2024
1 parent effeebb commit affd34a
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions actions/draw_line_on_image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
module.exports = {

Check failure on line 1 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
name: "Draw Line on Image",

Check failure on line 2 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `↹name:·"Draw·Line·on·Image",␍` with `··name:·'Draw·Line·on·Image',`
section: "Image Editing",

Check failure on line 3 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `↹section:·"Image·Editing",␍` with `··section:·'Image·Editing',⏎`

Check failure on line 4 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `␍⏎↹subtitle(data,·presets)·{␍` with `subtitle(data,·presets)·{`
subtitle(data, presets) {
const storeTypes = presets.variables;

Check failure on line 6 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `↹··const·storeTypes·=·presets.variables;␍` with `····const·storeTypes·=·presets.variables;`
return `${storeTypes[parseInt(data.storage, 10)]} (${data.varName})`;

Check failure on line 7 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `↹··return·`${storeTypes[parseInt(data.storage,·10)]}·(${data.varName})`;␍` with `····return·`${storeTypes[parseInt(data.storage,·10)]}·(${data.varName})`;`
},

Check failure on line 8 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `↹},␍` with `··},⏎`

Check failure on line 9 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `␍⏎↹meta:·{·version:·"2.1.7",·preciseCheck:·true,·author:·null,·authorUrl:·null,·downloadUrl:·null·},␍` with `meta:·{·version:·'2.1.7',·preciseCheck:·true,·author:·null,·authorUrl:·null,·downloadUrl:·null·},⏎`
meta: { version: "2.1.7", preciseCheck: true, author: null, authorUrl: null, downloadUrl: null },

Check failure on line 11 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `␍⏎↹fields:·["storage",·"varName",·"x1",·"y1",·"x2",·"y2",·"color",·"thickness"],␍` with `fields:·['storage',·'varName',·'x1',·'y1',·'x2',·'y2',·'color',·'thickness'],⏎`
fields: ["storage", "varName", "x1", "y1", "x2", "y2", "color", "thickness"],

Check failure on line 13 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

Replace `␍⏎↹html(isEvent,·data)·{␍` with `html(isEvent,·data)·{`
html(isEvent, data) {

Check warning on line 14 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

'isEvent' is defined but never used

Check warning on line 14 in actions/draw_line_on_image.js

View workflow job for this annotation

GitHub Actions / ESLint

'data' is defined but never used
return `
<retrieve-from-variable dropdownLabel="Source Image" selectId="storage" variableContainerId="varNameContainer" variableInputId="varName"></retrieve-from-variable>
<br><br><br>
<div style="padding-top: 8px;">
<div style="float: left; width: calc(50% - 12px);">
<span class="dbminputlabel">X1 Position</span><br>
<input id="x1" class="round" type="text" value="0"><br>
</div>
<div style="float: right; width: calc(50% - 12px);">
<span class="dbminputlabel">Y1 Position</span><br>
<input id="y1" class="round" type="text" value="0"><br>
</div>
</div>
<br><br><br>
<div style="padding-top: 8px;">
<div style="float: left; width: calc(50% - 12px);">
<span class="dbminputlabel">X2 Position</span><br>
<input id="x2" class="round" type="text" value="0"><br>
</div>
<div style="float: right; width: calc(50% - 12px);">
<span class="dbminputlabel">Y2 Position</span><br>
<input id="y2" class="round" type="text" value="0"><br>
</div>
</div>
<br><br><br>
<div style="padding-top: 8px; width: calc(50% - 12px)">
<span class="dbminputlabel">Line Color</span><br>
<input id="color" class="round" type="color" value="#ffffff"><br>
</div>
<br><br><br>
<div style="padding-top: 8px; width: calc(50% - 12px)">
<span class="dbminputlabel">Line Thickness (pixels)</span><br>
<input id="thickness" class="round" type="number" min="1" value="1"><br>
</div>`;
},

init() {},

action(cache) {
const data = cache.actions[cache.index];
const storage = parseInt(data.storage, 10);
const varName = this.evalMessage(data.varName, cache);
const image = this.getVariable(storage, varName, cache);
if (!image || !image.setPixelColor) {
this.callNextAction(cache);
return;
}
let x1 = parseInt(this.evalMessage(data.x1, cache), 10);
let y1 = parseInt(this.evalMessage(data.y1, cache), 10);
let x2 = parseInt(this.evalMessage(data.x2, cache), 10);
let y2 = parseInt(this.evalMessage(data.y2, cache), 10);
let color = parseInt(this.evalMessage(data.color, cache).replace('#', '0x'), 16);
let thickness = parseInt(this.evalMessage(data.thickness, cache), 10);

if (thickness < 1) {
thickness = 1;
}

const dx = Math.abs(x2 - x1);
const dy = Math.abs(y2 - y1);
const sx = (x1 < x2) ? 1 : -1;
const sy = (y1 < y2) ? 1 : -1;

if (dx === 0 && dy === 0) {
image.setPixelColor(color, x1, y1);
} else {
if (dx >= dy) {
let err = dx / 2;
for (let i = 0; i <= dx; i++) {
for (let j = -thickness / 2; j <= thickness / 2; j++) {
image.setPixelColor(color, x1, y1 + j);
}
if (err > dx) {
err -= dy;
x1 += sx;
}
err += dy;
y1 += sy;
}
} else {
let err = dy / 2;
for (let i = 0; i <= dy; i++) {
for (let j = -thickness / 2; j <= thickness / 2; j++) {
image.setPixelColor(color, x1 + j, y1);
}
if (err > dy) {
err -= dx;
y1 += sy;
}
err += dx;
x1 += sx;
}
}
}

this.callNextAction(cache);
},

mod() {}
};

0 comments on commit affd34a

Please sign in to comment.