~ubuntu-branches/debian/sid/pngphoon/sid

« back to all changes in this revision

Viewing changes to main.c

  • Committer: Bazaar Package Importer
  • Author(s): Meike Reichle
  • Date: 2007-04-13 20:13:16 UTC
  • Revision ID: james.westby@ubuntu.com-20070413201316-f1hdhugbwd9ahn0x
Tags: upstream-0.0.20060109
ImportĀ upstreamĀ versionĀ 0.0.20060109

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "image.h"
 
3
#include "moon.h"
 
4
#include "pngwrite.h"
 
5
#include "stars.h"
 
6
 
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
 
9
#include <unistd.h>
 
10
 
 
11
static inline void usage( char *name )
 
12
{
 
13
   char *base = name;
 
14
   char *c;
 
15
   
 
16
   for( c = name+1; *c; c++)
 
17
   {
 
18
      if( *(c-1) == '/' ) base = c; 
 
19
   }
 
20
   
 
21
   printf( "usage: %s options (* = mandatory)\n"
 
22
           "\t-w # width*\n"
 
23
           "\t-h # height*\n"
 
24
           "\t-f $ filename*\n"
 
25
           "\t-x # number of moons in x axis (for multihead configurations)\n"
 
26
           "\t-y # number of moons in y axis (for multihead configurations)\n"
 
27
           "\t-s # star density\n"
 
28
           "\t-b   black (no earthlight)\n", base );
 
29
   exit(0);
 
30
}
 
31
 
 
32
int main( int argc, char *argv[] )
 
33
{
 
34
   int     width     = 0;
 
35
   int     height    = 0;
 
36
   int     xmoons    = 1;
 
37
   int     ymoons    = 1;
 
38
   int     stars     = 50;
 
39
   char    *filename = NULL;
 
40
   int     black     = 0;
 
41
   image_t *image    = NULL;
 
42
   moon_t  *moon     = NULL;
 
43
   int     c;
 
44
   int     x;
 
45
   int     y;
 
46
   
 
47
   opterr = 0;
 
48
   
 
49
   if( argc == 1 )
 
50
   {
 
51
      usage( argv[0] );
 
52
   }
 
53
   
 
54
   while ((c = getopt (argc, argv, "w:h:x:y:s:f:b")) != EOF)
 
55
   {
 
56
      switch (c)
 
57
      {
 
58
         case 'w':
 
59
            width    = strtol( optarg, NULL, 0 );
 
60
            break;
 
61
         case 'h':
 
62
            height   = strtol( optarg, NULL, 0 );
 
63
            break;
 
64
         case 'x':
 
65
            xmoons   = strtol( optarg, NULL, 0 );
 
66
            break;
 
67
         case 'y':
 
68
            ymoons   = strtol( optarg, NULL, 0 );
 
69
            break;
 
70
         case 's':
 
71
            stars    = strtol( optarg, NULL, 0 );
 
72
            break;
 
73
         case 'f':
 
74
            filename = optarg;
 
75
            break;
 
76
         case 'b':
 
77
            black    = 1;
 
78
            break;
 
79
         default:
 
80
            printf("unknown option: '%c'\n", c);
 
81
      }
 
82
   }
 
83
   
 
84
   if( !width || !height || !filename )
 
85
   {
 
86
      printf( "you need to specify at least width, height and filename\n" );
 
87
   }
 
88
   
 
89
   moon = mooncreate();
 
90
   
 
91
   image = imagecreate( width, height );
 
92
   if( (width  < (moon->width)  * xmoons) ||
 
93
       (height < (moon->height) * ymoons) )
 
94
   {
 
95
      printf("image too small to fit moon%s, creating stars only\n",
 
96
             (xmoons * ymoons > 1) ? "s" : "");
 
97
      scarymonster( image, stars * 2 );
 
98
   }
 
99
   else
 
100
   {
 
101
      scarymonster( image, stars );
 
102
      for( y = (height/ymoons)/2; y < height; y += (height/ymoons) )
 
103
      {
 
104
         for( x = (width/xmoons)/2; x < width; x += (width/xmoons) )
 
105
         {
 
106
            mooncopy( image, moon, x, y, black );
 
107
         }
 
108
      }
 
109
   }
 
110
   pngwrite( image, filename );
 
111
   imagedestroy( image );
 
112
   moondestroy( moon );
 
113
   
 
114
   return 0;
 
115
}