Fooidge / PleaseJS

JavaScript Library for creating random pleasing colors and color schemes
2.28k stars 159 forks source link

How to output results of Please.js functions #29

Closed fluxxus closed 10 years ago

fluxxus commented 10 years ago

Being a web designer, with limited JS skills, I would like to know how should I output results of Please.js functions?

For example, the elementary Please.make_color(); function, how should I get the output of it?

Sorry for this type of question :)

Mirko

Fooidge commented 10 years ago

So in JavaScript, and many other languages when you call a function they return a value to you.

Please.make_color() currently returns a color to you as a hex value string.

so

var aNiceColor = Please.make_color(); 

would store the result of make_color() is the variable aNiceColor.

But you don't always need the variable!

Here's a more complicated example:

Please.make_scheme(Please.make_color({format: 'hsv'}),{scheme_type: 'analogous'});

In here we don't store to a variable. Instead, the return value of one function is immediately consumed by the next in order to fuel it's code.

I hope this makes sense.

fluxxus commented 10 years ago

Thanks for the explanation!! I get the variables bit, although feeling a bit stupid that didn't crossed my mind.

If it is not a problem to clarify the second example in more detail, where is the result stored and how should I fetch it?

Thanks

NadyaNayme commented 10 years ago

I call the function, store it as a variable, and then write the result as the contents of a div. I assume this is what you want? http://jsfiddle.net/9588evd6/

Each time you press "Run" you'll get a new color. You can change the parameter and return amounts to change the number and type of colors you get.

It can be modified to also set the div to be a square and set the background color to the color as well if you'd like it to be a bit more visual.

fluxxus commented 10 years ago

@Kyokou Thanks, that is exactly what I needed. I think I will have something to play with tonight by setting up a test page with colored divs and changing their bg color!

Thanks