Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Graphics (sprites) in Turbo Pascal

GatisGatis Posts: 6Member
I'm trying to turn from QBasic to TurboPascal and I'd like to do some graphics programming, but i dont know how...
Below is one short part of my QBasic program, I'd like to know - can something like this be done in Pascal also? HOW it can be done?
If it's not too much please give me some short exmple...
You can contact me using e-mail also...

My e-mail is rajah@one.lv

Thank You very much...

'Here's an QBasic example
SCREEN 12 'puts screen to mode (640x480) x16 colors
DIM klucis(225) 'bitmap size (x*y)
FOR y = 1 TO 15 'how many rows of pixels does picture contain
FOR x = 1 TO 15 'how many columns of pixels it contain
READ klucis 'reads pixels line by line from DATA lines
PSET (x, y), klucis 'puts pixels on sscreen
NEXT
NEXT
GET (1, 1)-(15, 15), klucis 'puts image to memory and assigns a name

PUT (100,100),klucis, PSET 'Joy can change x,y and it puts image there

'Below is bitmap of image for reading&putting on screen
DATA 00,15,15,15,15,15,15,14,14,14,14,14,14,14,00
DATA 15,15,15,15,15,15,15,14,14,14,14,14,00,00,14
DATA 15,15,15,15,15,15,15,14,14,14,14,14,14,00,14
DATA 15,15,15,15,15,15,15,14,14,14,14,14,00,00,14
DATA 15,15,15,15,15,15,15,14,14,14,14,00,14,00,14
DATA 15,15,15,15,15,15,15,14,14,14,14,14,00,00,14
DATA 15,15,15,15,15,15,15,14,14,14,14,00,14,00,14
DATA 14,14,14,14,14,14,14,10,10,10,10,10,00,00,10
DATA 14,14,14,14,14,14,14,10,10,10,10,00,10,00,10
DATA 14,14,00,14,00,14,00,10,00,10,00,10,00,00,10
DATA 14,00,14,00,14,00,14,00,10,00,10,00,00,00,10
DATA 14,00,00,00,00,00,00,00,00,00,00,00,00,00,10
DATA 14,00,00,00,00,00,00,00,00,00,00,00,00,00,10
DATA 14,14,00,14,00,14,00,10,00,10,00,10,00,10,10
DATA 00,14,14,14,14,14,14,10,10,10,10,10,10,10,00


