mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-11 19:00:00 +01:00
circular gradient module (#1496)
* circular gradient module * circular gradient option inside gradient module * Added test for gradient module * final shadow module with module test Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
This commit is contained in:
committed by
Jeffrey Warren
parent
8c4c607f2c
commit
9260bc2278
@@ -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.
|
||||
@@ -15,6 +18,7 @@ module.exports = function Gradient(options, UI) {
|
||||
|
||||
function extraManipulation(pixels) {
|
||||
const [w, h] = pixels.shape;
|
||||
if (options.gradientType === 'linear') {
|
||||
for (var i = 0; i < w; i++) {
|
||||
for (var j = 0; j < h; j++) {
|
||||
let val = (i / w) * 255;
|
||||
@@ -22,6 +26,18 @@ module.exports = function Gradient(options, UI) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
@@ -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
test/core/images/flower.js
Normal file
1
test/core/images/flower.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user