Skip to content

Instantly share code, notes, and snippets.

@atebit
Created April 24, 2024 14:00
Show Gist options
  • Select an option

  • Save atebit/843323862b8325430dae324d34b7aeec to your computer and use it in GitHub Desktop.

Select an option

Save atebit/843323862b8325430dae324d34b7aeec to your computer and use it in GitHub Desktop.
Ruby Color Contrast Algo
def export_color(flags)
unless flags & leave_value != 0 && value_element.nil?
# Implement your logic for handling value_element
end
value = to_s
value = value.upcase if caps
value = "##{value}" if hash
value_element.value = value unless value_element.nil?
unless flags & leave_style != 0 && style_element.nil?
style_element.style.background_image = "none"
style_element.style.background_color = "##{to_s}"
luminance = 0.213 * rgb[0] + 0.715 * rgb[1] + 0.072 * rgb[2]
text_color = luminance < 0.5 ? '#FFF' : '#000'
style_element.style.color = text_color
end
redraw_pad unless flags & leave_pad != 0 && is_picker_owner
redraw_sld unless flags & leave_sld != 0 && is_picker_owner
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment