Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #4

Open
wants to merge 1 commit into
base: 0.0.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions box/IconMake/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
18/12/07

0.0.2
- 将非安装包格式转移至安装包格式,尝试重构ui和代码
- 字符本地化,函数改善。(修改compare函数以准备未来从input或slider输入颜色)

* 将非安装包格式转移至安装包格式,尝试重构ui和代码
* 字符本地化,函数改善。(修改compare函数以准备未来从input或slider输入颜色)
* //$ui.alert($file.list("shared://../Icons"))

0.0.3
- 本地化字符

* 本地化字符

0.0.4

* 分离常量
154 changes: 1 addition & 153 deletions box/IconMake/main.js
Original file line number Diff line number Diff line change
@@ -1,157 +1,5 @@
//$ui.alert($file.list("shared://../Icons"))
let image
const
sideLength = Math.ceil(72.0 / $device.info.screen.scale),
view = {
type: "view",
props: {
id: "viewMain"
},
layout: function (make, view) {
make.center.equalTo(view.super)
make.size.equalTo($size(sideLength, sideLength))
}
},
getSnapshot = function () {
return $("viewMain").snapshot;
},
compare = function (imageT, colorC) {
let
colorCComponents = colorC.components,
red = colorCComponents.red,
green = colorCComponents.green,
blue = colorCComponents.blue,
sum = red + green + blue;
return function (w, h) {
let color = imageT.colorAtPixel($point(w, h)),
components = color.components,
r = components.red,
g = components.green,
b = components.blue,
sumT = r + g + b;
if (sumT > sum) {
return true
} else {
return false
}
}
},
compareAvg = function (imageT) {
return compare(imageT, imageT.averageColor);
},
buttonSave = {
type: "button",
props: {
title: $l10n("save")
},
layout: function (make, view) {
make.centerX.equalTo(view.super).multipliedBy(1.4)
make.centerY.equalTo(view.super).multipliedBy(1.5)
make.width.equalTo(view.super).multipliedBy(0.15)
},
events: {
tapped: function () {
let data = $("canvasView").snapshot.resized($size(72, 72)).png,
path = "shared://iconMake/"
if ($file.isDirectory(path)) {

} else {
$file.mkdir(path)
}
var success = $file.write({
data: data,
path: path + "icon.png"
})
if (success) {
$ui.alert({
title: "",
message: "存储成功,地址:\n" + path + "icon.png",
});
} else {
$ui.alert({
title: "",
message: "存储失败",
});
}
//$quicklook.open({ image: $("canvasView").snapshot });
}
}
},
buttonSelect = {
type: "button",
props: {
title: $l10n("select")
},
layout: function (make, view) {
make.centerX.equalTo(view.super).multipliedBy(0.6)
make.centerY.equalTo(view.super).multipliedBy(1.5)
make.width.equalTo(view.super).multipliedBy(0.15)
},
events: {
tapped: function () {
if ($("canvasView")) {
$("canvasView").remove()
}

let viewMain = $("viewMain")
$photo.pick().then(function (resp) {
if (resp.image) {
image = resp.image;
viewMain.add({
type: "canvas",
props: {
id: "canvasView"
},
layout: $layout.fill,
events: {
draw: function (view, ctx) {
ctx.drawImage(view.frame, image)
}
}
})
image = getSnapshot()
$("canvasView").remove()
viewMain.add({
type: "canvas",
props: {
id: "canvasView"
},
layout: $layout.fill,
events: {
draw: function (view, ctx) {
let gray = $color("gray"),
clear = $color("clear")
let compareWH = compareAvg(image)
for (let w = 0; w < sideLength; w++) {
for (let h = 0; h < sideLength; h++) {
if (compareWH(w, h)) {
ctx.fillColor = gray;
} else {
ctx.fillColor = clear;
}
ctx.fillRect($rect(w, h, 1, 1))
}
}
}
}
})
$quicklook.open({ image: getSnapshot() });
} else {
$ui.alert({
title: "提醒",
message: "你没有选择图片",
});
$app.close();
}
});
}
}
},
mainViews = [
view,
buttonSave,
buttonSelect
],
mainViews = require("./scripts/const.js"),
ui = {
type: "view",
props: {
Expand Down
18 changes: 18 additions & 0 deletions box/IconMake/scripts/UI/mainViews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const
sideLength = require("scripts/const/sideLength.js"),
view = {
type: "view",
props: {
id: "viewMain"
},
layout: function (make, view) {
make.center.equalTo(view.super)
make.size.equalTo($size(sideLength, sideLength))
}
},
mainViews = [
view,
buttonSave,
buttonSelect
]
module.exports = mainViews
200 changes: 200 additions & 0 deletions box/IconMake/scripts/const.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
let image
const
viewLayout = require("./layouts/viewLayout.js"),
view = {
type: "view",
props: {
id: "viewMain"
},
layout: viewLayout
}
const
sideLength = require("scripts/const/sideLength.js"),
getSnapshot = (id) => {
return $(id).snapshot;
},
sumId = (color) => {
let components = color.components,
r = components.red,
g = components.green,
b = components.blue,
sum = r + g + b;
return sum;
},
maxId = (color) => {
let components = color.components,
r = components.red,
g = components.green,
b = components.blue,
max = Math.max(r, g, b);
return max;
},
avgId = (color) => {
let components = color.components,
r = components.red,
g = components.green,
b = components.blue,
sum = r + g + b,
avg = sum / 3;
return avg;
},
minId = (color) => {
let components = color.components,
r = components.red,
g = components.green,
b = components.blue,
min = Math.min(r, g, b);
return min;
},
grayId = (color) => {
let components = color.components,
r = components.red,
g = components.green,
b = components.blue,
gray = (r * 0.299 + g * 0.587 + b * 0.114)
return gray;
},
saturationId = (color) => {
let components = color.components,
r = components.red,
g = components.green,
b = components.blue,
max = Math.max(r, g, b),
min = Math.min(r, g, b);
return max ? (1 - min / max) : max;
},
compareByFunc = (idFunc) => {
return (imageT, colorC) => {
let
id = idFunc(colorC);
return function (w, h) {
let color = imageT.colorAtPixel($point(w, h)),
idT = idFunc(color)
if (idT > id) {
return true
} else {
return false
}
}
}
},
compareAvgBySum = function (imageT) {
return compareByFunc(sumId)(imageT, imageT.averageColor);
},
compareAvgByMax = function (imageT) {
return compareByFunc(maxId)(imageT, imageT.averageColor);
},
buttonSave = {
type: "button",
props: {
title: $l10n("save")
},
layout: function (make, view) {
make.centerX.equalTo(view.super).multipliedBy(1.4)
make.centerY.equalTo(view.super).multipliedBy(1.5)
make.width.equalTo(view.super).multipliedBy(0.15)
},
events: {
tapped: function () {
let data = $("canvasView").snapshot.resized($size(72, 72)).png,
path = "shared://iconMake/"
if ($file.isDirectory(path)) {

} else {
$file.mkdir(path)
}
var success = $file.write({
data: data,
path: path + "icon.png"
})
if (success) {
$ui.alert({
title: "",
message: "存储成功,地址:\n" + path + "icon.png",
});
} else {
$ui.alert({
title: "",
message: "存储失败",
});
}
//$quicklook.open({ image: $("canvasView").snapshot });
}
}
},
buttonSelect = {
type: "button",
props: {
title: $l10n("select")
},
layout: function (make, view) {
make.centerX.equalTo(view.super).multipliedBy(0.6)
make.centerY.equalTo(view.super).multipliedBy(1.5)
make.width.equalTo(view.super).multipliedBy(0.15)
},
events: {
tapped: function () {
if ($("canvasView")) {
$("canvasView").remove()
}

let viewMain = $("viewMain")
$photo.pick().then(function (resp) {
if (resp.image) {
image = resp.image;
viewMain.add({
type: "canvas",
props: {
id: "canvasView"
},
layout: $layout.fill,
events: {
draw: function (view, ctx) {
ctx.drawImage(view.frame, image)
}
}
})
image = getSnapshot("viewMain")
$("canvasView").remove()
viewMain.add({
type: "canvas",
props: {
id: "canvasView"
},
layout: $layout.fill,
events: {
draw: function (view, ctx) {
let gray = $color("gray"),
clear = $color("clear")
let compareWH = compareAvgBySum(image)
for (let w = 0; w < sideLength; w++) {
for (let h = 0; h < sideLength; h++) {
if (compareWH(w, h)) {
ctx.fillColor = gray;
} else {
ctx.fillColor = clear;
}
ctx.fillRect($rect(w, h, 1, 1))
}
}
}
}
})
$quicklook.open({ image: getSnapshot("viewMain") });
} else {
$ui.alert({
title: "提醒",
message: "你没有选择图片",
});
$app.close();
}
});
}
}
},
mainViews = [
view,
buttonSave,
buttonSelect
]
module.exports = mainViews
Loading