Skip to content

Instantly share code, notes, and snippets.

@JoeWoodward
Created October 26, 2011 19:40
Show Gist options
  • Save JoeWoodward/1317554 to your computer and use it in GitHub Desktop.
Save JoeWoodward/1317554 to your computer and use it in GitHub Desktop.
def tag_percentage
total_tags = 0.0
Article.all_tag_counts.each do |tag|
total_tags += tag.count
end
return tag_percent = (count / total_tags * 100).ceil
end
def tag_popularity_as_hex(count)
#most saturated colour possible, used for a highly used tag
max_colour[] = [255.0, 0.0, 0.0]
# least saturated colour possible, used for tags that are rarely used
min_colour[] = [0.0, 255.0, 255.0]
tag_percent = tag_percentage
for i in 0..2
range[i] = min[i] - max[i]
one_percent_of_range[i] = range[i] / 100.0
rgb_value[i] = (one_percent_of_range * tag_percent) + max_colour
end
hex = "#%02x%02x%02x" % rgb_value[]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment