C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28691
Number of posts: 94711

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
[graphics c] how to draw a figure with graphics.h?? Posted by firas_tn on 30 Mar 2006 at 2:52 AM
Hi there
I really need your help, I have a project which simule soda distributor with using turbo c 3.0 and the lib graphics.h, i know how to draw many things like rectangle,circle... but the problem that I want to draw like a soda bottle which is coloured , i made all possible combinations but i didn't get any result unfortunately, is here someone who can help me please?
thanks
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by Lundin on 30 Mar 2006 at 3:07 AM
: Hi there
: I really need your help, I have a project which simule soda distributor with using turbo c 3.0 and the lib graphics.h, i know how to draw many things like rectangle,circle... but the problem that I want to draw like a soda bottle which is coloured , i made all possible combinations but i didn't get any result unfortunately, is here someone who can help me please?
: thanks
:


Check the help for setcolor().
For a list of functions, check the help for graphics.h.
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by firas_tn on 30 Mar 2006 at 3:31 AM
thank u for your reply but i checked the help included in turbo c 3.0 but it's not complete, can you tell me about some tutorials about graphic programming in c if you know some url ?

Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by Lundin on 30 Mar 2006 at 3:46 AM
: thank u for your reply but i checked the help included in turbo c 3.0 but it's not complete, can you tell me about some tutorials about graphic programming in c if you know some url ?
:
:


The help in TC is very good, everything you need is there, including code examples. Just copy and paste their examples and run them.

Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by AsmGuru62 on 30 Mar 2006 at 4:33 AM
: : thank u for your reply but i checked the help included in turbo c 3.0 but it's not complete, can you tell me about some tutorials about graphic programming in c if you know some url ?
: :
: :
:
:
: The help in TC is very good, everything you need is there, including code examples. Just copy and paste their examples and run them.
:
:
Do you have this line in your code?
#include <graphics.h>

If so, put a cursor on "graphics" and press CTRL+F1 combination - this should give you the list of ALL possible functions inside graphics.h and code samples for them once you go deeper into Help system.

Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by weapon__x on 30 Mar 2006 at 9:47 PM
its so nice to know that there's still some using TC 3.0 (or TC++), nowadays. with all the WYSIWYG/newer IDEs, i really do think having to hardcode the oldfashion way is good foundation in programming (personally speaking). just plain text editor and compiler, no autocomplete/functionhighlight.
sometimes it makes me wonder what happened to BGI programming and the likes with all this new ways of programming in the Gaming production. we've sure come quite far from Pacman to Counterstrike, from commandprompts to gui, it kinda makes me feel old, and come to think of it i'm only in my early 20's.


it happens...

baboy... baboy...

weaps

Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by firas_tn on 31 Mar 2006 at 1:24 PM
yeah it's interesting to program with tc 3.0 unless it's old :)
but for me it's an obligation because we study now graphics programmation in c so i must do that but if i had the choice i woul prefer to program with c++ or something like this it's more easy i think and there are a lot of library to use not like tc u see


Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by shaolin007 on 31 Mar 2006 at 4:25 PM
: its so nice to know that there's still some using TC 3.0 (or TC++), nowadays. with all the WYSIWYG/newer IDEs, i really do think having to hardcode the oldfashion way is good foundation in programming (personally speaking). just plain text editor and compiler, no autocomplete/functionhighlight.
: sometimes it makes me wonder what happened to BGI programming and the likes with all this new ways of programming in the Gaming production. we've sure come quite far from Pacman to Counterstrike, from commandprompts to gui, it kinda makes me feel old, and come to think of it i'm only in my early 20's.
:
:
: it happens...
:
: baboy... baboy...
:
: weaps
:
:

BGI ughh! Quicker to do your own routines in assembler. Nah, you are not old at all. Give me a call when you get 34.


Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by AsmGuru62 on 1 Apr 2006 at 9:10 PM
I have done pretty huge programs with TC 3.0 in my time - early 90s. All kinds: editors, machine controllers, other stuff... - you name it.
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by firas_tn on 2 Apr 2006 at 4:41 AM
indeed, I have a project which is simulating soda automatic distributor, I will do two menus : one for administrator of the distributor who can modify the quantity of bottles and their prices and a menu for customer who can choose which soda and the pieces of money they want to introduce to get the soda, I think it's clear that project for you now
and thanks for your help
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by weapon__x on 4 Apr 2006 at 7:31 PM
: I have done pretty huge programs with TC 3.0 in my time - early 90s. All kinds: editors, machine controllers, other stuff... - you name it.
:


yup, same here, ( though i'm limited to DOS environ those days... inport, outport, inportb, outportb, asm, interrupts, TSR's). parking area monitoring, robotics, alarm systems. way back then i see my graphics as cool, many would frown on those now a days.



Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by tylerhadfun on 5 Apr 2006 at 3:05 PM
This message was edited by tylerhadfun at 2006-4-5 15:5:55


:
: yup, same here, ( though i'm limited to DOS environ those days... inport, outport, inportb, outportb, asm, interrupts, TSR's). parking area monitoring, robotics, alarm systems. way back then i see my graphics as cool, many would frown on those now a days.
:



lol, thats what i use, and i dont consider my graphics good, but im only in highschool, and i know thing that my fellow students dont know about graphics. but i like the cheep graphics that i make lol =)


Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by firas_tn on 6 Apr 2006 at 12:08 PM
hey weapon x
you said you have developed many graphics program with tc 3.0 can you send me some of yours if it's possible to see them?
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by tylerhadfun on 2 Apr 2006 at 4:27 PM
i dont kno if any1 answered u yet, but there is a way to make cheep graphics. look at the setpalette function in the help. basically, u set the numbers 0-15 to a 64 bit color (0-63) and each 64 bit color is different

this code can show u all the colors, its pretty simple. anyways, after u have set the colors, use a 2-d integer. for example, soda[50][100], this is an integer that is 50 down and 100 accros. now, do
soda[50][100]={
0,1,2,0,0,2,0,0,3,...
};
and that will set the value of all of that integer (u must have all spaces filled for it to work correctly) and then say,
for(int i=o;i<100;i++){
for(int j=0;j<50;j++){
if(soda[j][i]==1){putpixel(i+100,j+100,COLOR1);}
/*COLOR1 is just an example, the vallue of COLOR1 would be set by the setpalette function*/
}
}

if thats 2 confusing, tell me what part u have troubles on!

email me at tylermailonly@hotmail.com (its the best way to contact me)

good luck!

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <graphics.h>
#include "tools.h"
int main(){
closegraph();
IGM();
cleardevice();
setbkcolor(0);
int i=0,k,c1=1,c2=2,c3=3,color1=1,color2=2,color3=3;
char s[50];
setpalette(c1,color1);
setpalette(c2,color2);
setpalette(c3,color3);
settextstyle(2,0,5);
do{
k=getkey();
switch(k){
case 72 : color1--; color2--; color3--; setpalette(c1,color1);
setpalette(c2,color2); setpalette(c3,color3); cleardevice(); break;
case 80 : color1++; color2++; color3++; setpalette(c1,color1);
setpalette(c2,color2); setpalette(c3,color3); cleardevice(); break;
}
setcolor(15);
sprintf(s,"%-3i--------",color1); outtextxy(320-85,240-68,s);
sprintf(s,"%-3i--------",color2); outtextxy(320-85,240-8,s);
sprintf(s,"%-3i--------",color3); outtextxy(320-85,240+52,s);
setfillstyle(1,c1); bar(350-20,180-20,350+20,180+20);
setfillstyle(1,c2); bar(350-20,240-20,350+20,240+20);
setfillstyle(1,c3); bar(350-20,300-20,350+20,300+20);
}while(k!=13);
}
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by shaolin007 on 2 Apr 2006 at 10:14 PM
: i dont kno if any1 answered u yet, but there is a way to make cheep graphics. look at the setpalette function in the help. basically, u set the numbers 0-15 to a 64 bit color (0-63) and each 64 bit color is different


Each palette entry consist of 3 bytes, rgb. The value 0-63 represent the intensity of each color written to the palette port in 3 byte increments. I wrote a program, in assembler, that dumps the palette table, which is 768 bytes or 256 colors, to a file. You can do some neat tricks by manipulating the palette and writing directly to the port.


Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by tylerhadfun on 3 Apr 2006 at 9:28 AM

