switched to G_PI and RAND_FUNC()

* plug-ins/gimpressionist/*.[ch]: switched to G_PI and RAND_FUNC()
This commit is contained in:
Vidar Madsen/gimpressionist
1999-09-09 22:29:41 +00:00
parent 8bd9e29708
commit 361f314abe
6 changed files with 53 additions and 38 deletions

View File

@ -1,3 +1,7 @@
Fri Sep 10 00:28:34 CEST 1999 vidar@prosalg.no (Vidar Madsen)
* plug-ins/gimpressionist/*.[ch]: switched to G_PIs and RAND_FUNC()s
Thu Sep 9 15:12:36 PDT 1999 Manish Singh <yosh@gimp.org> Thu Sep 9 15:12:36 PDT 1999 Manish Singh <yosh@gimp.org>
* plug-ins/imagemap/imap_polygon.c: fix gccism * plug-ins/imagemap/imap_polygon.c: fix gccism

View File

@ -1,3 +1,14 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef SRAND_FUNC
#define SRAND_FUNC srand
#endif
#ifndef RAND_FUNC
#define RAND_FUNC rand
#endif
#include <gtk/gtk.h> #include <gtk/gtk.h>
#define PLUG_IN_NAME "plug_in_gimpressionist" #define PLUG_IN_NAME "plug_in_gimpressionist"
@ -11,13 +22,13 @@
#define MAXORIENTVECT 50 #define MAXORIENTVECT 50
#define MAXSIZEVECT 50 #define MAXSIZEVECT 50
#ifndef M_PI #ifndef G_PI
#define M_PI 3.14159265358979323846 #define G_PI 3.14159265358979323846
#endif /* M_PI */ #endif
#ifndef M_PI_2 #ifndef G_PI_2
#define M_PI_2 (M_PI / 2.0) #define G_PI_2 (G_PI / 2.0)
#endif /* M_PI_2 */ #endif
/* Type declaration and definitions */ /* Type declaration and definitions */

View File

@ -34,12 +34,12 @@ int numvect = 0;
double degtorad(double d) double degtorad(double d)
{ {
return d/180.0*M_PI; return d/180.0*G_PI;
} }
double radtodeg(double d) double radtodeg(double d)
{ {
double v = d/M_PI*180.0; double v = d/G_PI*180.0;
if(v < 0.0) v += 360; if(v < 0.0) v += 360;
return v; return v;
} }
@ -117,18 +117,18 @@ double getdir(double x, double y, int from)
} else if(vec[i].type == 1) { } else if(vec[i].type == 1) {
double a = atan2(vec[i].dy, vec[i].dx); double a = atan2(vec[i].dy, vec[i].dx);
a -= atan2(y-vec[i].y, x-vec[i].x); a -= atan2(y-vec[i].y, x-vec[i].x);
tx = sin(a+M_PI_2); tx = sin(a+G_PI_2);
ty = cos(a+M_PI_2); ty = cos(a+G_PI_2);
} else if(vec[i].type == 2) { } else if(vec[i].type == 2) {
double a = atan2(vec[i].dy, vec[i].dx); double a = atan2(vec[i].dy, vec[i].dx);
a += atan2(y-vec[i].y, x-vec[i].x); a += atan2(y-vec[i].y, x-vec[i].x);
tx = sin(a+M_PI_2); tx = sin(a+G_PI_2);
ty = cos(a+M_PI_2); ty = cos(a+G_PI_2);
} else if(vec[i].type == 3) { } else if(vec[i].type == 3) {
double a = atan2(vec[i].dy, vec[i].dx); double a = atan2(vec[i].dy, vec[i].dx);
a -= atan2(y-vec[i].y, x-vec[i].x)*2; a -= atan2(y-vec[i].y, x-vec[i].x)*2;
tx = sin(a+M_PI_2); tx = sin(a+G_PI_2);
ty = cos(a+M_PI_2); ty = cos(a+G_PI_2);
} }
dst = dist(x,y,vec[i].x,vec[i].y); dst = dist(x,y,vec[i].x,vec[i].y);

View File

@ -1,6 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include "gimpressionist.h"
#include "ppmtool.h" #include "ppmtool.h"
int pfix(int n) int pfix(int n)
@ -26,20 +27,20 @@ void mkplasma_sub(struct ppm *p, int x1, int x2, int y1, int y2, float turb)
ny = (y1+y2)/2; ny = (y1+y2)/2;
if(!PIXEL(y1,nx,r)) if(!PIXEL(y1,nx,r))
PIXEL(y1,nx,r) = pfix((PIXEL(y1,x1,r)+PIXEL(y1,x2,r))/2.0+ PIXEL(y1,nx,r) = pfix((PIXEL(y1,x1,r)+PIXEL(y1,x2,r))/2.0+
turb*(rand()%xr-xr/2.0)); turb*(RAND_FUNC()%xr-xr/2.0));
if(!PIXEL(y2,nx,r)) if(!PIXEL(y2,nx,r))
PIXEL(y2,nx,r) = pfix((PIXEL(y2,x1,r)+PIXEL(y2,x2,r))/2.0+ PIXEL(y2,nx,r) = pfix((PIXEL(y2,x1,r)+PIXEL(y2,x2,r))/2.0+
turb*(rand()%xr-xr/2.0)); turb*(RAND_FUNC()%xr-xr/2.0));
if(!PIXEL(ny,x1,r)) if(!PIXEL(ny,x1,r))
PIXEL(ny,x1,r) = pfix((PIXEL(y1,x1,r)+PIXEL(y2,x1,r))/2.0+ PIXEL(ny,x1,r) = pfix((PIXEL(y1,x1,r)+PIXEL(y2,x1,r))/2.0+
turb*(rand()%yr-yr/2.0)); turb*(RAND_FUNC()%yr-yr/2.0));
if(!PIXEL(ny,x2,r)) if(!PIXEL(ny,x2,r))
PIXEL(ny,x2,r) = pfix((PIXEL(y1,x2,r)+PIXEL(y2,x2,r))/2.0+ PIXEL(ny,x2,r) = pfix((PIXEL(y1,x2,r)+PIXEL(y2,x2,r))/2.0+
turb*(rand()%yr-yr/2.0)); turb*(RAND_FUNC()%yr-yr/2.0));
if(!PIXEL(ny,nx,r)) if(!PIXEL(ny,nx,r))
PIXEL(ny,nx,r) = PIXEL(ny,nx,r) =
pfix((PIXEL(y1,x1,r)+PIXEL(y1,x2,r)+PIXEL(y2,x1,r)+ pfix((PIXEL(y1,x1,r)+PIXEL(y1,x2,r)+PIXEL(y2,x1,r)+
PIXEL(y2,x2,r))/4.0+turb*(rand()%(xr+yr)/2.0-(xr+yr)/4.0)); PIXEL(y2,x2,r))/4.0+turb*(RAND_FUNC()%(xr+yr)/2.0-(xr+yr)/4.0));
if(xr>1) { if(xr>1) {
mkplasma_sub(p,x1,nx,y1,ny, turb); mkplasma_sub(p,x1,nx,y1,ny, turb);
@ -60,10 +61,10 @@ void mkplasma_red(struct ppm *p, float turb)
for(y = 0; y < p->height; y++) for(y = 0; y < p->height; y++)
PIXEL(y,x,0) = 0; PIXEL(y,x,0) = 0;
x--; y--; x--; y--;
PIXEL(0,0,0) = 1+rand()%255; PIXEL(0,0,0) = 1+RAND_FUNC()%255;
PIXEL(y,0,0) = 1+rand()%255; PIXEL(y,0,0) = 1+RAND_FUNC()%255;
PIXEL(0,x,0) = 1+rand()%255; PIXEL(0,x,0) = 1+RAND_FUNC()%255;
PIXEL(y,x,0) = 1+rand()%255; PIXEL(y,x,0) = 1+RAND_FUNC()%255;
mkplasma_sub(p, 0, x, 0, y, turb); mkplasma_sub(p, 0, x, 0, y, turb);
} }

View File

@ -332,7 +332,7 @@ void freerotate(struct ppm *p, double amount)
double nx, ny; double nx, ny;
double R, a; double R, a;
struct ppm tmp = {0,0,NULL}; struct ppm tmp = {0,0,NULL};
double f = amount*M_PI*2/360.0; double f = amount*G_PI*2/360.0;
int rowstride = p->width * 3; int rowstride = p->width * 3;
a = p->width/(float)p->height; a = p->width/(float)p->height;

View File

@ -123,7 +123,6 @@ int bestbrush(struct ppm *p, struct ppm *a, int tx, int ty,
} }
} }
dev /= thissum; dev /= thissum;
/* dev += rand() / (float)RAND_MAX * 0.05; */
if((best == -1) || (dev < bestdev)) { if((best == -1) || (dev < bestdev)) {
g_list_free(brlist); g_list_free(brlist);
@ -143,7 +142,7 @@ int bestbrush(struct ppm *p, struct ppm *a, int tx, int ty,
return 0; return 0;
} }
i = rand() % g_list_length(brlist); i = RAND_FUNC() % g_list_length(brlist);
best = (long)((g_list_nth(brlist,i))->data); best = (long)((g_list_nth(brlist,i))->data);
g_list_free(brlist); g_list_free(brlist);
@ -283,7 +282,7 @@ void repaint(struct ppm *p, struct ppm *a)
return; return;
} }
srand(time(NULL) + getpid()); SRAND_FUNC(time(NULL));
numbrush = runningvals.orientnum * runningvals.sizenum; numbrush = runningvals.orientnum * runningvals.sizenum;
startangle = runningvals.orientfirst; startangle = runningvals.orientfirst;
@ -465,7 +464,7 @@ void repaint(struct ppm *p, struct ppm *a)
for(y = 0; y < dirmap.height; y++) { for(y = 0; y < dirmap.height; y++) {
guchar *dstrow = &dirmap.col[y*dirmap.width*3]; guchar *dstrow = &dirmap.col[y*dirmap.width*3];
for(x = 0; x < dirmap.width; x++) { for(x = 0; x < dirmap.width; x++) {
dstrow[x*3] = (M_PI + atan2(cy-y, cx-x)) * 255.0 / (M_PI*2); dstrow[x*3] = (G_PI + atan2(cy-y, cx-x)) * 255.0 / (G_PI*2);
} }
} }
} else if(runningvals.orienttype == 4) { /* Flowing */ } else if(runningvals.orienttype == 4) { /* Flowing */
@ -526,7 +525,7 @@ void repaint(struct ppm *p, struct ppm *a)
for(y = 0; y < sizmap.height; y++) { for(y = 0; y < sizmap.height; y++) {
guchar *dstrow = &sizmap.col[y*sizmap.width*3]; guchar *dstrow = &sizmap.col[y*sizmap.width*3];
for(x = 0; x < sizmap.width; x++) { for(x = 0; x < sizmap.width; x++) {
dstrow[x*3] = (M_PI + atan2(cy-y, cx-x)) * 255.0 / (M_PI*2); dstrow[x*3] = (G_PI + atan2(cy-y, cx-x)) * 255.0 / (G_PI*2);
} }
} }
} else if(runningvals.sizetype == 4) { /* Flowing */ } else if(runningvals.sizetype == 4) { /* Flowing */
@ -593,7 +592,7 @@ void repaint(struct ppm *p, struct ppm *a)
} }
for(j = 0; j < i; j++) { for(j = 0; j < i; j++) {
int a, b; int a, b;
a = rand()%i; a = RAND_FUNC() % i;
b = xpos[j]; xpos[j] = xpos[a]; xpos[a] = b; b = xpos[j]; xpos[j] = xpos[a]; xpos[a] = b;
b = ypos[j]; ypos[j] = ypos[a]; ypos[a] = b; b = ypos[j]; ypos[j] = ypos[a]; ypos[a] = b;
} }
@ -621,14 +620,14 @@ void repaint(struct ppm *p, struct ppm *a)
} }
if(runningvals.placetype == 0) { if(runningvals.placetype == 0) {
tx = rand() % (tmp.width - maxbrushwidth) + maxbrushwidth/2; tx = RAND_FUNC() % (tmp.width - maxbrushwidth) + maxbrushwidth/2;
ty = rand() % (tmp.height - maxbrushheight) + maxbrushheight/2; ty = RAND_FUNC() % (tmp.height - maxbrushheight) + maxbrushheight/2;
} else if(runningvals.placetype == 1) { } else if(runningvals.placetype == 1) {
tx = xpos[i-1]; tx = xpos[i-1];
ty = ypos[i-1]; ty = ypos[i-1];
} }
if(runningvals.placecenter) { if(runningvals.placecenter) {
double z = rand()*0.75 / RAND_MAX; double z = RAND_FUNC() * 0.75 / RAND_MAX;
tx = tx * (1.0-z) + tmp.width/2 * z; tx = tx * (1.0-z) + tmp.width/2 * z;
ty = ty * (1.0-z) + tmp.height/2 * z; ty = ty * (1.0-z) + tmp.height/2 * z;
} }
@ -651,7 +650,7 @@ void repaint(struct ppm *p, struct ppm *a)
switch(runningvals.orienttype) { switch(runningvals.orienttype) {
case 2: /* Random */ case 2: /* Random */
on = rand() % runningvals.orientnum; on = RAND_FUNC() % runningvals.orientnum;
break; break;
case 0: /* Value */ case 0: /* Value */
case 1: /* Radius */ case 1: /* Radius */
@ -671,7 +670,7 @@ void repaint(struct ppm *p, struct ppm *a)
switch(runningvals.sizetype) { switch(runningvals.sizetype) {
case 2: /* Random */ case 2: /* Random */
sn = rand() % runningvals.sizenum; sn = RAND_FUNC() % runningvals.sizenum;
break; break;
case 0: /* Value */ case 0: /* Value */
case 1: /* Radius */ case 1: /* Radius */
@ -746,9 +745,9 @@ void repaint(struct ppm *p, struct ppm *a)
} }
if(runningvals.colornoise > 0.0) { if(runningvals.colornoise > 0.0) {
double v = runningvals.colornoise; double v = runningvals.colornoise;
r = r + rand() / (float)RAND_MAX * v - v/2; r = r + RAND_FUNC() / (float)RAND_MAX * v - v/2;
g = g + rand() / (float)RAND_MAX * v - v/2; g = g + RAND_FUNC() / (float)RAND_MAX * v - v/2;
b = b + rand() / (float)RAND_MAX * v - v/2; b = b + RAND_FUNC() / (float)RAND_MAX * v - v/2;
if(r < 0) r = 0; else if(r > 255) r = 255; if(r < 0) r = 0; else if(r > 255) r = 255;
if(g < 0) g = 0; else if(g > 255) g = 255; if(g < 0) g = 0; else if(g > 255) g = 255;
if(b < 0) b = 0; else if(b > 255) b = 255; if(b < 0) b = 0; else if(b > 255) b = 255;