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
|
#include "m_pd.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
static t_class *ifs_class;
/*
* An interated function system music example
* a more general approach is needed.
*/
typedef struct _ifs {
t_object x_obj;
t_float R1,R2,S1,S2;
t_float T1[6],T2[6];
t_float A[6], B[6];
t_float C[6], D[6],P[6];
t_float x,y;
t_outlet *x_out,*y_out, *i_out;
} t_ifs;
void ifs_bang(t_ifs *x)
{
float r = ((float) rand())/RAND_MAX;
int i = 0;
while (r > x->P[i])
i++;
x->x = x->A[i]*x->x + x->B[i]*x->y + x->T1[i];
x->y = x->C[i]*x->x + x->D[i]*x->y + x->T2[i];
outlet_float(x->x_out,x->x);
outlet_float(x->y_out,x->y);
outlet_float(x->i_out,r);
}
void *ifs_new(t_floatarg f1)
{
x->nr_functions = 3;
t_float R1[6],R2[6],S1[6],S2[6];
t_ifs *x = (t_ifs *)pd_new(ifs_class);
t_int i;
t_float p = 1/x->nr_functions;
R1[0]=R1[1]=R1[2]=R1[3]=R1[4]=R1[5]= 1;
R2[0]=R2[1]=R2[2]=R2[3]=R2[4]=R2[5]= 0;
S1[0]=S1[1]=S1[2]=S1[3]=S1[4]=S1[5]= 0.5;//0.33333;
S2[0]=S2[1]=S2[2]=S2[3]=S2[4]=S2[5]= 1;//0.33333;
x->T1[0] = 0;
x->T2[0] = 2;
x->T1[1] = 1.5;
x->T2[1] = 1;
x->T1[2] = 1.5;
x->T2[2] = -1;
x->T1[3] = 0;
x->T2[3] = -2;
x->T1[4] = -1.5;
x->T2[4] = -1;
x->T1[5] = -1.5;
x->T2[5] = 1;
for (i = 0;i<6;i++) {
x->A[i] = S1[i]*cos(R1[i]);
x->B[i] = -S2[i]*sin(R2[i]);
x->C[i] = S1[i]*sin(R1[i]);
x->D[i] = S2[i]*cos(R2[i]);
x->P[i] = p*(i+1);
}
x->x = 0;
x->y = 0;
x->x_out = outlet_new(&x->x_obj,&s_float);
x->y_out = outlet_new(&x->x_obj,&s_float);
x->i_out = outlet_new(&x->x_obj,&s_float);
post("ifs initialized");
return (void *)x;
}
|