Computer Science Canada

bmp/jpg -> Turing Code (drawdot)

Author:  Izzy [ Wed Feb 19, 2003 9:14 am ]
Post subject:  bmp/jpg -> Turing Code (drawdot)

Heya,
I created this little program, because I wanted to have a picture in a game but...
1. Isn't drawn using lines and circles... pixel by pixel, argh, that's tough!
2. I don't want any picture files included (ie. MyChar.bmp) or what not Razz

So I created this little program.
Basically you navigate through your harddrive (hopefully C: because I didn't include a drive change), and find a picture file. Ex (*.bmp or *.jpg)! Then you load it into the program, the program then displays the picture and records every color of every pixel, it then saves the results in a *.t file (you assign the name), the code in the *.t file will be as follows...

drawdot (x, y, color)
..
..
..
for every frickin' pixel Razz

This means if you try using this with an 800x600 sized picture you'll end up with a 480,000 line code, just to draw your picture. And the file pushes 10 megs!

But.... if you have a nice little 50x50 picture you drew in paint it can do the job nicely!

Also, the program only has a palette of 255 colors so don't expect perfect quality! I will attach an example, of how well one picture turned out!

How you use this beast!
- There are two text fields (some of you may know them as text boxes)

- The top one is for the filename, this is where you type the name of the *.t file to be saved. (ex. If you put Monkey, the file will be saved as Monkey.t) You can enter it whenever you want, but make sure it's in there before you try to load the picture.

- The bottom text field is for navigating, Simply type the name of the directory you would like to navigate to and it will go there, it will then display all the files/folders in that directory in the Text Box on the right (in this case it's more like a picture box to you Visual Basic's kids)

- The two buttons are Next and Quit, Quit.. well quits and Next takes the data in the Directory Text Field and moves on to the next folder (or loads picture, you'll understand in a min)

- There are two Radio Buttons (or option buttons) which you use to switch mode (either, Open Directory or Open Picture), if Open Directory is selected, when you use the next button it will take the data in the Directory Field and attempt to open it as a Directory, if it's on Open Picture when you click next it will take the data in the Directory Field and try to open it as a picture file. Basically use Open Directory while navigating and use Open Picture only when you're navigated to the appropriate point (but have the file name in the Directory Field ex. Mychar.bmp)

Okay if you're still awake just try the program and see if you get it, if you don't just use this as a referense, or post a response!

*Note*
- This is my first GUI Program in Turing, so don't expect anything amazing.

- IF YOU GET STUCK while navigating through simply type c: to take yourself back to the root directory. (ie from c:\temp\a\b\c\d\e\f\g\h.exe to c:\)

- Use .. to go back to the root directory (ie. from c:\temp\foldera\ to c:\temp\)

- It isn't impossible to crash this program, I can drop it in 5 sec flat, but if you're aren't trying to then it's not that bad.

- When you load your picture it will display it and seem to sit there (the duration depends on how big it is) this is when it is working away! Just wait, and wait som'ore and eventually it will close. It took about 30 sec to do an 800x600 sized picture on my p3 running @ 933mhz w. 512 megs of ram. Crying or Very sad

- It will save the file in the directory you launched this program from, so put this program in a folder you know how to get at (ex. c:\temp).

This an example of a picture that turned out decent Razz I know it only turned out this good is because the Ultima Online engine has a similar palette to the one Turing has.

Before
http://www.geocities.com/izzy_turing/before.jpg

After
http://www.geocities.com/izzy_turing/after.jpg

Anyway just try it out, it's easy enough to understand!

Also, When in the FileName Text Field, if you press enter, it places the cursor in the Directory Text Field, if you press enter in the Directory Text Field it will activate the 'Next' Button Code.

- Izzy

Ps. If you don't already know you can use the Pic.New (x1,y1,x2,y2) to save whatever is in those coordinates in a variable, That function is what makes use of this program. i.e have your game load the source for the picture and draw the picture, then use Pic.New to save it! Viola! You can freely use the picture, moving it around easily.

Author:  Catalyst [ Wed Feb 19, 2003 9:54 am ]
Post subject: 

i did this exact thing! I need a proc to replace a faulty Pic proc for my turing ISU

Author:  Tony [ Wed Feb 19, 2003 10:02 am ]
Post subject: 

Good job Very Happy

its a good idea for hardcoding your image files inside your program if you want to hide them... so some reason or other Confused

I wonder if there's a way to convert a jpg image into a vector one? such as drawfillbox's and drawfillpolygon's indead of every pixel? Though I guess Adobe would already come out with it Confused

It would be a nice piece of software though Wink

Author:  Izzy [ Wed Feb 19, 2003 10:13 am ]
Post subject: 

Indeed it would be neat. Flash has a pretty spiffy one built into it!

Oh Catalyst, i was a bit confused about your post, do you need some help with something or are you just commenting?

- Izzy

Author:  Tony [ Wed Feb 19, 2003 11:12 am ]
Post subject: 

i think he was commening that he made a similar program before Confused

Author:  Izzy [ Wed Feb 19, 2003 11:32 am ]
Post subject: 

Heh, yeah I got that bit, but then he said something about a faulty pic procedure he has ? or something like that, anyway, we'll see what happens, he's the only guy that can really say Razz 8)

- Izzy

Author:  Izzy [ Thu Feb 20, 2003 7:59 am ]
Post subject: 

Heya,

I think I get what Catalyst was talking about, i've gotten an assert error when the program first runs, seems to run fine on my desktop, It hasn't worked on my Mom's, my laptop, or a computer @ school, could be an OS thing...

    - My mom's Desktop is running 98se.
    - My laptop is running 95.
    - The computer @ school is running 95.
    - My Desktop is running XPpro.


Anyway if you get an error, sorry. I'm not gonna bother trying to fix it (sorry) because it works fine on my desktop and that's all that really matters. Razz >8^P

- Izzy

Author:  Tony [ Thu Feb 20, 2003 12:46 pm ]
Post subject: 

Since win XP is not DOS based, it probably names folders differently or something... I donno...

Also might be the way turing gets to the files Confused They COULD have made a normal programming language, but NOO... had to use a cheap lexes (or whats that program's name?) instead.

Author:  Catalyst [ Thu Feb 20, 2003 12:51 pm ]
Post subject: 

what i meant was (and by the way i was just commenting) was that depending on the comp turing will take pics at diff color resolutions, sometimes 256 sometimes 16

Author:  Delta [ Fri Mar 21, 2003 10:57 am ]
Post subject:  Error

Yeah I got an Assertion error as well. Question...when you load an image does the program calculate the size of the picture or does it just draw the entire screen. If so how?


: