diff --git a/lib/models/random_color_generator.dart b/lib/models/random_color_generator.dart index 7ef8b04..0ab42b4 100644 --- a/lib/models/random_color_generator.dart +++ b/lib/models/random_color_generator.dart @@ -23,10 +23,6 @@ final Random _random = _createRandom(); /// mixed random colors. final List _typeWeights = _initTypeWeights(); -/// A blacklist of all the codes of the basic, web & named colors, used to avoid generating true -/// colors that are already in these lists. -final Set _knownColorsBlacklist = _initKnownColorsBlacklist(); - /// Creates a secure or insecure random number generator depending on the given [secure] parameter. Random _createRandom({bool secure = true}) { Random random; @@ -54,24 +50,6 @@ List _initTypeWeights() { return typeWeights; } -/// Creates the blacklist of all the codes of the basic, web & named colors. -/// -/// This is used to avoid generating true colors that are already in these lists. -Set _initKnownColorsBlacklist() { - final Set colorCodes = {}; - for (final KnownColor color in rbcg.kBasicColors) { - colorCodes.add(color.code); - } - for (final KnownColor color in rwcg.kWebColors) { - colorCodes.add(color.code); - } - for (final KnownColor color in rncg.kNamedColors) { - colorCodes.add(color.code); - } - print('colorCodes length: ${colorCodes.length}'); - return colorCodes; -} - /// Generates a random color based on the given color type. /// /// The returned [RandomColor] has a name if it was generated from named colors, or if its color @@ -89,7 +67,7 @@ RandomColor nextRandomColor(ColorType colorType) { case ColorType.attractiveColor: return racg.nextRandomColor(_random); case ColorType.trueColor: - return rtcg.nextRandomColor(_random, blacklist: _knownColorsBlacklist); + return rtcg.nextRandomColor(_random); } } diff --git a/lib/models/random_color_generators/random_true_color_generator.dart b/lib/models/random_color_generators/random_true_color_generator.dart index 12d40d2..86f4ba8 100644 --- a/lib/models/random_color_generators/random_true_color_generator.dart +++ b/lib/models/random_color_generators/random_true_color_generator.dart @@ -13,57 +13,19 @@ import '../../utils/color_utils.dart' as color_utils; import '../color_type.dart'; import '../random_color.dart'; -int _trueColorCount = 0; - /// Generates a random true color. -RandomColor nextRandomColor(Random random, {required Set blacklist}) { - late int randomColorCode; - - _trueColorCount++; - print(_trueColorCount); - - // Generate a random true color that is not in the black list (the basic, web & named colors) - // To avoid infinite loop, let's try 1000 times, it should be more than enough because the black - // list is less than 2K colors, while the total number of true colors is 16M. - for (int i = 0; i < 1000; i++) { - // Generate a random 24-bit color code, which is a number between 0x000000 and 0xFFFFFF - randomColorCode = color_utils.withFullAlpha(random.nextInt(0xFFFFFF + 1)); - // randomColorCode = color_utils.withFullAlpha(random.nextInt(0xFF + 1)); - // randomColorCode = random.nextInt(0xFFFFFF + 1); - - // print('randomColorCode $i: $randomColorCode'); - if (i > 0) { - print( - '$randomColorCode: We tried $i times to generate a random true color that is not in the black list.'); - } - - if (!blacklist.contains(randomColorCode)) { - break; - } - } - // print(''); +RandomColor nextRandomColor(Random random) { + // Generate a random 24-bit color code, which is a number between 0x000000 and 0xFFFFFF + final int randomColorCode = random.nextInt(0xFFFFFF + 1); return RandomColor( type: ColorType.trueColor, - color: Color(randomColorCode), + color: Color(color_utils.withFullAlpha(randomColorCode)), name: null, listPosition: randomColorCode, ); } -// /// Generates a random true color. -// RandomColor nextRandomColor(Random random) { -// // Generate a random 24-bit color code, which is a number between 0x000000 and 0xFFFFFF -// final int randomColorCode = random.nextInt(0xFFFFFF + 1); - -// return RandomColor( -// type: ColorType.trueColor, -// color: Color(color_utils.withFullAlpha(randomColorCode)), -// name: null, -// listPosition: randomColorCode, -// ); -// } - /// The number of available true colors that can be used to generate the random color. /// /// This is the total number of colors can be represented in a 24-bit color palette.