summaryrefslogtreecommitdiff
path: root/src/bin/line_blend.c
blob: dedc471fc31a416c0635b5462ed19b3d25cc582e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#undef FNAME
#undef NAME
#undef ICON

/* metadata */
#define FNAME line_blend_start
#define NAME "Line Blend"
#define ICON "rect.png"

#ifndef PROTO
# ifndef UI
#  include "main.h"

/* standard var */
static int done = 0;
/* private data */
static Evas_Object *o_images[OBNUM];

/* setup */
static void _setup(void)
{
   int i;
   Evas_Object *o;
   srnd();
   for (i = 0; i < OBNUM; i++)
     {
	int r, g, b, a;

        o = eo_add(EVAS_OBJ_LINE_CLASS, evas);
	o_images[i] = o;
	a = (rnd()&0xff) / 2;
	r = ((rnd()&0xff) * a) / 255;
	g = ((rnd()&0xff) * a) / 255;
	b = ((rnd()&0xff) * a) / 255;
	eo_do(o,
	      evas_obj_color_set(r, g, b, a),
	      evas_obj_line_xy_set(((win_w / 2) * (rnd()&0xff)) / 255,
                                   ((win_h / 2) * (rnd()&0xff)) / 255,
                                   ((win_w / 2) * (rnd()&0xff)) / 255 + (win_w / 2),
                                   ((win_h / 2) * (rnd()&0xff)) / 255 + (win_h / 2)),
              evas_obj_visibility_set(EINA_TRUE));

        
     }
   done = 0;
}

/* cleanup */
static void _cleanup(void)
{
   int i;
   for (i = 0; i < OBNUM; i++) eo_del(o_images[i]);
}

#define PI (double) 3.141592654

static void
_rotate_point(Evas_Coord *ox, Evas_Coord *oy, int r)
{
   double d;
   double x, y;
   double angle;

   x = *ox - (win_w / 2);
   y = *oy - (win_h / 2);

   d = sqrt(x * x + y * y);

   angle = atan((double) y / (double) x);
   if (x < 0) angle -= PI;

   switch (r & 0x3)
     {
      case 0: angle += 1 * PI / 180; break;
      case 1: angle += -1 * PI / 180; break;
      case 2: angle += 7 * PI / 180; break;
      case 3: angle += -1 * PI / 180; break;
     }

   *ox =  d * cos(angle) + (win_w / 2);
   *oy =  d * sin(angle) + (win_h / 2);
}

/* loop - do things */
static void _loop(double t, int f)
{
   int i;
   Evas_Coord ox1, oy1, ox2, oy2;
   Evas_Object *o;

   for (i = 0; i < OBNUM; i++)
     {
        o = o_images[i];
        eo_do(o, evas_obj_line_xy_get(&ox1, &oy1, &ox2, &oy2));
             
        _rotate_point(&ox1, &oy1, i);
        _rotate_point(&ox2, &oy2, i);
        eo_do(o, evas_obj_line_xy_set(ox1, oy1, ox2, oy2));
     }
   FPS_STD(NAME);
}

/* prepend special key handlers if interactive (before STD) */
static void _key(char *key)
{
   KEY_STD;
}












/* template stuff - ignore */
# endif
#endif

#ifdef UI
_ui_menu_item_add(ICON, NAME, FNAME);
#endif

#ifdef PROTO
void FNAME(void);
#endif

#ifndef PROTO
# ifndef UI
void FNAME(void)
{
   ui_func_set(_key, _loop);
   _setup();
}
# endif
#endif
#undef FNAME
#undef NAME
#undef ICON