SORU
22 Ocak 2009, PERŞEMBE


Nasıl otomatik olarak N "farklı" renk oluşturmak için?

Otomatik olarak N farklı renkleri seçmek için aşağıdaki iki yöntemden yazdım. RGB küp parçalı doğrusal bir fonksiyon tanımlayarak çalışır. Bunun yararı da, eğer istediğin buysa ilerici bir ölçek alabilirsiniz, ama N büyük aldığında renkleri benzer görünmeye başlar. Ayrıca eşit bir kafes içine RGB küp bölüp sonra puan çizim tahmin edebiliyorum. Başka bir yöntem biliyor mu? Bir liste tanımlamak ve sonra sadece bisiklet ekarte ediyorum. Ayrıca genelde çatışma veya güzel bakma umurumda değil desem, onlar sadece görsel olarak farklı olmak zorunda.

public static List<Color> pick(int num) {
	List<Color> colors = new ArrayList<Color>();
	if (num < 2)
		return colors;
	float dx = 1.0f / (float) (num - 1);
	for (int i = 0; i < num; i  ) {
		colors.add(get(i * dx));
	}
	return colors;
}

public static Color get(float x) {
	float r = 0.0f;
	float g = 0.0f;
	float b = 1.0f;
	if (x >= 0.0f && x < 0.2f) {
		x = x / 0.2f;
		r = 0.0f;
		g = x;
		b = 1.0f;
	} else if (x >= 0.2f && x < 0.4f) {
		x = (x - 0.2f) / 0.2f;
		r = 0.0f;
		g = 1.0f;
		b = 1.0f - x;
	} else if (x >= 0.4f && x < 0.6f) {
		x = (x - 0.4f) / 0.2f;
		r = x;
		g = 1.0f;
		b = 0.0f;
	} else if (x >= 0.6f && x < 0.8f) {
		x = (x - 0.6f) / 0.2f;
		r = 1.0f;
		g = 1.0f - x;
		b = 0.0f;
	} else if (x >= 0.8f && x <= 1.0f) {
		x = (x - 0.8f) / 0.2f;
		r = 1.0f;
		g = 0.0f;
		b = x;
	}
	return new Color(r, g, b);
}

CEVAP
7 Aralık 2010, Salı


Bu sorular, tartışmalar o KADAR çok görünür

Farklı çözümler önerildi, ama hiçbiri uygun. Neyse ki,bilimkurtarmaya gelir

Keyfi N

Son 2 çoğu üniversite kütüphaneleri / vekiller ile ücretsiz olacak.

N sonlu ve nispeten küçük

Bu durumda, bir liste, bir çözüm olabilir. Bu konuda çok ilginç bir yazı serbestçe kullanılabilir:

