Page 1 of 1

[Library] Quick Gradient Library

Posted: Thu Sep 25, 2014 5:25 am
by HugoBDesigner
So, I've always wanted to make some gradients, but LÖVE doesn't support it. So I made a quick library to make various different types of gradients in any shape you want (circle, rectangle, polygon, even lines!).

Update: Now this works for Löve 0.10.1, and I've updated the code so that having the gradient images is optional, not mandatory. If the gradients folder is not available, the program will now generate the images for you!

Just call require "gradient" and you're done!

How to use it:

Code: Select all

love.gradient.draw(function, mode, centerX, centerY, width, height, color1, color2[, angle, scaleX, scaleY])

Function: A drawing function (like with love stencils).

Mode: A gradient mode (linear, radial, angle, rhombus or square).

Center X: The X center of your shape.

Center Y: The Y center of your shape.

Width: The width of your shape (regardless of rotation).

Height: The height of your shape (regardless of rotation).

Color 1: The back color of your gradient.

Color 2: The front color of your gradient.

Angle: The rotation of your gradient image (default: 0).

Scale X: The scale factor for your gradient's width (default: 1, flip horizontally: -1).

Scale Y: The scale factor for your gradient's height (default: 1, flip vertically: -1).
If you have any feedback, error or feedback, please let me know.

Oh, here's an example (use the keys "WASD" to move the square, "TAB" to switch between gradients and "QE" to rotate it):
GradientExample.love
For Löve 0.10.x
(55.91 KiB) Downloaded 160 times
Aaaannd... A screenshot:
Image

(I'm open to any tips on how to improve this)

Re: [Library] Quick Gradient Library

Posted: Thu Sep 25, 2014 6:11 am
by josefnpat

Code: Select all

~♠ cd repos/love.gradient/
~/repos/love.gradient♠ unzip gradients.zip 
Archive:  gradients.zip
 

caution:  zipfile comment truncated
warning [gradients.zip]:  zipfile claims to be last disk of a multi-part archive;
  attempting to process anyway, assuming all parts have been concatenated
  together in order.  Expect "errors" and warnings...true multi-part support
  doesn't exist yet (coming soon).
error [gradients.zip]:  missing 1085502727 bytes in zipfile
  (attempting to process anyway)
error [gradients.zip]:  attempt to seek before beginning of zipfile
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

Re: [Library] Quick Gradient Library

Posted: Thu Sep 25, 2014 6:20 am
by HugoBDesigner
Oh, thanks for letting me know! It's a pity that Github couldn't support the .zip file, so I uploaded it in the main post (and removed from Github).

Re: [Library] Quick Gradient Library

Posted: Thu Sep 25, 2014 3:13 pm
by josefnpat
HugoBDesigner wrote:Oh, thanks for letting me know! It's a pity that Github couldn't support the .zip file, so I uploaded it in the main post (and removed from Github).
I'm not sure why github would not host data in a repo as is. Here's an example of it working; https://gist.github.com/josefnpat/2ef59aab6d133478dc4a

Re: [Library] Quick Gradient Library

Posted: Fri Sep 26, 2014 12:02 am
by HugoBDesigner
Huh... Then I'm probably missing something really obvious here... As I said, I'm a real noob in terms of Github :P

Re: [Library] Quick Gradient Library

Posted: Fri Sep 26, 2014 8:55 am
by shakesoda
Nice little lib! I've forked it for my own nefarious purposes, I should combine it with the gradient generator I wrote a while back for some extra features (arbitrary gradient stops)

Re: [Library] Quick Gradient Library

Posted: Mon Aug 29, 2016 4:03 pm
by HugoBDesigner
Alright, decided I should update this library. I gave up on GitHub because I'm never getting used to that.

I've updated the code to Löve 0.10.1, as well as made the gradients folder with the images optional. If you don't download the images, the program will automatically generate them for you!