:
: Each palette entry consist of 3 bytes, rgb. The value 0-63 represent the intensity of each color written to the palette port in 3 byte increments. I wrote a program, in assembler, that dumps the palette table, which is 768 bytes or 256 colors, to a file. You can do some neat tricks by manipulating the palette and writing directly to the port.
:


hey, could u do that in borland turbo c++ 3.0? if you could, i would much appriciate a sample code. plz! thanx in advance, and i think im learning as much as the guy who wrote this post in the first place =)
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by shaolin007 on 3 Apr 2006 at 1:06 PM
: hey, could u do that in borland turbo c++ 3.0? if you could, i would much appriciate a sample code. plz! thanx in advance, and i think im learning as much as the guy who wrote this post in the first place =)
:

I could but I don't have borland turbo C 3.0. I'll post my assembler source though. All you have to do is download FASM windows IDE version and compile. It will generate a .com file that when executed will create a directory called "PAL" and a file called "Palette.pal" in that directory. It will fail if you already have that directory on your disk.


use16                      ;create a .com executable
ORG 100h 

xor al, al                 ;zero register AL for use
mov cx, 768                
cld
mov di, palette
mov dx, 03c8h              ;set the palette index to zero
out dx, al                


Copy_Palette:

cmp cx, 0                 ;cx==768 and is decremented by 3-
                          ;each loop cycle 
je done                   ;if cx==0 then we are done writing to palette-
mov dx, 03c9h             ;array
insb
insb                      ;write 3 bytes to palette array
insb                      ;after the 3rd byte the palette index is-
inc al                    ;automatically incremented
sub cx, 3
jmp Copy_Palette


done:
    mov ah, 39h
    mov dx, pal             ;create directory
    int 21h
    jc Write_Error

    mov ah, 03ch
    mov dx, palette_file    ;create palette file
    mov cx, 0
    int 21h
    jc Write_Error
    mov [palette_handle], ax

    mov ah, 40h
    mov bx, [palette_handle] ;write date to palette file
    mov cx, 768
    mov dx, palette
    int 21h
    jc Write_Error
    cmp ax, 768              ;did it write to file 768 bytes?
    je WriteOK                

    mov ah, 03eh
    mov bx, [palette_handle]  ;close file
    int 21h
    jc Close_Error

;ERROR CODES

Close_Error:
mov dx, close
mov ah, 9
int 21h
jmp _End


Write_Error:
mov dx, error
mov ah, 9
int 21h
jmp _End

;SUCESS

WriteOK:
mov dx, writeok
mov ah, 9
int 21h


_End:
    mov ah, 7
    int 21h
    mov ax, 3
    int 10h
    mov ax, 4c00h
    int 21h

;DATA AREA

palette db 768 dup(0)
palette_file db "C:\pal\palette.pal",0
palette_handle dw 0
error db "Write failed!",13, 10, '$'
writeok db "768bytes written!",13,10,'$'
pal db "\pal",0
close db "Couldn't Close file!",0 

Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by tylerhadfun on 3 Apr 2006 at 2:10 PM
: : hey, could u do that in borland turbo c++ 3.0? if you could, i would much appriciate a sample code. plz! thanx in advance, and i think im learning as much as the guy who wrote this post in the first place =)
: :
:
: I could but I don't have borland turbo C 3.0. I'll post my assembler source though. All you have to do is download FASM windows IDE version and compile. It will generate a .com file that when executed will create a directory called "PAL" and a file called "Palette.pal" in that directory. It will fail if you already have that directory on your disk.

hey look, i downloaded it and i dont know how to run anyprograms because when i click on the FASM.EXE it does nothing. anyways, im not sure that i have all the minimum requirements, even though i have a windows XP, i dont think i have some of the files i need like win32. what should i do?
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by tylerhadfun on 3 Apr 2006 at 2:17 PM
: hey look, i downloaded it and i dont know how to run anyprograms because when i click on the FASM.EXE it does nothing. anyways, im not sure that i have all the minimum requirements, even though i have a windows XP, i dont think i have some of the files i need like win32. what should i do?
:
ok, never mind, i got the program to run, however, i cant run anything because i dont have the win32. and also,i was able 2 run ur program and it didnt do anything exept say 758 bites writen or something like that.
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by firas_tn on 3 Apr 2006 at 10:23 AM
thanks you very much for you help
I'll test this code and i'll tell you if it's ok or no
thanks a lot

Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by firas_tn on 3 Apr 2006 at 10:32 AM
I think that the bib "tools.h" must be in the include directory can you send it to me Tyler? you cand send it to me by email if it's possible
thanks in advance

Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by Rana ishtiaq on 2 Apr 2006 at 2:41 AM
Hi my dear brother i am also using Turbo C++ and now a days i a also trying to make a project. if you send me your email. then i can help you in this regard. i shall send you the code which i have made in my application. and after studying it you can make your desired program.
Do not worry about it. when i start it i also seems me very difficult but i do a lot with out any teacher.i am waiting for your reply.
mine email address is imtiaztkd@hotmail.com or imtiaztkd@yahoo.com
i mine wait starts now.
be happy all the time
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by firas_tn on 2 Apr 2006 at 4:35 AM
hi thanks a lot for your reply
here's my email adress, you can send me your source code at it: firas.jenhani@hexabyte.tn
I'm waiting for your reply
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by shaolin007 on 3 Apr 2006 at 4:37 PM
: Hi there
: I really need your help, I have a project which simule soda distributor with using turbo c 3.0 and the lib graphics.h, i know how to draw many things like rectangle,circle... but the problem that I want to draw like a soda bottle which is coloured , i made all possible combinations but i didn't get any result unfortunately, is here someone who can help me please?
: thanks
:

If it said 768 bytes written then check your C: drive for a directory called PAL. There you will find the file. You don't need any windows API's to run this program. It is all 16bit.


Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by tylerhadfun on 3 Apr 2006 at 5:07 PM
: : Hi there
: : I really need your help, I have a project which simule soda distributor with using turbo c 3.0 and the lib graphics.h, i know how to draw many things like rectangle,circle... but the problem that I want to draw like a soda bottle which is coloured , i made all possible combinations but i didn't get any result unfortunately, is here someone who can help me please?
: : thanks
: :
:
: If it said 768 bytes written then check your C: drive for a directory called PAL. There you will find the file. You don't need any windows API's to run this program. It is all 16bit.
:

:
:
hey it says i need something to open it with, umm, and i used the FASM and it doesnt do anything, what should i use to open it with?

Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by shaolin007 on 3 Apr 2006 at 5:23 PM
: : : Hi there
: : : I really need your help, I have a project which simule soda distributor with using turbo c 3.0 and the lib graphics.h, i know how to draw many things like rectangle,circle... but the problem that I want to draw like a soda bottle which is coloured , i made all possible combinations but i didn't get any result unfortunately, is here someone who can help me please?
: : : thanks
: : :
: :
: : If it said 768 bytes written then check your C: drive for a directory called PAL. There you will find the file. You don't need any windows API's to run this program. It is all 16bit.
: :

: :
: :
: hey it says i need something to open it with, umm, and i used the FASM and it doesnt do anything, what should i use to open it with?
:
:

I hope your kidding right? View it in a hex editor if your not. All it is, is a dump of the palette.

Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by tylerhadfun on 3 Apr 2006 at 5:32 PM

:
: I hope your kidding right? View it in a hex editor if your not. All it is, is a dump of the palette.
:


look, im only a beginner, so what is a hex editor? is it the FASM? i mean, im sorry it sounds stupid, but i dont kno what that is =(.
Report
Re: [graphics c] how to draw a figure with graphics.h?? Posted by shaolin007 on 4 Apr 2006 at 8:05 AM
:
: :
: : I hope your kidding right? View it in a hex editor if your not. All it is, is a dump of the palette.
: :

:
: look, im only a beginner, so what is a hex editor? is it the FASM? i mean, im sorry it sounds stupid, but i dont kno what that is =(.
:

FASM is an assembler/compiler. Hex editor can view files in hex format so you can modify them or do what ever. FHRED is a free hex editor I use and can be found by googling.


1 2  Next



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.