Archived

This topic is now archived and is closed to further replies.

Michalson

ASCII Fishtank Mini Contest!

Recommended Posts

IainC    127
Michalson: I know I should have waited But maybe I have such a revolutionary groundbreaking technique that I wanted everyone else to use big dithered fish so I''d look better

The reason for the roundabout technique is that I thought that doing this:

  
if (colour.r > colourTable[i][0]) {
differenceR = colour.r - colourTable[i][0];
} else {
differenceR = colourTable[i][0] - colour.r;
}

...would be cheaper than this:

  
differenceR = sqrt(colour.r - colourTable[i][0]);


Is this incorrect?

www.coldcity.com
code, pics, life

Share this post


Link to post
Share on other sites
Michalson    1657
quote:
Original post by IainC
Michalson: I know I should have waited But maybe I have such a revolutionary groundbreaking technique that I wanted everyone else to use big dithered fish so I''d look better

The reason for the roundabout technique is that I thought that doing this:


    
if (colour.r > colourTable[i][0]) {
differenceR = colour.r - colourTable[i][0];
} else {
differenceR = colourTable[i][0] - colour.r;
}

...would be cheaper than this:

differenceR = sqrt(colour.r - colourTable[i][0]);


Is this incorrect?

www.coldcity.com
code, pics, life


Yes, your example would be faster, however that is because you have included a sqrt, which is not needed in this case. You only need to know which one is the smallest distance, so it doesn''t matter if you use if A or if sqrt(A) (hence you should use the faster one).

Share this post


Link to post
Share on other sites
IainC    127

  
//Ooops, I meant to write

differenceR = sqrt((colour.r - colourTable[i][0])*(colour.r - colourTable[i][0]));
//instead of

differenceR = sqrt(colour.r - colourTable[i][0]);
//in my previous post



Surely I need the differences to all be positive for when I do the comparism?

Example:
Real RGB = (0.5, 0.5, 0.5)
Match option 1 = (0.4, 0.4, 0.4)
Match option 2 = (0.9, 0.9, 0.9)

Option 1 is obviously the correct choice...

Calculate with Real-Match:
Difference is (0.1, 0.1, 0.1) with option 1 and (-0.4, -0.4, -0.4) with option 2, indicating that I should use option 2 (incorrect)

Calculate with sqrt(Real-Match * Real-Match):
Difference is (0.1, 0.1, 0.1) with Option 1 and (0.4, 0.4, 0.4) with Option 2, indicating to use option 1 (correct).

Am I missing something obvious?





www.coldcity.com
code, pics, life

Share this post


Link to post
Share on other sites
Michalson    1657
quote:
Original post by IainC
Am I missing something obvious?



Allow me to repost the code that I posted in the first place:

colorDifference=Sqr(R1-R2)+Sqr(G1-G2)+Sqr(B1-B2)

That is what you are missing. All you are doing is trying to find the comparative distance between two colors as expressed in the three dimensional RGB color space, hence the formula is exactly the same as a regular distance formula, minus the sqrt (since you are only comparing).

Share this post


Link to post
Share on other sites
Michalson    1657
quote:
Original post by IainC
Ummm... Sorry to be a pain - but isn't mine still cheaper than three squares?

www.coldcity.com
code, pics, life


Nope. The main slowdown with your code is the usage of the IF statements. In each IF statement there is a roughly 50% chance for either possibility, meaning that roughly 50% of the time the CPU will pick the wrong path and be forced to stop execution while it refills the pipeline. On a P4 this miss could cost you 20 cycles per IF statement, meaning an average of 30 cycles lost over the 3 IFs. On the other hand my code in its entirety can likely be executed in under 20 cycles.

When branch prediction is not going to be effective for an operation (like when you have an IF statement with no real bias) if possible it can be much less costly to use a number of math statements (which will all be done in 1 cycles or less) than suffer misspredictions. For instance I was working on a video codec much earlier this year and I had a formula for determining the difference between two pixels (sound familiar?). The usage was that it would compare two frames and return the number of visible (to human perception) differences between two frames of video.

Here is the original code, Difference and Count are both 32bit integers and the code was being run on a PIII800:

if Difference>63 {the threshold} then Count:=Count+1;

In this example the value of Difference will always be greater or equal to 0, so I optimized it by writing it as a serious of AND, OR, NOT and shift statements. It would first remove all the lower bits, so that Difference would either be 0 or non-zero (if it was above 63), and then used the shift and bitwise operators to reduce the value to either 0 or 1. I then added that value to Count. While the code I produced might seem much longer than the original (about 6 lines of "complex" statements), it actually ran more than 4 times faster, since the CPU wasn't losing a large number of clock cycles everytime it mispredicted the outcome (it would have been closer to 8 times faster on a P4, due to the insanely long pipeline).

EDIT: That "4 times" speedup was for the entire program (including the code for the forumlas which was not changed), hence the actual speedup for that one line of code was much higher.

[edited by - michalson on November 1, 2002 10:09:13 AM]

Share this post


Link to post
Share on other sites
RPGeezus    216
If you''re REALLY worried about speed (for color matching), couldn''t you just use a precomputed table? It''s not like you''re dealing with 24 or 16 bit colors here.

Will

Share this post


Link to post
Share on other sites
IainC    127
Michalson, many thanks for taking the time to explain that to me; I''ll change my code to reflect the superior technique and bear it in mind in the future.

RPGeezus, it''s not really that important to me; I just wondered why my way wasn''t faster than Michalson''s

www.coldcity.com
code, pics, life

Share this post


Link to post
Share on other sites
Raptor85    180
could i make a text mode fish tank bootable from a floppy? (ill supply a batch file, and program to create the floppy of course)

even if not, ill do it(maybe ill use qb, maybe asm, maybe c++, whatever i feel like (heck, if i can figure out the translation for the command to switch to 80x50 mode, maybe ill write it in intel x86 machine code (would that be acceptable ) )

my AI fish will kick all!

Share this post


Link to post
Share on other sites
Raptor85    180


  
|_______________________________________ |
| |
| |
| |
| |
| ____ |
| / x \__/| |
| * \-___/--\| |
| |
| 0 O |
| // |

| \ \ 0 |
| / / |
| \ \ |
|_______/_/______________________________|
[/code]

mu ha ha ha ha ha
(last post was mine, wont let me delete it)

[edited by - Raptor85 on November 3, 2002 12:55:07 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Could one of you experts give me some prompts to start. I want to use the "default" libraries. How would I enable all of this text handling stuff?

Share this post


Link to post
Share on other sites
Michalson    1657
What compiler are you using? Most come with a standard "console" application template. Under Windows you want to lookup (on MSDN) the following Win32 commands to get started with "graphical" console output:

GetStdHandle
Use GetStdHandle(STD_OUTPUT_HANDLE) to get a handle to the console for use in other functions

SetConsoleScreenBufferSize
Sets the size of the internal buffer (stored used for the console)

SetConsoleWindowInfo
Sets the size of the actual console window

WriteConsoleOutput
Copies a buffer of CHAR_INFO records to the screen. Personally I find this is the best method for "graphical" content.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
What are the maxium and minimum dimensions of the window and/or its resolution? Can we have a "fullscreen" aquarium with the tiniest of text?

Share this post


Link to post
Share on other sites
Michalson    1657
quote:
Original post by Anonymous Poster
What are the maxium and minimum dimensions of the window and/or its resolution? Can we have a "fullscreen" aquarium with the tiniest of text?


As stated before it''s either 80x50 or 80x25 (Depending on your version of Windows you might not be physically able to do anything other than these 2 [except for 80x43]). The size of text is up to the user, though you can assume they''ll go fullscreen in which case it''s 8x8 or 8x16.

Share this post


Link to post
Share on other sites
Gah I wish I would have had time and attention to get on this when it started. It would have given me a little project, rather than just writing handfuls of little handy code fragments that I might use some day.

Can''t wait for the next little project.

-Ryan "Run_The_Shadows"
-Run_The_Shadows@excite.com
-The Navidson Record! The best film you''ll never see!

Share this post


Link to post
Share on other sites
Michalson    1657
quote:
Original post by Anonymous Poster
How to submit these sweet fishy fishtank?


It will likely be by email to an email account (not my normal account, since hotmail doesn''t allow >1MB), or I might setup a web based file upload (though that will mean no progress bars/resuming which could be bad for 56K users. I also don''t know if the upload would kill my bandwidth restrictions).


This post qualifies for 100 per cent Canadian Content under the rulings of the Canadian Internet Commission and the Federal Ministry of Communication. There are four Americans who worked on this post, but they all have landed immigrant status, and have signed CRTC affidavits swearing that they drink beer, eat back bacon, drive snowmobiles and wear toques. Any resemblance between the Content of this post and the content of any American post is purely coincidental and not the intention of the poster or the various Internet Agencies of the Canadian Government who have screened these posts prior to bulk erasing in accordance with the policies of the Federal Internet Identity Board.

Share this post


Link to post
Share on other sites
Tandaur    122
Grr i hate windows. Im used to programming MUDs in linux.

I havent programmed in windows since 11th grade which was in
'96.

Doing it as a win32 app not a console app cus i want buttons or
menus. Though i dont recall how to set the window size etc.

Oh well, ill just write my classes and worry about displaying the stuff later.

[edited by - tandaur on November 6, 2002 3:18:32 AM]

Share this post


Link to post
Share on other sites
TwistedMatrix    122
I have a question. I have many extra sources in my sumbission now that are not required to be compiled to run the ascii fish demo. (These are short programs I am writing alongside to make lookup tables and such for the main program)

My question is: DO all included sources need to be procompiled before the submission is sent (Reason for asking is DJGPP compiles really big EXE''s. I could include them all into the same program, but the code would get too messy to deal with i think.)

thanks...

-= Twisted Matrix =-

Share this post


Link to post
Share on other sites
Michalson    1657
quote:
Original post by TwistedMatrix
I have a question. I have many extra sources in my sumbission now that are not required to be compiled to run the ascii fish demo. (These are short programs I am writing alongside to make lookup tables and such for the main program)

My question is: DO all included sources need to be procompiled before the submission is sent (Reason for asking is DJGPP compiles really big EXE''s. I could include them all into the same program, but the code would get too messy to deal with i think.)

thanks...

-= Twisted Matrix =-


That gets tricky, since at the same time you could argue that textures should require the original working file and such. I think I''ll leave it up to you. So long as the source code and datafiles you provide are all that is needed to make a new exe then it is fine (though you might include some documentation on how you generated the files). Of course in reality I don''t think it would be a great deal of trouble to include source code for those (you don''t need to include EXEs), since source code zips nicely (Yesterday I zipped a 1.2MB source file into a 21KB zip file), but it won''t be required unless the judges raise concerns about the source of your datafiles (in which case I would simply request a non-redistributable source file to verify that the files are legit).

Share this post


Link to post
Share on other sites
TwistedMatrix    122
I wasnt asking if I shoud include the source that generates the precomputed data. I would include all source natrually. I was asking if all of the extra code needed to be built(compiled + linked) before it is zipped and sent.

quote:
That gets tricky, since at the same time you could argue that textures should require the original working file and such. I think I''ll leave it up to you.

textures? what do you mean. I thought you said that the main program could incorperate NO image data what-so-ever. Mabey i am misunderstanding you.

-= Twisted Matrix =-

Share this post


Link to post
Share on other sites
CWizard    127
quote:
Original post by Michalson
It will likely be by email to an email account (not my normal account, since hotmail doesn''t allow >1MB), or I might setup a web based file upload (though that will mean no progress bars/resuming which could be bad for 56K users. I also don''t know if the upload would kill my bandwidth restrictions).
Submit by e-mail??? That sounds crappy If you like, and need it, I could set up an unlimited ftp account on a T1 line, for you to use. I could also script it to send an e-mail to you when something is uploaded. Let me know if you''re interested.

Share this post


Link to post
Share on other sites
Michalson    1657
quote:
Original post by TwistedMatrix
I wasnt asking if I shoud include the source that generates the precomputed data. I would include all source natrually. I was asking if all of the extra code needed to be built(compiled + linked) before it is zipped and sent.

textures? what do you mean. I thought you said that the main program could incorperate NO image data what-so-ever. Mabey i am misunderstanding you.

-= Twisted Matrix =-


I was just citing textures as a general example, though of course you could have textures (TGA or whatever format you want), so long as they are displayed in textmode. I guess I misinterpreted your question, the answer is that the executables required are for your actual entry (that way judges can see your entry even if they don''t have access to the same compiler).


This post qualifies for 100 per cent Canadian Content under the rulings of the Canadian Internet Commission and the Federal Ministry of Communication. There are four Americans who worked on this post, but they all have landed immigrant status, and have signed CRTC affidavits swearing that they drink beer, eat back bacon, drive snowmobiles and wear toques. Any resemblance between the Content of this post and the content of any American post is purely coincidental and not the intention of the poster or the various Internet Agencies of the Canadian Government who have screened these posts prior to bulk erasing in accordance with the policies of the Federal Internet Identity Board.

Share this post


Link to post
Share on other sites
TempusElf    186
quote:
Original post by Tandaur
Doing it as a win32 app not a console app cus i want buttons or
menus. Though i dont recall how to set the window size etc.



Oh dammit... and I thought my idea was so original... oh well

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.