Skip to content

Instantly share code, notes, and snippets.

@bricker
Created September 19, 2012 22:16
Show Gist options
  • Select an option

  • Save bricker/3752693 to your computer and use it in GitHub Desktop.

Select an option

Save bricker/3752693 to your computer and use it in GitHub Desktop.
Demo pastel colors
##
# Simple script which generates 20 "random" pastel colors and
# creates a (horrifically invalid) HTML template
# demonstrating those colors as blocks.
# Also provides the array of colors used.
#
# ruby ./pastel-blocks.rb
# open ./pastel-demo.html
#
require 'erb'
result = ERB.new(
<<-eos
<%
min_color = 128
max_offset = 100
colors = []
20.times do
nums = [0, rand(max_offset), rand(max_offset), max_offset].sort
values = nums.each_cons(2).map do |a,b|
"%02x" % (min_color+b-a)
end
colors << "#" + values.join
end
%>
<%= colors.inspect %>
<hr />
<% colors.each_with_index do |color, i| %>
<% if i % 4 == 0 %><div style="clear:both;"><% end %>
<div style="width:100px;height:100px;float: left;background-color: <%= color %>"><%= color %></div>
<% if i % 4 == 3 %></div><% end %>
<% end %>
eos
).result(binding)
File.open "./pastel_blocks.html", "w" do |f|
f.write result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment