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

Circular gradient #869

wants to merge 1 commit into from

Conversation

niravasher
Copy link

Fixes #[Add issue number here.]

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with npm test
  • code is in uniquely-named feature branch and has no merge conflicts
  • PR is descriptively titled
  • ask @publiclab/is-reviewers for help, in a comment below

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If 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!

@niravasher
Copy link
Author

@publiclab/is-reviewers please have a look at it

@harshkhandeparkar
Copy link
Member

@publiclab/is-reviewers

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Mar 17, 2019

@niravasher
Copy link
Author

I hope the PR got updated. Also keeping the save function for now to test something, will remove later

Copy link
Member

@harshkhandeparkar harshkhandeparkar left a 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?

@niravasher
Copy link
Author

niravasher commented Mar 18, 2019

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
Screenshot (42) @harshkhandeparkar
Yes I cleared the cache twice

Copy link
Member

@jywarren jywarren left a 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 👍 😄 📐

src/modules/CircularGradient/Module.js Outdated Show resolved Hide resolved
src/modules/CircularGradient/Module.js Outdated Show resolved Hide resolved
src/modules/CircularGradient/info.json Outdated Show resolved Hide resolved
@harshkhandeparkar
Copy link
Member

Can you commit your new code?

@niravasher
Copy link
Author

Updated my PR @harshkhandeparkar @jywarren

Copy link
Member

@harshkhandeparkar harshkhandeparkar left a 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

Copy link
Member

@jywarren jywarren left a 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);
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);

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",
Copy link
Member

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;
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;

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);
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);

"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!

callback();
});
});
function extraManipulation(pixels) {
Copy link
Member

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!

Copy link
Author

@niravasher niravasher Mar 20, 2019

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

@@ -1,6 +1,13 @@
{
"name": "Gradient",
"description": "Gives a gradient of the image",
"inputs": {},
"inputs": {
Copy link
Member

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!

Copy link
Member

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 😄

Copy link
Author

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. 😄 😄

@niravasher
Copy link
Author

Pushed all new suggested changes to this. Why am I still getting those conflicts? @harshkhandeparkar @jywarren

@jywarren jywarren mentioned this pull request Mar 21, 2019
4 tasks
@jywarren jywarren requested a review from Divy123 March 22, 2019 19:48
@Divy123
Copy link
Member

Divy123 commented Mar 22, 2019

There are conflicts due to some other PRs already merged after your last rebase.
So you can again make a rebase but lets work on the reviews by the reviewers first.

Copy link
Member

@Divy123 Divy123 left a 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'),
Copy link
Member

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) {
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 .

@@ -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) {

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));

@niravasher
Copy link
Author

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.

@Divy123
Copy link
Member

Divy123 commented Mar 25, 2019

@niravasher what can be done here is you can go one commit behind on this.
I think some wrong files have changed here due to rebase done incorrectly.
You can go behind one or two commits back when there was only your changes and I suggest there is no need to rebase until you are done with your work completely.
It should be the last step.
Please go a commit behind to that version where there were only your changes.

@Divy123
Copy link
Member

Divy123 commented Mar 25, 2019

We will see the merge conflicts once you are on the rght version.

@jywarren
Copy link
Member

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.

Copy link
Member

@jywarren jywarren left a 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')
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!

@@ -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.

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.

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

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.

Suggested change
console.log(width);

}
var increment = width/2;
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);

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.

Suggested change
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);
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);

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);
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);

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);
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);

"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.

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

@niravasher
Copy link
Author

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

@harshkhandeparkar
Copy link
Member

Wait!

@harshkhandeparkar
Copy link
Member

You don't have to retork

@harshkhandeparkar
Copy link
Member

You can run git reset --hard upstream/main to make your current branch perfectly even with upstream/main.

You can run this command on your own main branch and then create a new branch from it

@harshkhandeparkar
Copy link
Member

Another pr for the same is open.

@niravasher niravasher mentioned this pull request Jan 14, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants