Skip to content

Commit

Permalink
added override and more algs to choose from
Browse files Browse the repository at this point in the history
  • Loading branch information
1Euro7Cent committed Aug 17, 2022
1 parent 0b3ca2c commit 3c13682
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 45 deletions.
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

If you have questions suggestions or bugs, please open an issue or send me a dm per dc(mrballou#9055)

## installation video:
## installation video (click image):

[![placeholder](https://img.youtube.com/vi/3Js--QGcVpI/0.jpg)](https://youtu.be/3Js--QGcVpI)

Expand All @@ -20,26 +20,36 @@ If you have questions suggestions or bugs, please open an issue or send me a dm

## Installation

- go to releases
- download the latest release
- extract the zip file into a folder
- run the `drawbot.exe`
- close the window again
- run `initializePositions.exe` and follow the instructions (abort/save with right click)
- run `drawbot.exe` again
- run `gui.exe`
- enjoy!
- Go to releases.
- Download the latest release.
- Extract the zip file into a folder.
- Run the `drawbot.exe`.
- Close the window again.
- Run `initializePositions.exe` and follow the instructions (abort/save with right click).
- Run `drawbot.exe` again.
- Run `gui.exe`.
- Enjoy!

## Build

- clone repo
- have [c++ build tools](https://visualstudio.microsoft.com/en/) installed
- have [python 3.10+](https://www.python.org/downloads/) installed
- have [nodejs 16+](https://nodejs.org/en/) installed
- install pip requirements (`pip install -r requirements.txt`)
- install npm dependencies (`npm install`)
- to build run `npm run build`
- Clone repo.
- Have [c++ build tools](https://visualstudio.microsoft.com/en/) installed.
- Have [python 3.10+](https://www.python.org/downloads/) installed.
- Have [nodejs 16+](https://nodejs.org/en/) installed.
- Install pip requirements (`pip install -r requirements.txt`).
- Install npm dependencies (`npm install`).
- To build run `npm run build`.
- To run the main bot run `node index.js`.
- To run the gui run `python gui.py`.

## faq:
## Faq:

- If the gui instantly crashes, try running the drawbot.exe and then the gui. The drawbot.exe creates all nessesery files for the gui to work.
- The override position works like this:
- press the override button.
- Move the mouse to the top left corner where you want to override the position to.
- Click.
- Move the mouse to the bottom right corner where you want to override the position to.
- Click.
- The bot will now only draw in the new definded area.
- Reset by pressing the reset button.
13 changes: 12 additions & 1 deletion classes/DrawManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,25 @@ module.exports = class DrawManager {
}

let position = positions.getPlatform(this.settings.name)
if (settings.data.positionOverride.enabled) {
position.topleft = {
x: settings.data.positionOverride.x1,
y: settings.data.positionOverride.y1
}
position.bottomright = {
x: settings.data.positionOverride.x2,
y: settings.data.positionOverride.y2
}
}

let size = {
w: Math.round((position.bottomright.x - position.topleft.x) / this.settings.distancing),
h: Math.round((position.bottomright.y - position.topleft.y) / this.settings.distancing)
}

console.log(`resizing to ${size.w}x${size.h}`)
let resized = await this.resizer.resize(img, size)
// @ts-ignore
let resized = await this.resizer.resize(img, size, settings.data.resizeImgAlg)

await resized.writeAsync(this.config.temp + 'resized.png')

Expand Down
31 changes: 24 additions & 7 deletions classes/Resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,34 @@ module.exports = class Resizer {
* this resizes the image to NOT loose the aspect ratio and the image CANNOT be any larger then the given size on the width or height
* @param {Jimp} img
* @param {{w:number, h:number}} size
* @param {"fit" | "stretch" | "cropX" | "cropY" | "none"} alg
*/
async resize(img, size) {
async resize(img, size, alg) {
let nSize = {
w: -1,
h: -1
}
switch (alg) {
case 'fit':
nSize = resizer.resize(img.bitmap.width, img.bitmap.height, size.w, size.h, {
resizeType: "fast", // exact, fast

let nsize = resizer.resize(img.bitmap.width, img.bitmap.height, size.w, size.h, {
resizeType: "fast", // exact, fast
}) // { width: 979, height: 1080, timeTook: 6, steps: 856 }
return img.resize(nSize.width, nSize.height)
case 'stretch':
nSize = size
return img.resize(nSize.w, nSize.h)
case 'cropX':
return img.resize(Jimp.AUTO, size.h)
case 'cropY':
return img.resize(size.w, Jimp.AUTO)
case 'none':
return img
default:
throw new Error("Unknown resize algorithm: " + alg)

}) // { width: 979, height: 1080, timeTook: 6, steps: 856 }

console.log(nsize)

return img.resize(nsize.width, nsize.height)

}
}
}
4 changes: 4 additions & 0 deletions classes/config/GuiConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ module.exports = class GuiConfig extends BaseConfig {
["lineSavingMode", "onTimeDelayMode"],
["onTimeDelayText", "onTimeDelayMultiplyer"],
["sortColorsAlgorithmText", "sortColorsAlgorithm"],
["resizeImageAlgorithmText", "resizeImageAlgorithm"],
["positionImageAlgorithmText", "positionImageAlgorithm"],

["ditherAlgorithmText", "ditherAlgorithm"],
["ignoreColorText", "ignoreColor"],
["maxLinesText", "maxLines"],
["colorDelayText", "colorDelay"],
["saveConfigButton", "saveConfig"],
["loadConfigButton", "loadConfig"],
["manualOverrideButton", "manualOverrideResetButton"],
["imageUrlText", "imageUrl"],
["", "drawButton"],

Expand Down
8 changes: 7 additions & 1 deletion classes/config/Positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module.exports = class Positions extends BaseConfig {
x: 0,
y: 0
},
width: 0, // based on the two above
height: 0,
colors: {
"#000000": {
Expand Down Expand Up @@ -46,9 +48,13 @@ module.exports = class Positions extends BaseConfig {

/**
* @param {string} platform
* @returns {{topleft: {x: number, y: number}, bottomright: {x: number, y: number}, bucket:{x: number, y:number}, pen:{x:number, y:number} , colors: {hex: {x: number, y: number}}}}
* @returns {{topleft: {x: number, y: number}, bottomright: {x: number, y: number}, width:number, height:number, bucket:{x: number, y:number}, pen:{x:number, y:number} , colors: {hex: {x: number, y: number}}}}
*/
getPlatform(platform) {
let width = this.data[platform].bottomright.x - this.data[platform].topleft.x
let height = this.data[platform].bottomright.y - this.data[platform].topleft.y
this.data[platform].width = width
this.data[platform].height = height

return this.data[platform]

Expand Down
9 changes: 9 additions & 0 deletions classes/config/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ module.exports = class Setting extends BaseConfig {
colorDelay: 0,
ignoreColors: ['#ffffff'],
sortColAlg: "size 0-9",
resizeImgAlg: "fit",
positionImgAlg: "center",
bucket: false,
lineSaving: false,
onTimeDelay: false,
onTimeDelayMultiplyer: 1,
positionOverride: {
enabled: false,
x1: 0,
y1: 0,
x2: 0,
y2: 0
}
}

}
Expand Down
5 changes: 5 additions & 0 deletions classes/instructions/DrawInstruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ module.exports = class DrawInstruction {
}

async execute() {
// @ts-ignore
if ((isNaN(this.cords.x1) || isNaN(this.cords.y1) || (this.type.includes('DRAG') && (isNaN(this.cords.x2) || isNaN(this.cords.y2))))) {
console.log(this)
throw new Error(`Cords are not numbers`)
}
switch (this.type) {
case "DOT":
robot.moveMouse(this.cords.x1, this.cords.y1)
Expand Down
Loading

0 comments on commit 3c13682

Please sign in to comment.