struct ColorUtil::BakedPalette

Defined in:

colorutil/baked_palette.cr

Constant Summary

EXPLORATION_TOLERANCE = 50
ITERATIONS = 500
NEIGHBOUR_COEFFICIENT = 1_f64

Constructors

Class Method Summary

Constructor Detail

def self.new(source : SemanticPalette) #

[View source]

Class Method Detail

def self.acceptance_probability(energy, new_energy, temp) #

Returns the probability of accepting a new state given the annealing temperatue and the energy of the new state. Requires normalized energies on [0, 1]


[View source]
def self.d_contrast(fixed, wrt) : Float64 #

Returns the partial derivative of the WCAG contrast function in the variable wrt (with respect to) when the other lightness is fixed.


[View source]
def self.energy(state, rules, max_error) #

Returns the energy for a state. This is quite wishy-washy - for a random set of lightnesses, I found that almost all of them had miniscule energy compared to the maximum error possible. So, i played with tanh to try to normalize the outputs into a more uniform range. The coefficient 51 gave me a mean energy of 0.5, so that's what i stuck with.


[View source]
def self.error(lightness : Tensor(Float64), rules : Array(Array(Float))) : Float64 #

[View source]
def self.error_gradient(lightness : Tensor(Float64), rules : Array(Array(Float64))) : Tensor(Float64) #

Returns a tensor of the same size as the input storing the analytic solution for the error gradient in each variable.


[View source]
def self.max_error(rules) #

Returns an upper bound on how large the error in a system could be given a set of rules. This upper bound is not exact - it assumes that the contrast error is always the largest that it could be, which for some rule sets, may be contradictory. For example, if there are two rules between two colors, dictating that they contraast fully and not at all, this method will return an unattainable error level.


[View source]
def self.neighbour(state, temp) #

Returns a modified version of the state according to the annealing temperature.


[View source]
def self.temperature(completion) #

Returns the annealing temperature at a certain completion step in the domain [0, 1]. This function, too, returns a number in the range [0, 1].


[View source]