Important alert: (current site time 12/20/2014 11:04:39 AM EDT)
 

VB icon

snowing effect (very realistic)

Email
Submitted on: 3/5/2005 3:52:00 PM
By: VAMMM 
Level: Intermediate
User Rating: By 1 Users
Compatibility: C, Borland C++
Views: 2938
 
     this program simulate a snowing effect. it can be implemented to directx or opengl since it uses just a couple of graphics functions. clear screen & put pixel.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :snowing effect (very realistic)
//**************************************
needs egavga.bgi file to be in the same directory
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: snowing effect (very realistic)
// Description:this program simulate a snowing effect. it can be implemented to directx or opengl since it uses just a couple of graphics functions. clear screen & put pixel.
// By: VAMMM
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=9054&lngWId=3//for details.//**************************************

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <TIME.H>
#include <dos.h>
#define pix1 750//change to the number of stars to be displayed
#define pix3 pix1/3
int i,xmax,ymax,pixx[pix1],pixy[pix1],pixc[pix1];
void main(void){
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
 printf("Graphics error: %s\n", grapherrormsg(errorcode));
 printf("Press any key to halt:");
 getch();
 exit(1); /* return with error code */
}
xmax=getmaxx();
ymax=getmaxy();
randomize();
for(i=0;i<pix3;i=i+3){
 pixx[i]=random(xmax);
 pixy[i]=random(ymax);
 pixc[i]=EGA_WHITE;
 pixx[i+1]=random(xmax);
 pixy[i+1]=random(ymax);
 pixc[i+1]=EGA_LIGHTGRAY;
 pixx[i+2]=random(xmax);
 pixy[i+2]=random(ymax);
 pixc[i+2]=EGA_WHITE;
}
do{
 cleardevice();
 for(i=0;i<pix1;i++){ //i+=2
	putpixel(pixx[i],pixy[i],pixc[i]);
	//putpixel(pixx[i+1],pixy[i+1],pixc[i+1]);
	if (pixx[i]>=xmax) pixx[i]=0;
	if (pixy[i]>=ymax) pixy[i]=0;
	//if (pixx[i+1]>=xmax) pixx[i+1]=0;
	//if (pixy[i+1]>=ymax) pixy[i+1]=0;
	pixx[i]+=((0)+random(2));
	pixy[i]+=((1)+random(3));
	//pixx[i+1]+=((1)+random(1));
	//pixy[i+1]+=((1)+random(2));
 }
 delay(10);
}while(!kbhit());
/* clean up */
closegraph();
}


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

12/18/2009 5:09:48 AM

i cant get it to run ! help me plz
error is :
Error 1 fatal error C1083: Cannot open include file: 'graphics.h': No such file or directory c:\users\pariesa\documents\visual studio 2008\projects\snow\snow\snow.cpp 3

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.