Jump to content


Photo

C Animation


  • Please log in to reply
2 replies to this topic

#1 Dragolux

Dragolux

    Young Padawan

  • Members
  • Pip
  • 123 posts
  • Gender:Male
  • Location:United States
  • Interests:I love computers! I love Photoshop, Flash, Blender, Firefox, I love, well, EVERYTHING!!<br /><br />:D

Posted 13 May 2008 - 09:35 AM

Hey all,

I've been trying to make a program that animates from an array in C, and I can't get it to work. The idea is to have a separate header file that stores all of the frames of the animation. (all of the frames are just text - ascii) Then in the main program, there is a function called playForward that plays the animation forward.

Here's the main file...

#include <stdio.h>
			 #include "frames.h"
			 
			 void playForward( char *frames );
			 
			 int main( void ) {
				 playForward( *bounce );
				 
				 getchar();
				 
				 return 0;
			 }
			 
			 void playForward( char *frames ) {
				  int i = 0;  /* outer counter */
				  int j = 0;  /* inner counter */
				  int k = 0;  /* double inner counter */
				  
				  for( i = 0; i < frameNum * frameHeight; i++ ) {
					   printf( "%s\n", &frames[ i ] );
				  }
				  
				  /*for( i = 1; i <= frameNum; i++ ) {
					   for( j = 0; j < frameHeight; j++ ) {
							//for( k = 1; k <= frameLength; k++ ) {
								 printf( "%s\n", &frames[ j ] );
							//}
							//printf( "\n" );
					   }
					   printf( "\n" );
				  }*/
			 }

...and here's the header file (frames.h)...

int frameNum = 5;
			 int frameHeight = 3;
			 int frameLength = 5;
			 
			 char *bounce[] = {
				  "*****",
				  "*	",
				  "*****",
				  
				  "*****",
				  " *   ",
				  "*****",
				  
				  "*****",
				  "  *  ",
				  "*****",
				  
				  "*****",
				  "   * ",
				  "*****",
				  
				  "*****",
				  "	*",
				  "*****",
				  };

As you can see, the animation is very simple, and I just want to figure out how to make it work.

This is the output I get when I run the program:

*****
		   ****
		   ***
		   **
		   *
		   
		   *
		   
		   
		   
		   
			*
		   *

But I want it to print this:

*****
	   *
	   *****
   
		 *****
	  *
		 *****
   
		 *****
	   *
		 *****
   
		 *****
		*
		 *****
   
		 *****
		 *
		 *****

(or something like that - this forum messes up the spacing in the code :) )

Does anyone know what the problem could be?

Thanks!

*bump*

Edited by rc69, 10 June 2008 - 12:55 AM.


#2 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 10 June 2008 - 12:56 AM

Don't bump, especially when you're still in the top 10...

My C is a bit rusty, but this should theoretically work. Before you try to change anything though, my mixing of pointer/array syntax was intentional, so though i make typos quite frequently, that wasn't one of them :(

#include <stdio.h>

int frameNum = 5;

char *bounce = {
	 "*****\n*	\n*****",
	 "*****\n *   \n*****",
	 "*****\n  *  \n*****",
	 "*****\n   * \n*****",
	 "*****\n	*\n*****"
};

void playForward(char *frames){
	int x;
	for(x=0; x < frameNum; x++){
		printf("%s\n", frames[x]);
	}
}

int main() {
	playForward(bounce);

	getchar();

	return 0;
}

Edited by rc69, 10 June 2008 - 01:01 AM.


#3 Dragolux

Dragolux

    Young Padawan

  • Members
  • Pip
  • 123 posts
  • Gender:Male
  • Location:United States
  • Interests:I love computers! I love Photoshop, Flash, Blender, Firefox, I love, well, EVERYTHING!!<br /><br />:D

Posted 10 June 2008 - 08:56 AM

Sorry about bumping - I didn't know what else to do (hey, it worked, didn't it? ;) ).

Anyway, thanks for the code, I'll check it out and see how it works.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users