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 #869

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions src/Modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ module.exports = {
'blend': require('./modules/Blend'),
'blur': require('./modules/Blur'),
'brightness': require('./modules/Brightness'),
'circular-gradient': require('./modules/CircularGradient'),
'channel': require('./modules/Channel'),
'colorbar': require('./modules/Colorbar'),
'colormap': require('./modules/Colormap'),
'color-temperature': require('./modules/ColorTemperature'),
'contrast': require('./modules/Contrast'),
'convolution': require('./modules/Convolution'),
'crop': require('./modules/Crop'),
Expand All @@ -36,6 +38,5 @@ module.exports = {
'saturation': require('./modules/Saturation'),
'text-overlay': require('./modules/TextOverlay'),
'threshold': require('./modules/Threshold'),
'tint': require('./modules/Tint'),
'color-temperature': require('./modules/ColorTemperature')
'tint': require('./modules/Tint')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't worry about these, i just alphabetized them!

}
41 changes: 41 additions & 0 deletions src/modules/CircularGradient/Module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = function Circular(options, UI) {

var output;

// The function which is called on every draw.
function draw(input, callback, progressObj) {
progressObj.stop(true);
progressObj.overrideFlag = true;

var step = this;

function extraManipulation(pixels) {
pixels = require('./circularGradient')(pixels, options)
return pixels

};

function output(image, datauri, mimetype) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove unused variables here .


// This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype };

}

return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
}

return {
options: options,
draw: draw,
output: output,
UI: UI
}
}
37 changes: 37 additions & 0 deletions src/modules/CircularGradient/circularGradient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = exports = function(pixels, options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its recommended not to assign a value to exports directly.
In this case you can directly do module.exports = function(...)
exports should be used only to add propoerties to it not assigning it directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module.exports = exports = function(pixels, options) {
module.exports = function(pixels, options) {


let defaults = require('./../../util/getDefaults.js')(require('./info.json'));

let fillColor = options.fillColor || defaults.fillColor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so here we can just set fillColor to white, so we can remove all the fillColor code, make sense? we only want monochrome for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let fillColor = options.fillColor || defaults.fillColor;

options.centreX = options.centreX || defaults.centreX;
options.centreY = options.centreY || defaults.centreY;

var width = pixels.shape[0];
var height = pixels.shape[1];
if(height%2 != 0) {
height = height-1;
}
if(width%2 != 0) {
width = width-1;
}
var increment = width/2;
console.log(width);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, let's take out the log statements!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(width);

console.log(height);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(height);


fillColor = fillColor.split(" ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fillColor = fillColor.split(" ")


for (var i = 0 ; i < width ; i++) {
for (var j = 0 ; j < height ; j++) {
var distX = Math.abs(options.centreX - i);
var distY = Math.abs(options.centreY - j);
var distance = Math.sqrt(Math.pow(distX, 2) + Math.pow(distY, 2));
var brightness = 255 * (distance / (2*width));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think brightness is unused here.
So this can be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var brightness = 255 * (distance / (2*width));

if (distance-1 > width) {distance = width;}
pixels.set(i, j, 0, fillColor[0]*1.5*distance/width);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right so on these three lines, we can just remove the fillcolor[.] parts, and it'll fill evenly with white.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pixels.set(i, j, 0, fillColor[0]*1.5*distance/width);
pixels.set(i, j, 0, 255 * distance / width);

pixels.set(i, j, 1, fillColor[1]*1.5*distance/width);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pixels.set(i, j, 1, fillColor[1]*1.5*distance/width);
pixels.set(i, j, 1, 255 * distance / width);

pixels.set(i, j, 2, fillColor[2]*1.5*distance/width);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pixels.set(i, j, 2, fillColor[2]*1.5*distance/width);
pixels.set(i, j, 2, 255 * distance / width);

pixels.set(i, j, 3, 255);
}
}
return pixels
}
4 changes: 4 additions & 0 deletions src/modules/CircularGradient/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = [
require('./Module'),
require('./info.json')
]
25 changes: 25 additions & 0 deletions src/modules/CircularGradient/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Circular Gradient",
"description": "Gives a circular gradient of the image",
"inputs": {
"fillColor": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And let's remove this parameter here, we'll be able to do all color work in the next module!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reminding that we should remove this whole parameter, down to line 10!

"type": "String",
"desc": "three space separated numbers representing the RGB values of fill-color",
"default": "100 100 100",
"placeholder": "100 100 100"
},
"centreX": {
"type": "integer",
"max": 210,
"desc": "X co-ordinate of centre of gradient",
"default": 305,
},
"centreY": {
"type": "integer",
"max": 210,
"desc": "Y co-ordinate of centre of gradient",
"default": 214,
}
},
"docs-link":"https://github.com/publiclab/image-sequencer/blob/main/docs/MODULES.md"
}