PDA

View Full Version : sine wave graphics source wanted


dale
02-28-2004, 06:29 PM
Hello,

I am looking for the source code to a program
that will display a sine wave(s) across the middle
of the computer screen. Preferably in C or DOS C,
Anyone know where I could find something like that ?

If you want to e-mail me where I might find source
code like that, thats ok too.

Thank You,
Dale

Arthur J. O'Dwyer
02-29-2004, 12:39 AM
On Sun, 29 Feb 2004, dale wrote: I am looking for the source code to a program that will display a sine wave(s) across the middle of the computer screen. Preferably in C or DOS C, Anyone know where I could find something like that ?

Here's some really ancient Turbo C code that implements a
discrete sine algorithm probably stolen from HAKMEM. It
works on my computer. :)
It displays two stationary sine curves: one computed the
ordinary way, and one computed using the HAKMEM method. (They're
very close together.) It wouldn't be too hard to make the
curves move.
As for having the program run on startup: the easiest way
would be to add a line to AUTOEXEC.BAT. ;-)

The code below is free for any and all purposes.

#pragma inline

#include <math.h>
#include <conio.h>

const double pi = 3.1416;

int SineTable[256];

void putpixel(int y, int x, unsigned char col)
{
asm mov ax, 0xA000
asm mov es, ax
asm mov al, col
asm mov bx, y
asm xchg bh, bl /* bx = 256*y */
asm mov di, bx
asm mov cl, 2
asm shr di, cl /* di = 64*y */
asm add di, bx
asm add di, x /* di = 320*y + x */

asm mov [es:di], al
}

void initSines()
{
int s;
int s1 = 0;
int s2 = 402;
register int i;

for (i=0; i < 256; i++)
{
/* s = (2 - 1.0/2048 - 1.0/8192) * s2 - s1;
s1 = s2;
s2 = s;
SineTable[i] = s; */

asm mov ax, s2
asm mov bx, ax
asm shl bx, 1
asm mov cl, 11
asm sar ax, cl
asm sub bx, ax
asm sar ax, 1
asm sar ax, 1
asm add ax, s1
asm sub bx, ax

asm mov ax, s2
asm mov s1, ax
asm mov s2, bx

SineTable[i] = s2;
}
}

int main(void)
{
int i;

asm mov ax, 19
asm int 0x10

initSines();
for (i=0; i < 256; i++)
{
putpixel(100 + sin(i*pi/128) * 100, i, 11);
putpixel(90 + SineTable[i] / 163.84, i, 15);
}

while (!kbhit());
asm mov ax, 3
asm int 0x10
return 0;
}


MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service