#### Howdy, Stranger!

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

#### 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 Programmers 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 it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# [graphics c] how to draw a figure with graphics.h??

• Posts: 12Member
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
· ·
• Posts: 26Member
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
#include
#include
#include
#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);
}
· ·
• Posts: 1,018Member
: 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

[green]
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.
[/green]

· ·
• Posts: 26Member

: [green]
: 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.
: [/green]

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 =)
· ·
• Posts: 12Member
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

· ·
• Posts: 12Member
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

· ·
• Posts: 1,018Member
: 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 =)
:
[green]
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.
[/green]

[code]
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:palpalette.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
[/code]
· ·
• Posts: 26Member
: : 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 =)
: :
: [green]
: 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?
· ·
• Posts: 26Member
: 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.
· ·
• Posts: 1,018Member
: 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
:
[green]
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.
[/green]

· ·