-
Notifications
You must be signed in to change notification settings - Fork 209
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
Circular gradient #869
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||||
module.exports = exports = function(pixels, options) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its recommended not to assign a value to exports directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
let defaults = require('./../../util/getDefaults.js')(require('./info.json')); | ||||||
|
||||||
let fillColor = options.fillColor || defaults.fillColor; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK so here we can just set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, let's take out the log statements! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
console.log(height); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
fillColor = fillColor.split(" ") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
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)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think brightness is unused here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (distance-1 > width) {distance = width;} | ||||||
pixels.set(i, j, 0, fillColor[0]*1.5*distance/width); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right so on these three lines, we can just remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
pixels.set(i, j, 3, 255); | ||||||
} | ||||||
} | ||||||
return pixels | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = [ | ||
require('./Module'), | ||
require('./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": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
} |
There was a problem hiding this comment.
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!