Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/jacastanon01/color-picker

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/jacastanon01/color-picker

  • v0.0.0-20240902185252-eef6a2c196a6
  • Source
  • Go
  • Socket score

Version published
Created
Source

Go Color Picker

Screenshot 2024-08-28 at 8 34 08 AM

Overview

This is an exploration of how pixels store color. My goal with this project is to learn more about differents way to generate data that can be used for colors. I used raylib to create a simple color spectrum where you can pick a color and see the resulting value of the pixel in RGB format.

Understanding color and its measurement

Color is a visual perception created by the interaction of light with our eyes. Light consists of electromagnetic waves, and when it strikes an object, certain wavelengths are absorbed while others are reflected. Our eyes perceive these reflected wavelengths as color. In digital systems, color is often represented using the RGB (Red, Green, Blue) model, which combines these three primary colors of light at varying intensities to create a spectrum of colors. Alternatively, the HSL (Hue, Saturation, Lightness) model measures color differently by defining its hue (the type of color), saturation (the intensity of the color), and lightness (the brightness of the color). When creating a color palette with only two pigments, the resulting spectrum is limited, often focusing on gradients between the two, producing a harmonious and visually cohesive range of colors. I generated the HSL values based on pixel position and then converted that data into an RGB format:

func GenerateSpectrum(w, h int32) *rl.Image {
	const min, max float32 = 0.5, 1.0
	image := rl.GenImageColor(int(w), int(h), rl.Blank)

	for y := int32(0); y < h; y++ {
		for x := int32(0); x < w; x++ {
			var hue float32 = scaleValue((float32(x) / float32(w)), 360, 0)
			var saturation float32 = 1 // default to full saturation
			var brightness float32 = scaleValue(float32(y)/float32(h), max, min)

			imageRGB := rl.ColorFromHSV(hue, saturation, brightness)
			rl.ImageDrawPixel(
				image, x, y, imageRGB,
			)
		}
	}
	return image
}

Made with

  • Go's standard library
  • Raylib
  • ❤️ and 🧐

How to run

  • Install Go
  • Clone this repo git clone https://github.com/jacastanon01/color-picker.git
  • Navigate to the cloned directory. If using VSCode, use the build options to launch the program or run go run cmd/colorpicker/main.go at the root

FAQs

Package last updated on 02 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc