Mercurial > sdl-ios-xcode
annotate XCodeiPhoneOS/Demos/src/common.c @ 2385:0705e8ebe951 gsoc2008_iphone
Rectangles demo (SDL_RenderFill)
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Fri, 18 Jul 2008 20:52:18 +0000 |
parents | d3952f445f4d |
children |
rev | line source |
---|---|
2381
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
1 /* |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
2 * common.c |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
3 * written by Holmes Futrell |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
4 * use however you want |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
5 */ |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
6 |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
7 #include "common.h" |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
8 #include "SDL.h" |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
9 #include <stdlib.h> |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
10 |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
11 /* |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
12 Produces a random int x, min <= x <= max |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
13 following a uniform distribution |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
14 */ |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
15 int randomInt(int min, int max) { |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
16 return min + rand() % (max - min + 1); |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
17 } |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
18 /* |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
19 Produces a random float x, min <= x <= max |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
20 following a uniform distribution |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
21 */ |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
22 float randomFloat(float min, float max) { |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
23 return rand() / (float)RAND_MAX * (max - min) + min; |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
24 } |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
25 |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
26 void fatalError(const char *string) { |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
27 printf("%s: %s\n", string, SDL_GetError()); |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
28 exit(1); |
d3952f445f4d
Files used by all demos (random numbers, screen size, etc)
Holmes Futrell <hfutrell@umail.ucsb.edu>
parents:
diff
changeset
|
29 } |