Göz önünde bulundurulması gereken birkaç renk listesi vardır:

  • Neredeyse hiç karışmış 11 renk (önceki bölümün ilk kağıt mevcut Boynton listesi
  • Kelly 22 maksimum kontrast renkler (kağıt mevcut yukarıda)

Ben de MIT öğrencisi tarafından this Palet koştu. Son olarak, aşağıdaki bağlantılardan farklı renk sistemleri / koordinatları (makaleler bazı renkleri örneğin RGB belirtilen değildir) arasında dönüştürme yararlı olabilir:

Kelly ve Boynton listesi için, zaten RGB dönüştürme yaptım. Kod biraz C#:

public static ReadOnlyCollection<Color> KellysMaxContrastSet
{
    get { return _kellysMaxContrastSet.AsReadOnly(); }
}

private static readonly List<Color> _kellysMaxContrastSet = new List<Color>
{
    UIntToColor(0xFFFFB300), //Vivid Yellow
    UIntToColor(0xFF803E75), //Strong Purple
    UIntToColor(0xFFFF6800), //Vivid Orange
    UIntToColor(0xFFA6BDD7), //Very Light Blue
    UIntToColor(0xFFC10020), //Vivid Red
    UIntToColor(0xFFCEA262), //Grayish Yellow
    UIntToColor(0xFF817066), //Medium Gray

    //The following will not be good for people with defective color vision
    UIntToColor(0xFF007D34), //Vivid Green
    UIntToColor(0xFFF6768E), //Strong Purplish Pink
    UIntToColor(0xFF00538A), //Strong Blue
    UIntToColor(0xFFFF7A5C), //Strong Yellowish Pink
    UIntToColor(0xFF53377A), //Strong Violet
    UIntToColor(0xFFFF8E00), //Vivid Orange Yellow
    UIntToColor(0xFFB32851), //Strong Purplish Red
    UIntToColor(0xFFF4C800), //Vivid Greenish Yellow
    UIntToColor(0xFF7F180D), //Strong Reddish Brown
    UIntToColor(0xFF93AA00), //Vivid Yellowish Green
    UIntToColor(0xFF593315), //Deep Yellowish Brown
    UIntToColor(0xFFF13A13), //Vivid Reddish Orange
    UIntToColor(0xFF232C16), //Dark Olive Green
};

public static ReadOnlyCollection<Color> BoyntonOptimized
{
    get { return _boyntonOptimized.AsReadOnly(); }
}

private static readonly List<Color> _boyntonOptimized = new List<Color>
{
    Color.FromArgb(0, 0, 255),      //Blue
    Color.FromArgb(255, 0, 0),      //Red
    Color.FromArgb(0, 255, 0),      //Green
    Color.FromArgb(255, 255, 0),    //Yellow
    Color.FromArgb(255, 0, 255),    //Magenta
    Color.FromArgb(255, 128, 128),  //Pink
    Color.FromArgb(128, 128, 128),  //Gray
    Color.FromArgb(128, 0, 0),      //Brown
    Color.FromArgb(255, 128, 0),    //Orange
};

static public Color UIntToColor(uint color)
{
    var a = (byte)(color >> 24);
    var r = (byte)(color >> 16);
    var g = (byte)(color >> 8);
    var b = (byte)(color >> 0);
    return Color.FromArgb(a, r, g, b);
}

Ve burada hex ve 8-bit-başına-kanal gösterimi: RGB değerlerini

kelly_colors_hex = [
    0xFFB300, # Vivid Yellow
    0x803E75, # Strong Purple
    0xFF6800, # Vivid Orange
    0xA6BDD7, # Very Light Blue
    0xC10020, # Vivid Red
    0xCEA262, # Grayish Yellow
    0x817066, # Medium Gray

    # The following don't work well for people with defective color vision
    0x007D34, # Vivid Green
    0xF6768E, # Strong Purplish Pink
    0x00538A, # Strong Blue
    0xFF7A5C, # Strong Yellowish Pink
    0x53377A, # Strong Violet
    0xFF8E00, # Vivid Orange Yellow
    0xB32851, # Strong Purplish Red
    0xF4C800, # Vivid Greenish Yellow
    0x7F180D, # Strong Reddish Brown
    0x93AA00, # Vivid Yellowish Green
    0x593315, # Deep Yellowish Brown
    0xF13A13, # Vivid Reddish Orange
    0x232C16, # Dark Olive Green
    ]

kelly_colors = dict(vivid_yellow=(255, 179, 0),
                    strong_purple=(128, 62, 117),
                    vivid_orange=(255, 104, 0),
                    very_light_blue=(166, 189, 215),
                    vivid_red=(193, 0, 32),
                    grayish_yellow=(206, 162, 98),
                    medium_gray=(129, 112, 102),

                    # these aren't good for people with defective color vision:
                    vivid_green=(0, 125, 52),
                    strong_purplish_pink=(246, 118, 142),
                    strong_blue=(0, 83, 138),
                    strong_yellowish_pink=(255, 122, 92),
                    strong_violet=(83, 55, 122),
                    vivid_orange_yellow=(255, 142, 0),
                    strong_purplish_red=(179, 40, 81),
                    vivid_greenish_yellow=(244, 200, 0),
                    strong_reddish_brown=(127, 24, 13),
                    vivid_yellowish_green=(147, 170, 0),
                    deep_yellowish_brown=(89, 51, 21),
                    vivid_reddish_orange=(241, 58, 19),
                    dark_olive_green=(35, 44, 22))

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Marina and The Diamonds

    Marina and T

    8 Temmuz 2008
  • PamtheBlamofficial

    PamtheBlamof

    31 Aralık 2010
  • Skittles Page

    Skittles Pag

    28 Mart 2011