-
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
Conversation
@publiclab/is-reviewers please have a look at it |
@publiclab/is-reviewers |
The best example for a module is drawRectangle https://github.com/publiclab/image-sequencer/blob/main/src/modules/DrawRectangle/module.js https://github.com/publiclab/image-sequencer/blob/main/src/modules/DrawRectangle/DrawRectangle.js |
I hope the PR got updated. Also keeping the save function for now to test something, will remove later |
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.
Can you provide an image for the output. Also have you cleared the cache?
The putput is a weird looking gradient in the top-left quadrant. If I include the top-left quadrant, it just overlaps the top left quadrant with a linear gradient |
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.
Hi @niravasher!! Try these suggestions, then use the monochrome output and add the colormap
module. You'll see how the monochrome will map to various color maps in the next step!
Great work, this is almost there! Love the trigonometry 👍 😄 📐
Can you commit your new code? |
Updated my PR @harshkhandeparkar @jywarren |
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.
Please do a rebase
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.
OK, went though and left some requests and tips, thank you @niravasher this is great work!
width = width-1; | ||
} | ||
var increment = width/2; | ||
console.log(width); |
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.
Oops, let's take out the log statements!
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.
console.log(width); |
package.json
Outdated
@@ -36,6 +36,7 @@ | |||
"image-sequencer-invert": "^1.0.0", | |||
"imagejs": "0.0.9", | |||
"imgareaselect": "git://github.com/jywarren/imgareaselect.git#v1.0.0-rc.2", | |||
"infinite-gradients": "0.0.1", |
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.
Are you using this? if not, let's take it back out, thanks!
|
||
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 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.
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.
let fillColor = options.fillColor || defaults.fillColor; |
var distance = Math.sqrt(Math.pow(distX, 2) + Math.pow(distY, 2)); | ||
var brightness = 255 * (distance / (2*width)); | ||
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 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.
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.
pixels.set(i, j, 0, fillColor[0]*1.5*distance/width); | |
pixels.set(i, j, 0, 255 * distance / width); |
"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 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!
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.
Just reminding that we should remove this whole parameter, down to line 10!
src/modules/Gradient/Module.js
Outdated
callback(); | ||
}); | ||
}); | ||
function extraManipulation(pixels) { |
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.
Uh oh, would you mind leaving the existing Gradient module as it is for the time being? We can work on it in a follow-up step, so lets keep this PR simpler. Thanks!
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.
Removed the changes. I added the feature for choosing the direction of gradient. Will update this in next PR
src/modules/Gradient/info.json
Outdated
@@ -1,6 +1,13 @@ | |||
{ | |||
"name": "Gradient", | |||
"description": "Gives a gradient of the image", | |||
"inputs": {}, | |||
"inputs": { |
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.
Oh i see! OK, well, we can leave this in if you like, but perhaps in the future it's best to do only one concrete thing in each PR, so we have less to review and it's more self-contained. Make sense? Thank you!
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.
This is a cool addition to this module though 😄
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.
Hehe, this is funny. Will take care for such kind of changes from the next time. 😄 😄
Pushed all new suggested changes to this. Why am I still getting those conflicts? @harshkhandeparkar @jywarren |
There are conflicts due to some other PRs already merged after your last rebase. |
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.
Please look into the suggested changes.
Awesome job !! 😄
src/Modules.js
Outdated
@@ -8,6 +8,7 @@ module.exports = { | |||
'blur': require('./modules/Blur'), | |||
'brightness': require('./modules/Brightness'), | |||
'channel': require('./modules/Channel'), | |||
'circularGradient': require('./modules/circularGradient'), |
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.
It should be ./modules/CircularGradient inside require here.
|
||
}; | ||
|
||
function output(image, datauri, mimetype) { |
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.
We can remove unused variables here .
@@ -0,0 +1,37 @@ | |||
module.exports = exports = function(pixels, options) { |
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.
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.
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.
module.exports = exports = function(pixels, options) { | |
module.exports = function(pixels, options) { |
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 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.
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.
var brightness = 255 * (distance / (2*width)); |
Ill make all the changes suggested by you @Divy123 , I am just not able to get rid of these merge conflicts. I am making unwanted commits. |
@niravasher what can be done here is you can go one commit behind on this. |
We will see the merge conflicts once you are on the rght version. |
Hi! I spent some time to extract /only/ the circular gradient work from here, and make just one commit. @niravasher it may be helpful to read through some guides on Git workflow -- it can get pretty complex, but it's worth it and I know you'll be an expert in no time 😄 👍 http://publiclab.org/developers#Resources has some good links, and https://dev.to has lots of nice guides too! I'll make some suggestions now in the simplified commit. |
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.
Hi @niravasher I went through and made suggestions for every change necessary, and then the removal of the fillColor
parameter in info.json
. If you can make these changes and upload one last screenshot, we should be able to merge this PR! Thank you so much!!!
@@ -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') |
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!
@@ -0,0 +1,37 @@ | |||
module.exports = exports = function(pixels, options) { |
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.
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; |
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.
let fillColor = options.fillColor || defaults.fillColor; |
width = width-1; | ||
} | ||
var increment = width/2; | ||
console.log(width); |
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.
console.log(width); |
} | ||
var increment = width/2; | ||
console.log(width); | ||
console.log(height); |
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.
console.log(height); |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
var brightness = 255 * (distance / (2*width)); |
var distance = Math.sqrt(Math.pow(distX, 2) + Math.pow(distY, 2)); | ||
var brightness = 255 * (distance / (2*width)); | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
pixels.set(i, j, 0, fillColor[0]*1.5*distance/width); | |
pixels.set(i, j, 0, 255 * distance / width); |
var brightness = 255 * (distance / (2*width)); | ||
if (distance-1 > width) {distance = width;} | ||
pixels.set(i, j, 0, fillColor[0]*1.5*distance/width); | ||
pixels.set(i, j, 1, fillColor[1]*1.5*distance/width); |
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.
pixels.set(i, j, 1, fillColor[1]*1.5*distance/width); | |
pixels.set(i, j, 1, 255 * distance / width); |
if (distance-1 > width) {distance = width;} | ||
pixels.set(i, j, 0, fillColor[0]*1.5*distance/width); | ||
pixels.set(i, j, 1, fillColor[1]*1.5*distance/width); | ||
pixels.set(i, j, 2, fillColor[2]*1.5*distance/width); |
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.
pixels.set(i, j, 2, fillColor[2]*1.5*distance/width); | |
pixels.set(i, j, 2, 255 * distance / width); |
"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 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!
I am deleting this repository and forking once again, will make a new pull request @jywarren New PR will have all the changes suggested by you |
Wait! |
You don't have to retork |
You can run You can run this command on your own main branch and then create a new branch from it |
Another pr for the same is open. |
Fixes #[Add issue number here.]
Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
npm test
@publiclab/is-reviewers
for help, in a comment belowIf tests do fail, click on the red
X
to learn why by reading the logs.Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software
Thanks!