Alright then. Apologies accepted.
Alright then. Apologies accepted.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Wait. You called me a zealot, and I apologized? Brlblbrlblbl, you meanie.
I like to just cut the middleman when apologies are in order. Makes (my) life so much easier.
You should start doing it too. Feeling like apologizing to someone? Apologize and accept your own apology. There! Problem solved. With the added benefit you don't risk running into some arsehole who can't accept apologies. Besides, who's should always accept an apology? The person that asked of course! He's the one that knows whether his apology is sincere or not.
Life should be this simple.
Last edited by Mario F.; 08-22-2015 at 12:11 PM.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
I tried writing some code that did this color thing, I'm still working on it, but so far I have it like this:
$>./rainbow "lyrics.txt" "#FF0000" "#00FF00" "#0000FF" "out.txt"
Jumping up and down the floor,
My head is an animal.
And once there was an animal,
It had a son that mowed the lawn.
The son was an OK guy,
They had a pet dragonfly.
The dragonfly it ran away,
But it came back with a story to say.
Her dirty paws and furry coat,
She ran down the forest slopes.
The forest of talking trees,
They used to sing about the birds and the bees.
The bees had declared a war,
The sky wasn't big enough for them all.
The birds, they got help from below,
From dirty paws and the creatures of snow.
So for a while things were cold,
They were scared down in their holes.
The forest that once was green
Was colored black by those killing machines.
But she and her furry friends
Took down the queen bee and her men.
And that's how the story goes,
The story of the beast with those four dirty paws.
With only 2 colors ("#FF0000" "#0000FF") :
Jumping up and down the floor,
My head is an animal.
And once there was an animal,
It had a son that mowed the lawn.
The son was an OK guy,
They had a pet dragonfly.
The dragonfly it ran away,
But it came back with a story to say.
Her dirty paws and furry coat,
She ran down the forest slopes.
The forest of talking trees,
They used to sing about the birds and the bees.
The bees had declared a war,
The sky wasn't big enough for them all.
The birds, they got help from below,
From dirty paws and the creatures of snow.
So for a while things were cold,
They were scared down in their holes.
The forest that once was green
Was colored black by those killing machines.
But she and her furry friends
Took down the queen bee and her men.
And that's how the story goes,
The story of the beast with those four dirty paws.
WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;
You'll get better color transitions if you mix the colors in YCbCr color space instead of RGB.
I'm going to report you lot to the moderators.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Very nice. Another fun feature to try adding is direction of coloring.
Left-to-right:
1234567890Code:--start=left --color1=red --color2=blue
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
Top-to-bottom:
1234567890Code:--start=top --color1=blue --color2=green
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
Diagonal:
1234567890Code:--start=topleft --color1=FF11FF --color2=23FFFF
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
I knew you would have the vertical as well lol! The mixture of the two is a challenge, I'll have to work it out.Originally Posted by Matticus
I'll give it a shot, thanks .You'll get better color transitions if you mix the colors in YCbCr color space instead of RGB.
WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;
I would love to see a much wider block of "1-0" text where a message is visible within the block using contrasting colors. Could the cursing filter filter it?
gg
I figured out the problem with the transitions. I was dividing the color-step by the entire line length, rather than the length of the segment for a transition. So it wasn't fully reaching one color before changing to another.
I thought I would post the part I had the most trouble with. Most of the rest of the program is just the Color class, which has some RegExp's in a static map to recognize the color type. This looping part gave me trouble as it was such a brain bender to me:
Sample output with multiple colors :Code:// I know it's probably golfed down too much bool Rainbow::output (std::ifstream& in, std::ofstream& out, const bool& html /*false*/) const { bool isOpen = in.is_open() && out.is_open(); if (isOpen) { std::string line(""); // Loop through line by line. while (std::getline(in, line, '\n')) { // Calculate max width of line segment const float width = line.length() / (float)(m_numColors - 1); // Get value copy of first color, in order to accumulate changes. // Possibly it would work to use (character_index / width) ratio as well. Color currentColor = **m_colors.begin(); // Loop through colors from 1 to end, we need the index so not using iterators. for (int i = 1, iEnd = m_colors.size(); i < iEnd; i++) { // Loop through characters of segment we are working on, // substr automatically cuts off too long lines. // This basically works the same as sprite animation. for (const auto& ch : line.substr((int)((i - 1) * width),(int)((i - 1) * width + width))) { // This seems necessary as colored spaces don't seem to be preserved on vBulletin if (isspace(ch)) { out << ch; continue; } // Wrap the character in font tags, or forum specific tags with the color value out << htmlWrap(currentColor, ch, html); // Update the color by taking difference of where we are and where we // are going, then divide by the length in units of a line segment. // Again this works like moving sprites by velocity. currentColor += ((*m_colors[i] - *m_colors[i - 1]) / width); } // Update the current color to the next one, again by value currentColor = *m_colors[i]; } out << (html ? "<BR>" : "\r\n"); } } return isOpen; }
$> ./rainbow "test.txt""#FF0000" "#00FFFF" "#FF00FF"
This establishment's name is Hochberghaus. It is in Bohemia, a short day's
journey from Vienna, and being in the Austrian Empire is of course a health resort.
The empire is made up of health resorts; it distributes health to the whole world.
Its waters are all medicinal. They are bottled and sent throughout the earth; the
natives themselves drink beer. This is self-sacrifice apparently--but
outlanders who have drunk Vienna beer have another idea about it.
Last edited by Alpo; 08-24-2015 at 07:52 PM.
WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;
Isn't it just normal bilinear interpolation,
V = ( (h - y) ⋅ ( (w - x) ⋅ V00 + x ⋅ V0w ) / w + y ⋅ ( (w - x) ⋅ Vh0 + x ⋅ Vhw ) / w ) / hper component? V00 being the value at x=0,y=0, V0w at x=w,y=0, Vh0 at x=0,y=h, and Vhw at x=w,y=h?
Ah, no; you probably want the start and end values for each line, i.e.
V0 = ( (h - y) ⋅ V00 + y ⋅ Vh0 ) / hVw = ( (h - y) ⋅ V0w + y ⋅ Vhw ) / hand then interpolate the color on each line, as the number of characters w on each line varies, ie.
V = ( (w - x)⋅ V0 + x ⋅ Vw ) / w
If you only have the two components for the diagonal, the other two can be either mid way,
V = (V0 + V1) / 2or scaled by the aspect ratio,
V0w = (w⋅V00 + h⋅Vhw) / (w + h)Vh0 = (h⋅V00 + w⋅Vhw) / (w + h)depending on whether you want the perpendicular line of the gradient to also be diagonal, or just at straight angles to the defined diagonal. It only shows up when the text block is non-square, though.
Also, like Mario implied in #66, these are ANSI, not POSIX.1, if you do them in a terminal.
Actually, my approach is probably a lot more basic than that. It only works with two colors, and steps the color components of each successive diagonal linearly from the start color to the end color.
The equations you posted seem much more advanced than the implementation in my own version of the program.
To illustrate the basic approach I used with a simple example, let's assume the following:
- Use letters in lieu of color codes
- The start letter is 'A'
- The end letter is 'U'
- The number of rows is 4
- The number of columns is 8
This would give us a step size of:
('U' - 'A') / (8-1) + (4-1) = 20 / 10 = 2
Printed out, it would look like this:
Or, to illustrate it with a diagram:Code:A C E G I K M O C E G I K M O Q E G I K M O Q S G I K M O Q S U
To me, this general approach was the best way to achieve simple diagonal coloring. (As this was just intended as a quick "fun" project, I tried to avoid getting too fancy.)