HTML Color Table Generator


When I’m bored I can spend my time creating weird, pointless things. Such as this HTML Color Table generator. What does it do?

Well, it takes only 2 inputs: the number of rows and numbers of columns. It then creates (rows)*(columns) number of cells, each cell being a different color( might be even unique but I guess there’s a high chance 2 cells will have the same color). Bonus: each cell is numbered! :))

It’s a simple console C++ program that makes use of the randomization function( well, computers have a pseudo-randomization algorithm but it works…).

Here’s how the program looks:

And here’s how the output .html file looks like for the above numbers(10 rows and 20 colons):

Meh, doesn’t have a point right? I made it just for fun 😛

If you want you can download the program here (I think it only works under Windows).

And here’s the source code if you’re interested:

// uses style=”background-color:rgb(r,g,b)” and rand()%256 for generating the color

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <fstream>
using namespace std;

int main(){

srand(time(NULL));
ofstream table(“colortable.html”);
int rows, colons; int i,j, r,g,b;
int number=0;

cout<<“WARNING! DO NOT IMPUT HIGH NUMBERS! (number of cells = rows*colons!) => Will take forever to generate…”<<endl<<endl<<“It is also recommended to avoid a big number of colons to avoid horizontal scrolling!”<<endl<<endl;

cout<<“Input the number of <<rows>> the color table will have:”<<endl; cin>>rows;
cout<<endl<<“Input the number of <<colons>> the color table will have:”<<endl; cin>>colons;
cout<<endl<<“We are ready to start!”<<endl;

table<<” <html><html><head><title>Random Color Table</title></head><body><table border=’1′ align=’center’>”;

for(i=0; i<rows; i++){
table<<“<tr>”;
for(j=0; j<colons; j++){
table<<“<td style=’background-color:rgb(“<<rand()%256<<“,”<<rand()%256<<“,”<<rand()%256<<“)’>”<<number<<“</td>”;
cout<<“Cell number”<<number<<endl;
number++;
}
}

table<<“</table></body></html>”;

return 0;}

Have fun!

Advertisements

7 thoughts on “HTML Color Table Generator

  1. Poate nu are vreo aplicatie directa insa e interesanta de urmarit, atat codul cat si ceea ce este afisat cand ruleaza. Foarte interesant!

  2. Ti-am studiat putin programul si i-am gasit o aplicatie practica. In webdesign este folositor un program care sa-ti genereze un tabel de culori. Asa ca, sper sa nu te superi, insa am preluat ideea unui astfel de program si am scris un alt cod, in java, care creeaza automat 3840 culori intr-un oarecare gradient si afiseaza codurile css ale culorilor. Nu ti-am preluat codurile ci am scris altele, mergand pe alta idee. Daca te intereseaza, asta este adresa: http://23ars.blogspot.ro/2012/06/previous-program-in-java.html

    1. De ce sa ma deranjeze? Ma bucur ca te-a inspirat! Ceea ce am facut eu a fost foarte “basic”, iar tu ai extins ideea. Foarte interesant!

      1. pai… te-am anuntat ca ti-am preluat ideea de program. nu vreau sa iau ceva din munca unei persoane si sa modific putin sau mai mult fara sa anunt…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s