colorizertrontastic.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /* allow different things to have a distinct personality while conforming
  3. * to a common set of rules
  4. *
  5. * a problem that is encountered is that adding rules will need to erode the
  6. * distinctiveness of the personality, often so much so that the personality
  7. * is gone
  8. *
  9. * to further complicate things, color while infinite in spectrum, only gives
  10. * limited range when used to provide uniqueness, for example one might
  11. * consider red and slightly different red the same color
  12. *
  13. * we have several things that need to be tracked:
  14. * 1. radon pCi/L
  15. * 2. temperature
  16. * 3. humidity
  17. * 4. pressure
  18. * 5. air qualaity
  19. *
  20. * in a home with ten sensors it is feasible that there be ten to fifty things
  21. * to keep track of. therefore the total number of things needing tracking
  22. * is variable.
  23. *
  24. * fitting more things into an enclosed space is obviously the job of a
  25. * computer program, maintaining distinctiveness evenly, or even with a bias
  26. * may also be the job of a computer program
  27. *
  28. * an difficult to explain rule is that colors must converge, they still
  29. * will need to be different, but if one picks starting colors, then it makes
  30. * sense to say that as colors are generated based on the starting colors one
  31. * would not want them to diverge, therefore, they must converge
  32. *
  33. * for this example, I want the color to converge on red, but since I do not
  34. * want everyone to be red, colors will instead converge into colors strictly
  35. * between yellow and red, this limits starting colors somewhat more, but
  36. * whatever
  37. *
  38. * yellow is made when blue is removed from white
  39. *
  40. */
  41. require_once("test-pattern.php");
  42. // rule #1: each sensor is assigned a unique color
  43. $LIST_OF_SENSORS = array(
  44. "cheese",
  45. "chicken",
  46. "beef",
  47. "doornail",
  48. "toothrack"
  49. );
  50. // rule #2: sensor unique colors cannot contain quantities of reserved colors
  51. $RESERVED_COLORS = array(
  52. "red" => 127,
  53. "blue" => 0,
  54. "green" => 0
  55. );
  56. // rule #3: tracked things have an importance, lower is more important
  57. $LIST_OF_DATATYPES = array(
  58. "radon",
  59. "humidity",
  60. "pressure",
  61. "dust",
  62. "temperature"
  63. );
  64. $sensorCount = count($LIST_OF_SENSORS);
  65. $datatypeCount = count($LIST_OF_DATATYPES);
  66. header("Content-Type: application: xhtml+xml");
  67. $test = new Paint();
  68. // light gray for mixing (gray would be 0x808080)
  69. $lightGray = new Pixel(0xD3, 0xD3, 0xD3);
  70. // generate an gradient between red and yellow, use flags to make colors more distinct
  71. $redToYellow = Pixel::generatePixelLine(
  72. new Pixel(/* red */ 255,0,0),
  73. new Pixel(/* yellow */ 255,255,0),
  74. array(/* options */
  75. "total" => $sensorCount,
  76. "flags" => PIXEL_ALTERNATE | PIXEL_ADD | PIXEL_BLUE,
  77. "bias" => 0.35
  78. )
  79. );
  80. $justGreen = new Pixel(/* green */ 0,255,0);
  81. $someGreenThatILike = Pixel::mix($justGreen, new Pixel(/* blue */ 0,32,192));
  82. // generate starting colors, I like green, use flags to make colors really distinct
  83. $blueToGreen = Pixel::generatePixelLine(
  84. $someGreenThatILike,
  85. $justGreen,
  86. array(/* options */
  87. "total" => $sensorCount,
  88. "flags" => PIXEL_ALTERNATE | PIXEL_ADD | PIXEL_BLUE,
  89. "bias" => 0.5
  90. )
  91. );
  92. $radius = 20;
  93. $cursor = new Coord(0,0);
  94. // generate palette based on starting options
  95. for($i=$sensorCount;$i--;) {
  96. // save the cursor's vertical position (technically we know it is zero, but whatever)
  97. $vertical = $cursor->y;
  98. // mix the starting and ending color in equal parts
  99. $mixture = Pixel::mix($blueToGreen[$i], $redToYellow[$i]);
  100. // mix this color with light gray with a 1:2 ratio
  101. $mixture = Pixel::mix($mixture, $lightGray, 1/3, 2/3);
  102. // for fun, make mixture fade into background
  103. $mixture->setAlpha(0.3);
  104. // but then have it fade back in, cool and fun!
  105. $redToYellow[$i]->setAlpha(0.65);
  106. // generate the first half of colors from start to this mixture, increase fade
  107. $startToMixture = Pixel::generatePixelLine(
  108. $blueToGreen[$i],
  109. $mixture,
  110. array(/* options */
  111. "total" => (int) round($sensorCount / 2, 0, PHP_ROUND_HALF_UP),
  112. "flags" => PIXEL_SUB | PIXEL_ALPHA,
  113. "bias" => /* increase rate of fade towards mixture */ 0.25
  114. )
  115. );
  116. // generate the second half of colors from this mixture to end
  117. $mixtureToEnd = Pixel::generatePixelLine(
  118. $mixture,
  119. $redToYellow[$i],
  120. array(/* options */
  121. "total" => (int) 1 + round($sensorCount / 2, 0, PHP_ROUND_HALF_DOWN)
  122. )
  123. );
  124. // last pixel in the first half is same as the first in second, remove it
  125. array_pop($startToMixture);
  126. // draw all the pretty colors for this sensor
  127. $mixed = array_merge($startToMixture, $mixtureToEnd);
  128. foreach($mixed as $pixel) {
  129. $test->addCircle(new Coord($cursor->x, $cursor->y), $pixel, $radius);
  130. // move the cursor down
  131. $cursor->y += ($radius * 2);
  132. }
  133. // move the cursor to the right
  134. $cursor->x += ($radius * 2);
  135. // restore the cursor's vertical position
  136. $cursor->y = $vertical;
  137. }
  138. echo $test;