RGB Gradation Chart Generator


/ Published in: Python
Save to your folder(s)

[from the author's website]
I wrote this to better understand the relationship between RGB colors. Running it will generate a fairly large HTML file with all sorts of color transitions on it so you can see what is happening as colors are tweaked in different ways.


Copy this code and paste it in your HTML
  1. import string
  2.  
  3. colors = ("00", "33", "66", "99", "CC", "FF")
  4. masks = ("#00~00", "#~~00", "#~0000", "#~00~", "#0000~", "#00~~", "#FF~00", "#~~~")
  5.  
  6.  
  7. f = open("colortest-gradation.html", 'w')
  8. f.write("<html><head><title>RGB Gradation</title></head><body bgcolor='black'><tt><b>")
  9.  
  10. f.write("<p><font color='white'>Gentle gradations through RGB color:</font></p>\n")
  11.  
  12. bytes = ("00", "11", "22", "33", "44", "55", "66", "77", "88", "99", "AA", "BB", "CC", "DD", "EE", "FF")
  13. halfbytes = ("00", "00", "11", "11", "22", "22", "33", "33", "44", "44", "55", "55", "66", "66", "77", "77")
  14.  
  15. for green in bytes:
  16. f.write( "<li>" )
  17. for white in bytes:
  18. c1 = "#" + white + green + white
  19. c2 = "#" + white + white + green
  20. c3 = "#" + green + white + white
  21.  
  22. f.write( "<font color='" + c1 + "'>" )
  23. f.write( "T")
  24. f.write( "</font>")
  25.  
  26. for white in bytes:
  27. c1 = "#" + white + green + white
  28. c2 = "#" + white + white + green
  29. c3 = "#" + green + white + white
  30.  
  31. f.write( "<font color='" + c2 + "'>" )
  32. f.write( "T")
  33. f.write( "</font>")
  34.  
  35. for white in bytes:
  36. c1 = "#" + white + green + white
  37. c2 = "#" + white + white + green
  38. c3 = "#" + green + white + white
  39.  
  40.  
  41.  
  42. f.write( "<font color='" + c3 + "'>" )
  43. f.write( "T")
  44. f.write( "</font>")
  45.  
  46. f.write( "</li>\n" )
  47.  
  48. f.write("<p><font color='white'>Double all bytes to get real color (#0A0 --> #00AA00 etc)</font></p>\n")
  49.  
  50. f.write("<p><font color='white'>Green varied alone, Red/Blue varied together:</font></p>\n")
  51. for green in bytes:
  52. f.write( "<li>" )
  53. for white in bytes:
  54. c1 = "#" + white + green + white
  55. c2 = "#" + white + white + green
  56. c3 = "#" + green + white + white
  57.  
  58. cout = "#" + c1[1] + c1[3] + c1[5] + " "
  59.  
  60. f.write( "<font color='" + c1 + "'>" )
  61. f.write( cout)
  62. f.write( "</font>")
  63.  
  64. f.write( "</li>\n" )
  65.  
  66. f.write("<p><font color='white'>Blue varied alone, Red/Green varied together:</font></p>\n")
  67. for green in bytes:
  68.  
  69. f.write( "<li>" )
  70. for white in bytes:
  71. c1 = "#" + white + green + white
  72. c2 = "#" + white + white + green
  73. c3 = "#" + green + white + white
  74.  
  75. cout = "#" + c2[1] + c2[3] + c2[5] + " "
  76.  
  77. f.write( "<font color='" + c2 + "'>" )
  78. f.write( cout)
  79. f.write( "</font>")
  80.  
  81. f.write( "</li>\n" )
  82.  
  83. f.write("<p><font color='white'>Red varied alone, Green/Blue varied together:</font></p>\n")
  84. for green in bytes:
  85. f.write( "<li>" )
  86. for white in bytes:
  87. c1 = "#" + white + green + white
  88. c2 = "#" + white + white + green
  89. c3 = "#" + green + white + white
  90.  
  91. cout = "#" + c3[1] + c3[3] + c3[5] + " "
  92.  
  93. f.write( "<font color='" + c3 + "'>" )
  94. f.write( cout)
  95. f.write( "</font>")
  96.  
  97.  
  98.  
  99.  
  100. f.write( "</li>\n" )
  101.  
  102. for red in bytes:
  103. f.write("<p><font color='white'>Red locked at " + red + ", other colors varied:</font></p>\n")
  104. for green in halfbytes:
  105. f.write( "<li>\n")
  106. for blue in halfbytes:
  107. c3 = "#" + red + green + "00"
  108.  
  109. cout = "#" + c3[1] + c3[3] + c3[5] + " "
  110.  
  111. f.write( "<font color='" + c3 + "'>" )
  112. f.write( cout)
  113. f.write( "</font>")
  114.  
  115.  
  116.  
  117.  
  118. f.write( "</li>\n" )
  119.  
  120.  
  121. for green in bytes:
  122. f.write("<p><font color='white'>Green locked at " + green + ", other colors varied:</font></p>\n")
  123. for red in bytes:
  124. f.write( "<li>\n")
  125. for blue in bytes:
  126. c3 = "#" + red + green + blue
  127.  
  128. cout = "#" + c3[1] + c3[3] + c3[5] + " "
  129.  
  130. f.write( "<font color='" + c3 + "'>" )
  131. f.write( cout)
  132. f.write( "</font>")
  133.  
  134.  
  135.  
  136.  
  137. f.write( "</li>\n" )
  138.  
  139. for blue in bytes:
  140. f.write("<p><font color='white'>Blue locked at " + blue + ", other colors varied:</font></p>\n")
  141. for green in bytes:
  142. f.write( "<li>\n")
  143. for red in bytes:
  144. c3 = "#" + red + green + blue
  145.  
  146. cout = "#" + c3[1] + c3[3] + c3[5] + " "
  147.  
  148. f.write( "<font color='" + c3 + "'>" )
  149. f.write( cout)
  150. f.write( "</font>")
  151.  
  152.  
  153.  
  154.  
  155. f.write( "</li>\n" )
  156.  
  157.  
  158. f.write("</b></tt></body></html>")
  159. f.close()

URL: http://www.elifulkerson.com/projects/colortest-gradation.php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.