mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 11:50:02 +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,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user