Computer Science Canada

[Tutorials] Pictures/Images

Author:  Dan [ Thu Dec 19, 2002 9:29 pm ]
Post subject:  [Tutorials] Pictures/Images

How to use images in Turing


You can load 3 different types of pictures in Turing. They are PCX, BMP and TIM.


1st you need to load the image into Turing's memory:

var varname :int := Pic.FileNew ("filename")


Ex.

code:

     %for a file that is in the same dir as your Turing code                                                                                                                   
      var mypic :int := Pic.FileNew ("coolpic.bmp")
     


or

code:

       %to specify the exact location of this file
       var mypic :int:= Pic.FileNew ("c:\turing\mygame\coolpic.bmp")
     


2nd you need to show the picture and set it's location on the screen

Pic.Draw (picID, x, y, mode)


Ex.

%to draw the picture in the center of the screen with no mode
Pic.Draw (mypic, maxx div 2, maxy div 2, 0)


The modes:

picCopy This draws the picture on top of what was underneath, obscuring it completely.

picXOR This draws the picture XORing it with the background.

picMerge This draws the picture like picCopy except that any occurrence of the background color in the picture is not drawn to the screen.

picUnderMerge This draws the picture, but only where the background color was displayed underneath it


If you want to get rid of the picture after you have drawn it on the screen use cls and to get it out of the memory of the computer use Pic.Free (mypic).


Example of a program that uses pics:


code:

                %program to show a logo picture
                var mypic :int := Pic.FileNew ("coolpic.bmp")
                Pic.Draw (mypic, maxx div 2, maxy div 2, 0)
               
                delay (2000)
                cls
                Pic.Free (mypic)



this was one of the 1st turealrs i made, i dont think i did a good job on it but i figered why not post. so here it is...

Author:  Tony [ Thu Dec 19, 2002 10:29 pm ]
Post subject: 

turing 4.x also supports .jpg format. And you can also hope for .gif support in about 4-5 years from now.

Author:  cutecotton [ Mon Dec 23, 2002 12:59 am ]
Post subject: 

*sniff* how i wished i found this forum earlier..i've been struggling for 2 days to find out howt o do that in turing..*sniff*

Author:  Vicous [ Fri Feb 28, 2003 9:52 am ]
Post subject:  window size

on a side note, what is the code for changing the window size, I know it has something to do with setscreen

Author:  Tony [ Fri Feb 28, 2003 10:02 am ]
Post subject: 

View.Set("graphics:length;height")

as in View.Set("graphics:400;100")

Author:  Vicous [ Fri Feb 28, 2003 10:12 pm ]
Post subject:  view.set, setscreen

wha? whats the dif between view.set and setscreen?

Author:  Tony [ Sat Mar 01, 2003 12:08 am ]
Post subject: 

no difference... you can use ether one you like.

Author:  Vicous [ Sun Mar 02, 2003 4:45 am ]
Post subject:  Re: [Tutorials] Pics

Hacker Dan wrote:
How to use images in Turing

The modes:

picCopy This draws the picture on top of what was underneath, obscuring it completely.

picXOR This draws the picture XORing it with the background.

picMerge This draws the picture like picCopy except that any occurrence of the background color in the picture is not drawn to the screen.

picUnderMerge This draws the picture, but only where the background color was displayed underneath it



can you elaborate on a few things, such as how to set which background color, and what XORing means?

Author:  Asok [ Wed Mar 05, 2003 7:09 pm ]
Post subject: 

I figured picXor was just some guys at UofT being leet.

don't hax0r my picX0r!

ooooh yea! Smile

Author:  Tony [ Wed Mar 05, 2003 7:33 pm ]
Post subject: 

someone beeing playing too much counter-stike Wink

its a good game though 8)

Author:  Tubs [ Wed Mar 05, 2003 7:40 pm ]
Post subject: 

rofl thats good

its not just in cs, that kind of language is on every internet game

btw cs sucks compared to mohaa bf1942 etc etc

Author:  Asok [ Wed Mar 05, 2003 7:51 pm ]
Post subject: 

I have to agree, in bf1942 you get to run people over in viechles! *remembers tribes2*

*beep beep*
whoops Laughing

Author:  Vicous [ Wed Mar 05, 2003 7:56 pm ]
Post subject:  well

