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

circular gradient module #1496

Merged
merged 6 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
26 changes: 21 additions & 5 deletions src/modules/Gradient/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const pixelSetter = require('../../util/pixelSetter.js'),

module.exports = function Gradient(options, UI) {

var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.gradientType = options.gradientType || defaults.gradientType;

var output;

// The function which is called on every draw.
Expand All @@ -15,11 +18,24 @@ module.exports = function Gradient(options, UI) {

function extraManipulation(pixels) {
const [w, h] = pixels.shape;
for (var i = 0; i < w; i++) {
for (var j = 0; j < h; j++) {
let val = (i / w) * 255;

pixelSetter(i, j, [val, val, val, 255], pixels);
if (options.gradientType === 'linear') {
for (var i = 0; i < w; i++) {
for (var j = 0; j < h; j++) {
let val = (i / w) * 255;

pixelSetter(i, j, [val, val, val, 255], pixels);
}
}
}
else {
for (var i = 0; i < w; i++) {
for (var j = 0; j < h; j++) {
var distX = Math.abs(w / 2 - i);
var distY = Math.abs(h / 2 - j);
var distance = Math.sqrt(Math.pow(distX, 2) + Math.pow(distY, 2));
val = 255 * (distance / pixels.shape[0]);
pixelSetter(i, j, [val, val, val, 255], pixels);
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/modules/Gradient/info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"name": "gradient",
"description": "Gives a gradient of the image",
"inputs": {},
"inputs": {
"gradientType": {
"type": "select",
"desc": "Choose between linear or circular gradient",
"default": "linear",
"values": ["linear", "circular"]
}
},
"docs-link":"https://github.com/publiclab/image-sequencer/blob/main/docs/MODULES.md#gradient-module"
}
1 change: 1 addition & 0 deletions test/core/images/flower.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions test/core/modules/gradient.js

Large diffs are not rendered by default.