Comments

  • Phat NatPhat Nat Posts: 757Member
    : I'm trying to turn from QBasic to TurboPascal and I'd like to do some graphics programming, but i dont know how...
    : Below is one short part of my QBasic program, I'd like to know - can something like this be done in Pascal also? HOW it can be done?
    : If it's not too much please give me some short exmple...
    : You can contact me using e-mail also...
    :
    : My e-mail is rajah@one.lv
    :
    : Thank You very much...
    :
    : 'Here's an QBasic example
    : SCREEN 12 'puts screen to mode (640x480) x16 colors
    : DIM klucis(225) 'bitmap size (x*y)
    : FOR y = 1 TO 15 'how many rows of pixels does picture contain
    : FOR x = 1 TO 15 'how many columns of pixels it contain
    : READ klucis 'reads pixels line by line from DATA lines
    : PSET (x, y), klucis 'puts pixels on sscreen
    : NEXT
    : NEXT
    : GET (1, 1)-(15, 15), klucis 'puts image to memory and assigns a name
    :
    : PUT (100,100),klucis, PSET 'Joy can change x,y and it puts image there
    :
    : 'Below is bitmap of image for reading&putting on screen
    : DATA 00,15,15,15,15,15,15,14,14,14,14,14,14,14,00
    : DATA 15,15,15,15,15,15,15,14,14,14,14,14,00,00,14
    : DATA 15,15,15,15,15,15,15,14,14,14,14,14,14,00,14
    : DATA 15,15,15,15,15,15,15,14,14,14,14,14,00,00,14
    : DATA 15,15,15,15,15,15,15,14,14,14,14,00,14,00,14
    : DATA 15,15,15,15,15,15,15,14,14,14,14,14,00,00,14
    : DATA 15,15,15,15,15,15,15,14,14,14,14,00,14,00,14
    : DATA 14,14,14,14,14,14,14,10,10,10,10,10,00,00,10
    : DATA 14,14,14,14,14,14,14,10,10,10,10,00,10,00,10
    : DATA 14,14,00,14,00,14,00,10,00,10,00,10,00,00,10
    : DATA 14,00,14,00,14,00,14,00,10,00,10,00,00,00,10
    : DATA 14,00,00,00,00,00,00,00,00,00,00,00,00,00,10
    : DATA 14,00,00,00,00,00,00,00,00,00,00,00,00,00,10
    : DATA 14,14,00,14,00,14,00,10,00,10,00,10,00,10,10
    : DATA 00,14,14,14,14,14,14,10,10,10,10,10,10,10,00

    It can. There are numerous ways of doing it. First off, Pascal doesn't directly support the SCREEN 12 function, although you can set video modes using BGI (Borland Graphics Interface) or using assembly or another home made unit. Pascal works differently in that you can access memory directly instead of get/put/pset/etc. For Pascal you can just use:
    [code]
    Mem[:] := ;
    := Mem[:];
    [/code]

    Sorry, I just realized I'm making this really difficult. I don't use BGI units anymore (for years) due to speed and lack of options. I started translating your program, but my methods are a little confusing. I will leave what I did since no-one else has replied here, but you should look into "BGI" and look at the Turbo Pascal Help files on the GRAPH unit.

    Phat Nat



    Here's the start of what I was doing:

    [code]
    {Here's an Pascal example }
    PROGRAM Example;

    { Below is bitmap of image for reading&putting on screen }
    CONST
    klucis : Array[0..14,0..14] of Byte =
    ((00,15,15,15,15,15,15,14,14,14,14,14,14,14,00),
    (15,15,15,15,15,15,15,14,14,14,14,14,00,00,14),
    (15,15,15,15,15,15,15,14,14,14,14,14,14,00,14),
    (15,15,15,15,15,15,15,14,14,14,14,14,00,00,14),
    (15,15,15,15,15,15,15,14,14,14,14,00,14,00,14),
    (15,15,15,15,15,15,15,14,14,14,14,14,00,00,14),
    (15,15,15,15,15,15,15,14,14,14,14,00,14,00,14),
    (14,14,14,14,14,14,14,10,10,10,10,10,00,00,10),
    (14,14,14,14,14,14,14,10,10,10,10,00,10,00,10),
    (14,14,00,14,00,14,00,10,00,10,00,10,00,00,10),
    (14,00,14,00,14,00,14,00,10,00,10,00,00,00,10),
    (14,00,00,00,00,00,00,00,00,00,00,00,00,00,10),
    (14,00,00,00,00,00,00,00,00,00,00,00,00,00,10),
    (14,14,00,14,00,14,00,10,00,10,00,10,00,10,10),
    (00,14,14,14,14,14,14,10,10,10,10,10,10,10,00));

    VAR
    Data : Array[0..224] Of Byte;
    ScrWidth : Word;

    PROCEDURE Screen(Mode: Byte); Assembler;
    ASM
    Mov Ax, Mode
    Int $10 { Interrupt 10h }
    End;

    PROCEDURE Get(ScrX,ScrY : Word);
    VAR x,y : Word;
    Begin
    FOR y := 1 TO 15 { how many rows of pixels does picture contain }
    FOR x = 1 TO 15 { how many columns of pixels it contain }
    Data[x,y] := Mem[$A000:ScrX+ScrY*ScrWidth];
    End;

    PROCEDURE Put(ScrX,ScrY : Word);
    VAR x,y : Word;
    Begin
    FOR y := 1 TO 15 { how many rows of pixels does picture contain }
    FOR x = 1 TO 15 { how many columns of pixels it contain }
    Mem[$A000:x+y*ScrWidth] := Data[x,y];
    End;

    VAR
    x, y : Word; { 2-byte allowing 0-65535) }

    Begin
    ScrWidth := 320; { 640 pixels, 2 pixels per byte }
    SCREEN(12); { puts screen to mode (640x480) x16 colors }
    GET (1, 1); { puts image to memory and assigns a name }
    PUT (100,100) { Joy can change x,y and it puts image there }
    End.
    [/code]

Sign In or Register to comment.