hate to be the one to break up this converstation (Counterstrike sounds familiar but I can't pin it down right now) but I kinda want the answer

Author:  Asok [ Wed Mar 05, 2003 8:11 pm ]
Post subject: 

k, all the pic options have to do with picture layering on top of eachother

picMerge will set it so that the color that matches the background is actually transparents so you can see images underneath

picCopy place the image on top of allready drawn images.

picXor inverts the color that is different than the background when a picture is touching it.

picUnderMerge sends the picture to the back so that other images that were drawn before it are still above it.

EDIT: oh and to set the background color is:

code:
colorback(color)


where the parameter is replaced with the actual color you want. (the Candian spelling of "colour" works too.)

Author:  Vicous [ Wed Mar 05, 2003 8:22 pm ]
Post subject:  the devil made me say it

what is this candian place and do they have candy?

sorry, that was just too tempting, thank you for answering my questions and giving me a reason to laugh

Author:  Tony [ Wed Mar 05, 2003 8:57 pm ]
Post subject: 

canada is a large North American nation located between Greenland and Alaska, most of which is above sea-level. Its the place where bombs will land once US anti-missile defence initiative takes place.

We dont have any candy, but I can offer you some sweets if you'd like Wink

Alright... in case some smartass will start lecturing me on proper use of english and difference between its variations, I'll admit that we dont have any sweets ether... British do Confused But we do import candy from US so feel free to treat yourself Wink

Author:  Vicous [ Thu Mar 06, 2003 7:49 pm ]
Post subject:  Im canadian too!

I'm canadian too, I was just joking as he posted that the "candian" (notice Candian, not Canadian) spelling of colour works too.

mmmmmmmmmm, candy

Author:  Tony [ Thu Mar 06, 2003 8:12 pm ]
Post subject: 

this is getting way off topic, but hey, what can I do?

if you start talking to dan, you can soon figure that he doesnt need to encript any of his documents cuz noone would be able to read them anyway Wink

Author:  Dan [ Thu Mar 06, 2003 9:48 pm ]
Post subject: 

hell ya, and thats the way i like it (cuts down on cost of enrption software). also stops poleop form using find on my computer to find any of my docments Wink .

Author:  haujobb [ Mon Mar 24, 2003 9:39 pm ]
Post subject: 

I'm having trouble with these commands I'm using:

var title : int := Pic.FileNew ("a:\title.pcx")

and:

Pic.Draw (title, 300, 300, 0)

and I get the error:

Illegal pic identifier

Does anyone know what that means, and can poeple hurry, I don't mean to be demanding but I'm on a tight schedule and I can't do much more until this damn thing works...

Author:  Tony [ Mon Mar 24, 2003 9:44 pm ]
Post subject: 

well although Dan said that file type is supported, I've never seem it before so I sujest using something we KNOW works. .bmp and .jpeg

or maybe it just cant find the file since its on an a:\ drive? such as floppy is missing... (why would you put image file on a floppy!?).

Illigal pic ID basically means you didnt load the file.

Author:  Delta [ Tue Mar 25, 2003 2:35 pm ]
Post subject:  PCX hahahaha...(cough)

I remember PCX files but that was back in the day when I downloaded the DOS version of Turing. But you're a lot better off just sticking to BMP and JPG files.

Author:  ¿§¥JÃ¥mës¥§¿ [ Sat Aug 23, 2003 7:24 pm ]
Post subject: 

How do you make the pic fill the whole screen like a back ground?









Canada rocks!!!!!! Very Happy

Author:  krishon [ Sat Aug 23, 2003 9:29 pm ]
Post subject: 

i think it should be in the help files...i dunno...haven't touched turing in a while...and i mean a while, lol...its been all c++

Author:  ¿§¥JÃ¥mës¥§¿ [ Sun Aug 24, 2003 10:26 am ]
Post subject: 

It just might be somewhere in the help files but I have no clue how to find ot can someone please help!!! Sad Question

Author:  Tony [ Sun Aug 24, 2003 7:27 pm ]
Post subject: 

code:

for y:1..maxy step pic.height(picID)
   for x:1..maxx step pic.width(picID)
   pic.draw(picID,x,y)
end for
end for


something like above.. standart grid filling algorithm.

Note: not actual turing code, might need to use proper syntax instead

Author:  AsianSensation [ Sun Aug 24, 2003 9:39 pm ]
Post subject: 

¿§¥Jåmës¥§¿ wrote:
How do you make the pic fill the whole screen like a back ground?


Pic.Scale can do that.

newpicID := Pic.Scale (picID, maxx, maxy)

that would stretch a picture to fill the entire run window.

or ...

You can customize the picture before hand. Like use some editing tools, like Paint Shop Pro, and edit it, and then call up the image.

Author:  ¿§¥JÃ¥mës¥§¿ [ Sun Aug 24, 2003 9:44 pm ]
Post subject:  thanx

Thanx alot that'll really help Very Happy

Author:  air_force91 [ Sun Jan 04, 2004 12:11 pm ]
Post subject:  i can't view the pic

u know how i need to enter (mypic, maxx div 2, maxy div 2, 0)

well...the "0" at the end's creating a problem...this is what im getting: Illegal picture ID '0'. (Probable cause: Picture was not successfully created)...

Author:  Tony [ Sun Jan 04, 2004 7:21 pm ]
Post subject: 

no... the 0 is the value of picCopy mode.

the problem is your picture ID, which is "mypic" variable

Author:  DanShadow [ Sun Jan 04, 2004 8:00 pm ]
Post subject: 

Yes, your program is doing this:
(mypic, maxx div 2, maxy div 2, 0)
Picture variable= mypic
x co-ordinate of picture= maxx div 2
y co-ordinate of picture= maxy div 2
value of picture= 0?????
Turing Program: 0?! Wtf does that mean!! AhhaAh! Dying!!!
The 0 has to be one of the following: (picCopy, picMerge, picXOR, etc.) I forget the rest of th em, but replace one of those with 0 to make the picture load correctly.

Author:  Mazer [ Sun Jan 04, 2004 8:33 pm ]
Post subject: 

no. 0 is perfectly fine. PicCopy is just a constant for 0.

watch:
code:

put picCopy
put picXor
put picMerge
put picUnderMerge


tada! those are four of turings draw modes. you could type those, or you could type a number from 0 to 4 instead. 4 will work as a draw mode but it doesn't seem to do anything useful.

so, to sum up, the problem was indeed with the loading of the picture. you probably had the filename typed wrong.

Author:  DanShadow [ Sun Jan 04, 2004 9:29 pm ]
Post subject: 

Oh really?! I thought the value of the pic had to be identified by pic+something...not numbers. Hm, interesting

Author:  help_wanted [ Fri Jan 09, 2004 1:11 pm ]
Post subject:  doesn't work

THIS DOES NOT WORK

Author:  DanShadow [ Fri Jan 09, 2004 3:50 pm ]
Post subject: 

NO! IT DOES WORK! YOU DONT WORK! WORK DAMN YOU!!
hehe, sorry for caps. And yes, it does work, make sure your picture, and .exe are in the same directory (folder).

code:

var ogre:int:=Pic.FileNew("ogre-picture.bmp")
Pic.Draw(ogre,200,200,picMerge)

Put a picture named "ogre-picture.bmp" in the same directory as your turing file, try this, and tell me it doesnt work. tx

Author:  recneps [ Fri Jan 09, 2004 9:19 pm ]
Post subject: 

sorry to be off topic (not that half of this topic has been) but why is the first page messed up?

Author:  Dan [ Sat Jan 10, 2004 2:48 am ]
Post subject: 

recneps wrote:
sorry to be off topic (not that half of this topic has been) but why is the first page messed up?


b/c an evil compsci.ca bug creeped up and eat the formating on the latter post on that page.

i am trying to kill this infseation of bugs but it has been slow going, alougth you may noticed that that waring on the main page is gone Wink

Author:  syphon4 [ Fri Jun 03, 2005 8:10 pm ]
Post subject:  pic

it always has a problem with my pic ture name in the location of the file..help
var pic : int := Pic.FileNew ("C:\pink pimp")


my picture is saved directly under c: and its called pink pimp and its a jpeg file..................how can i make this program works

p.s. I will pwn any of you noobs in CS because im uber pro

Author:  Cervantes [ Sat Jun 04, 2005 6:45 am ]
Post subject:  Re: pic

syphon4 wrote:
it always has a problem with my pic ture name in the location of the file..help
var pic : int := Pic.FileNew ("C:\pink pimp")

my picture is saved directly under c: and its called pink pimp and its a jpeg file..................how can i make this program works

It's time we cleared something up. Asking the same question multiple times does NOT increase the chances of getting help. Rather, it infuriates people.
syphon4 wrote:

p.s. I will pwn any of you noobs in CS because im uber pro

Laughing And this doesn't help you get your answers either.

Now, go look in your other thread for your answer.

Author:  questionableninja [ Wed Nov 21, 2007 5:00 pm ]
Post subject:  RE:[Tutorials] Pictures/Images

when i input an img and i try to move it around it goes off the curser meaning that when the curser goes off the screen the game ends : (

Author:  Clayton [ Wed Nov 21, 2007 5:50 pm ]
Post subject:  RE:[Tutorials] Pictures/Images

You're going to have to be a bit more descriptive here. I have absolutely no idea what you are talking about. Is the image set to track with the mouse? Is the image set to the keyboard cursor? I think you see the problem here.

Author:  sh0td0wn [ Wed Jan 16, 2008 12:02 am ]
Post subject:  Re: [Tutorials] Pictures/Images

How do you kill the image after you're done with it, or at least hide?

Author:  syntax_error [ Wed Jan 16, 2008 12:15 am ]
Post subject:  Re: [Tutorials] Pictures/Images

are you talking bout free.pic?
not sure if that is quite teh syntax but its something like that

Author:  ericfourfour [ Wed Jan 16, 2008 4:36 pm ]
Post subject:  RE:[Tutorials] Pictures/Images

If you want to remove a picture from the screen, you have to draw over it. To deallocate a picture's memory use Pic.Free.

Author:  revangrey [ Fri Jan 02, 2009 5:05 pm ]
Post subject:  Re: [Tutorials] Pictures/Images

seeing as how many times this thread has been brought back I do not consider this to be a "necro"

I hope...

anyways I seem to be unable to put in a .jpg image

or any image for that matter

now I am pretty sure I have followed the steps but would anyone care to explain this to me?

I may have missed something...

Author:  Insectoid [ Fri Jan 02, 2009 7:49 pm ]
Post subject:  RE:[Tutorials] Pictures/Images

If you have a valid question, necroing a tutorial is perfectly fine. What version of Turing are you using? The original tutorial looks dated to me, written before JPGs were supported. I suggest looking through other people's code or posting your code in the help section. Then we can help better.

Author:  mrt2323 [ Sun Mar 15, 2009 11:10 pm ]
Post subject:  Re: [Tutorials] Pictures/Images

wtf is the A suppose to do after you specify the location of the pic. I can get it to work. Im noob at this.. it's only been my first 2 weeks with turing.

Author:  Insectoid [ Mon Mar 16, 2009 8:44 am ]
Post subject:  RE:[Tutorials] Pictures/Images

That is a graphical error. Ignore it.

use Pic.FileNew ("blahblahblah.bmp")

Author:  bigone150 [ Tue Apr 28, 2009 8:34 am ]
Post subject:  Re: [Tutorials] Pictures/Images

var Alien : int := Pic.FileNew ("Alien.bmp")
Pic.Draw (Alien, 520, 195, 0) % 520,1



hmm that is my coding for a picture i wanna keep at coordinates 520,195... when i run it it comes up as a blank screen even when i have all my coding... there.
Also while im at it i would like to make the picture shake left right a bit as its an alien.. IF someone could reply to this fast. I would really appreciate it as its due in 45 mins..

Author:  mirhagk [ Thu Sep 24, 2009 10:42 am ]
Post subject:  Re: [Tutorials] Pictures/Images

Hey so i've read the tutorial on printing, I have a question though, is there any way to print a picture?

Author:  syntax_error [ Thu Sep 24, 2009 11:07 pm ]
Post subject:  RE:[Tutorials] Pictures/Images

You would have to write your own function for that to be remotely possible; I am certain there is no in built function with turing.

Author:  D_homes [ Tue Jan 19, 2010 3:31 pm ]
Post subject:  RE:[Tutorials] Pictures/Images

Is it possible to use the same image more than once at a time?

Author:  TheGuardian001 [ Tue Jan 19, 2010 4:06 pm ]
Post subject:  Re: RE:[Tutorials] Pictures/Images

D_homes @ Tue Jan 19, 2010 3:31 pm wrote:
Is it possible to use the same image more than once at a time?

Yes.

Author:  D_homes [ Tue Jan 19, 2010 4:35 pm ]
Post subject:  Re: RE:[Tutorials] Pictures/Images

TheGuardian001 @ Tue Jan 19, 2010 4:06 pm wrote:

Yes.


And how would one go about doing that?

Author:  TheGuardian001 [ Tue Jan 19, 2010 5:27 pm ]
Post subject:  Re: [Tutorials] Pictures/Images

The same way you did it the first time.
code:

var myImg : int := Pic.FileNew("MyImage.jpg")
Pic.Draw(myImg,10,10,picMerge)
Pic.Draw(myImg,300,300,picMerge)

Author:  Jfenty15 [ Sat Dec 25, 2010 1:35 am ]
Post subject:  RE:[Tutorials] Pictures/Images

K wat if ive got a forked backround looping, but continueously 'cls'ing? for me the picture just flickers Sad
and how do i post code so i can show you?

Author:  Jfenty15 [ Sat Dec 25, 2010 1:37 am ]
Post subject:  RE:[Tutorials] Pictures/Images

here but warning this could cause siezures or epileptic reactions so beware: View.Set ("graphics:1200;800, nobuttonbar")

var i : int := 0

procedure sticky (y : real)
var stickyleft : int := Pic.FileNew ("Sticky left.GIF")
var stickyright : int := Pic.FileNew ("Sticky right.GIF")
if y = 1 then
cls
Pic.Draw (stickyleft, maxx div 2, maxy div 2, picCopy)
elsif y = 2 then
cls
Pic.Draw (stickyright, maxx div 2, maxy div 2, picCopy)
end if
end sticky

process playstuff
loop
Music.PlayFile ("Full Double Rainbow.wav")
end loop
end playstuff

process backround
loop
if Rand.Real > 0.5 then

for x : 32 .. 54
colorback (x)
cls
end for
end if
end loop
end backround


fork playstuff
fork backround
loop
for y : 1 .. 2
sticky (y)
end for
end loop

Author:  Tony [ Sat Dec 25, 2010 1:44 am ]
Post subject:  RE:[Tutorials] Pictures/Images

Drawing the background and foreground at the same time is just a bad idea. I'll let you figure out as to why that is.

Author:  TokenHerbz [ Sat Dec 25, 2010 3:17 am ]
Post subject:  RE:[Tutorials] Pictures/Images

ya terrible, try also offscreenonly and View.Update to help smooth things over.

Author:  Jfenty15 [ Sun Dec 26, 2010 12:02 am ]
Post subject:  RE:[Tutorials] Pictures/Images

is there a way to clear backround and for ground seperatly?

Author:  Jfenty15 [ Sun Dec 26, 2010 12:09 am ]
Post subject:  RE:[Tutorials] Pictures/Images

oh and is it possible to delay one part but not another if they are both part of a fork?

Author:  Jfenty15 [ Sun Dec 26, 2010 12:18 am ]
Post subject:  RE:[Tutorials] Pictures/Images

:S sorry one more thing um... i ran out of max id numbers even tho im "cls"ing so if i can delete the image or reset the id numbers? but before i finish the whole thing crashes because of loss of id numbers... here is the new program:

View.Set ("graphics:800;600, nobuttonbar")

var i : int := 0

procedure sticky (y : real)
var stickyleft : int := Pic.FileNew ("Sticky left.GIF")
var stickyright : int := Pic.FileNew ("Sticky right.GIF")
if y = 1 then
cls
Pic.Draw (stickyleft, (800 div 2)-100, (600 div 2)-75, picMerge)
delay (100)
elsif y = 2 then
cls
Pic.Draw (stickyright, (800 div 2)-50, (600 div 2)-75, picMerge)
delay (100)
end if
end sticky

process playstuff
loop
Music.PlayFile ("Full Double Rainbow.wav")
end loop
end playstuff

process backround
loop
if Rand.Real > 0.5 then

for x : 32 .. 54
colorback (x)
end for
end if
end loop
end backround


fork playstuff
fork backround
loop
for y : 1 .. 2
sticky (y)
end for
end loop

please enter your own audio file and pic and see if you can make it work?... maybe using Pic.Mirror?

Author:  Tony [ Sun Dec 26, 2010 12:28 am ]
Post subject:  RE:[Tutorials] Pictures/Images

Every time you use Pic.FileNew, it uses a new ID (up to a max of 1000, I think). Think about what it does (do you really need 1000 unique pictures at the same time?).

The background and foreground can be conceptually different, but you have only one screen to draw on. At the point the only difference is that you draw the background first and then the foreground on top. If you clear the screen, the entire thing clears. If you draw the background after the foreground, all you'll have on the screen is the background. forks makes the computer draw stuff at random, making everything a huge mess. Stop doing that.

Author:  gnauhZ [ Thu May 19, 2011 11:33 am ]
Post subject:  Re: [Tutorials] Pictures/Images

I get an "Illegal Extended Character in string literal" at ("H:\Turing Game--->\M<---ap.jpg")
any help. This also happens for the example that you gave me.

Author:  Tony [ Thu May 19, 2011 11:46 am ]
Post subject:  RE:[Tutorials] Pictures/Images

It sounds like part of the filename includes a character outside of ASCII's standard 0-127 values. This probably happens because \ is an escape character for special meanings; try using
code:

"H:\\Turing Game\\Map.jpg"

Although I'm not sure just how well spaces will be handled here.

Author:  SwiftDynasty [ Thu Jan 12, 2012 6:25 pm ]
Post subject:  Re: [Tutorials] Pictures/Images

Okay I'm having trouble putting in this picture fot turing this is what i have so far:

var pic : int
pic := Pic.FileNew ("pic.jpg")
Pic.Draw(pic,maxx,maxy,picCopy)


Whats wrong with it, it says,
"Illegal Picture ID number "0". ( Probable cause: Picture was not succesfully created.)"

Please help.

Author:  SwiftDynasty [ Thu Jan 12, 2012 6:57 pm ]
Post subject:  Re: [Tutorials] Pictures/Images

Okay, now I put the picture in the same folder as the turing program and there are no errors but the picture won't come up.

Author:  Beastinonyou [ Thu Jan 12, 2012 8:18 pm ]
Post subject:  Re: [Tutorials] Pictures/Images

SwiftDynasty @ Thu Jan 12, 2012 6:57 pm wrote:
Okay, now I put the picture in the same folder as the turing program and there are no errors but the picture won't come up.


lol... When you are drawing a picture using Pic.Draw (), the X and Y coordinates is the where the Bottom Left corner of the picture starts..

So if you are trying to draw the Picture at maxx, maxy (top Right of screen), you don't see the picture because it's being drawn beyond the screen.

Try drawing at 0,0..

Author:  Kman43759 [ Sat Oct 11, 2014 10:13 am ]
Post subject:  Re: [Tutorials] Pictures/Images

Ugh it came up saying some crap like Illegal Item ID 0 (probable cause: picture not succesful) blah blah dfjhsdif
I tried BMP AND JPG and it did not work

Author:  Insectoid [ Sat Oct 11, 2014 11:18 am ]
Post subject:  RE:[Tutorials] Pictures/Images

There are a number of reasons your picture didn't load. Maybe you've mistyped the file name. Maybe the file is in the wrong folder. When it 'says some crap', that crap is usually some hint about what went wrong so you can try to fix it.

Author:  Raknarg [ Sun Oct 12, 2014 5:00 pm ]
Post subject:  RE:[Tutorials] Pictures/Images

Illegal Item ID 0 (probable cause: picture not succesful)

Your picture is stored as an int in Turing. When you're drawing or doing something to a picture, the value of that int can't be 0. If it is, it throws this error.

If your PIcture ID is zero, it's either because it's set to 0 and you didn't load a picture, or you attempted to load a picture and that picture as you specified it did not exist.

Author:  gohabsgo007 [ Mon Jan 12, 2015 7:32 pm ]
Post subject:  RE:[Tutorials] Pictures/Images

Sometimes you just save your picture in a different folder and your code 'll work.


: