Last active
July 10, 2021 20:41
-
-
Save meloonics/2f23ee465f0014982cc258bbefb7f8b1 to your computer and use it in GitHub Desktop.
The standalone script for my ColorPaletteGenerator for easier use inside your own projects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
var cas : float | |
var bcs : float | |
var brad : float | |
var crad : float | |
var contrastedB : bool = false | |
var contrastedC : bool = false | |
var indieB : bool = false | |
var exactSecondary : bool = true | |
func make_palette(A : Color): | |
randomizeSettings() | |
var C = getC(A) | |
var B = getB(A, C) | |
var ab = get_secondary(A, B) | |
var bc = get_secondary(B, C) | |
var ca = get_secondary(C, A) | |
return PoolColorArray([A, ab, B, bc, C, ca]) | |
func getC(A) -> Color: | |
var ch = fposmod(A.h + crad, 1.0) | |
var cs = A.s * cas | |
var cv = A.v | |
if contrastedC: | |
return Color.from_hsv(ch, cs, cv).contrasted() | |
return Color.from_hsv(ch, cs, cv) | |
func getB(A : Color, C : Color): | |
var bh | |
var bs | |
var bv | |
if indieB: | |
bh = fposmod(A.h + brad, 1.0) | |
bs = A.s * bcs | |
bv = A.v# + (A.v - cv) / 2 | |
else: | |
bh = lerp(A.h, C.h, brad) if C.h > A.h else lerp(A.h, 1.0 + C.h, brad) | |
bs = C.s * bcs | |
bv = A.v + (A.v - C.v) / 2 | |
if contrastedB: | |
return Color.from_hsv(bh, bs, bv).contrasted() | |
return Color.from_hsv(bh, bs, bv) | |
func get_secondary(c1: Color, c2 : Color): | |
if exactSecondary: | |
var c1r = Vector2(c1.s, 0).rotated(c1.h * TAU) | |
var c2r = Vector2(c2.s, 0).rotated(c2.h * TAU) | |
var secV = c1r + c1r.direction_to(c2r) * c1r.distance_to(c2r)/2 | |
var sec = Color.from_hsv(secV.angle() / TAU, secV.length(), lerp(c1.v, c2.v, 0.5)) | |
return sec | |
else: | |
return lerp(c1, c2, 0.5) | |
func randomizeSettings(): | |
cas = rand_range(0.8, 1.0) | |
bcs = rand_range(0.8, 1.0) | |
brad = rand_range(0.4, 0.8) | |
crad = rand_range(0.4, 0.8) | |
#contrastedB = randi()%3 == 0 | |
#contrastedC = randi()%3 == 0 | |
#indieB = randi()%3 == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment