1 #include <math.h>
2 #include <tina/sys.h>
3 #include <tina/sysfuncs.h>
4 #include <tina/math.h>
5 #include <tina/mathfuncs.h>
6 #include <tina/vision.h>
7
8 Imrect *imf_spiral(int x_centre, int y_centre, int height, int width,
9 double overtake, double loops)
10 {
11
12 /* Image creation tool for making spirals. Angle is measured with reference to the
13 positive x-axis from the centre.
14 This is version 3, discrete solution. PAB 17 / 5 / 2001. */
15
16 Imrect *im;
17 Imregion *roi;
18 float *row=fvector_alloc(0, width);
19 float radius, radius_a, radius_b, theta, temp, x, y;
20 float k_a, k_b;
21 int i, j, flag;
22
23 if(loops<0||overtake<0)
24 {
25 error("Positive parameters only", warning);
26 fvector_free((void *) row, 0);
27 return;
28 }
29
30 im = im_alloc(height, width, (Imregion *)NULL, float_v);
31 if(im==NULL)
32 {
33 return;
34 }
35 roi = im->region;
36
37 k_a = exp(log(width/2) / (TWOPI*loops));
38 k_b = pow(k_a, ((overtake+1)/overtake));
39
40 for(i=roi->ly; i<roi->uy; i++)
41 {
42 for(j=roi->lx; j<roi->ux; j++)
43 {
44 x = j-x_centre;
45 y = y_centre-i;
46 radius = sqrt(sqr(x)+sqr(y));
47 theta = atan2(y, x);
48 if(y<0) theta = TWOPI+theta;
49
50 flag=0;
51 while(flag==0)
52 {
53 radius_a = (pow(k_a, theta));
54 radius_b = (pow(k_b, theta))+1;
55
56 /* Note: the plus one in the previous
57 line is used to get the inner parts of the
58 spiral fully painted, by ensuring that
59 there is always at least a one pixel gap
60 between the two radii:
61 equivalent to an angular offset on
62 the outer spiral */
63
64 if(radius_a<=radius&&radius_b>=radius)
65 {
66 row[j]=255.0;
67 flag=1;
68 }
69 if(radius<radius_a&&radius<radius_b)
70 {
71 row[j]=0.0;
72 flag=1;
73 }
74 if(radius>radius_a&&radius>radius_b)
75 {
76 theta += TWOPI;
77 }
78 }
79 }
80 im_put_rowf(row, im, i, 0, width);
81 }
82
83 fvector_free((void *) row, 0);
84 return(im);
85 }
86
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.