[Library] Quick Gradient Library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

[Library] Quick Gradient Library

Post 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 158 times
Aaaannd... A screenshot:
Image

(I'm open to any tips on how to improve this)
Attachments
gradient.lua
Raw library
(4.48 KiB) Downloaded 201 times
gradients.zip
Gradient images
(53.71 KiB) Downloaded 157 times
Last edited by HugoBDesigner on Mon Aug 29, 2016 4:00 pm, edited 2 times in total.
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: [Library] Quick Gradient Library

Post 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)
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: [Library] Quick Gradient Library

Post 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).
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: [Library] Quick Gradient Library

Post 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
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: [Library] Quick Gradient Library

Post 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
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
shakesoda
Citizen
Posts: 78
Joined: Thu Sep 25, 2014 11:57 am
Location: Seattle, WA
Contact:

Re: [Library] Quick Gradient Library

Post 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)
excessive ❤ moé (LÖVE3D, CPML, ...). holo on IRC.
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: [Library] Quick Gradient Library

Post 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!
@HugoBDesigner - Twitter
HugoBDesigner - Blog
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest