@@ -38,9 +38,11 @@ function setup() {
3838 textSize ( 20 * t )
3939 textFont ( 'Consolas' )
4040 g . set = g . attrs [ 0 ]
41+ g . seti = 0
4142 g . addr = 0
4243 g . edit = 1
4344 g . e = 0
45+ g . me = 4
4446 g . col = 1
4547 g . excl = 0
4648 g . excn = 0
@@ -52,99 +54,144 @@ function setup() {
5254 g . shift = 0
5355}
5456
57+ //Iteration Modes
58+ function itLI ( ) {
59+ r0 = sqrt ( g . t . x * g . t . x + g . t . y * g . t . y )
60+ r1 = ( 1 - 1 / ( r0 + 1 ) ) / r0
61+ x0 = g . t . x * r1
62+ y0 = g . t . y * r1
63+ x1 = g . attr . x
64+ y1 = g . attr . y
65+ x2 = g . pnt . x
66+ y2 = g . pnt . y
67+ x3 = ( 1 - x0 ) * x1 + y0 * y1 + x0 * x2 - y0 * y2
68+ y3 = ( 1 - x0 ) * y1 - y0 * x1 + x0 * y2 + y0 * x2
69+ }
70+
71+ function itCD ( ) {
72+ x0 = exp ( g . t . x )
73+ y0 = log ( abs ( g . t . y ) + 1 ) * ( g . t . y < 0 ? - 1 : 1 )
74+ x0 = exp ( g . t . x )
75+ y0 = log ( abs ( g . t . y ) + 1 ) * ( g . t . y < 0 ? - 1 : 1 )
76+ x1 = g . attr . x - g . pnt . x
77+ y1 = g . attr . y - g . pnt . y
78+ x2 = g . pnt . x
79+ y2 = g . pnt . y
80+ r = sqrt ( x1 * x1 + y1 * y1 )
81+ x3 = x2 + ( x0 * x1 - y0 * y1 ) / r
82+ y3 = y2 + ( x0 * y1 + x1 * y0 ) / r
83+ }
84+
85+ function itEItoLI ( ) {
86+ x4 = g . t . x * 2
87+ y4 = g . t . y * 2
88+ x1 = g . attr . x
89+ y1 = g . attr . y
90+ x2 = g . pnt . x
91+ y2 = g . pnt . y
92+ r2 = sqrt ( x2 * x2 + y2 * y2 )
93+ t = atan2 ( y2 , x2 )
94+ x5 = x1 + pow ( r2 , x4 ) * exp ( - y4 * t ) * cos ( t * x4 + y4 * log ( r2 ) )
95+ y5 = y1 + pow ( r2 , x4 ) * exp ( - y4 * t ) * sin ( t * x4 + y4 * log ( r2 ) )
96+ r0 = sqrt ( x5 * x5 + y5 * y5 )
97+ r1 = ( 1 - 1 / ( r0 + 1 ) ) / r0
98+ x0 = x5 * r1
99+ y0 = y5 * r1
100+ x3 = ( 1 - x0 ) * x1 + y0 * y1 + x0 * x2 - y0 * y2
101+ y3 = ( 1 - x0 ) * y1 - y0 * x1 + x0 * y2 + y0 * x2
102+ }
103+
104+ function itEItoCD ( ) {
105+ x4 = g . t . x * 2
106+ y4 = g . t . y * 2
107+ x5 = g . attr . x
108+ y5 = g . attr . y
109+ x2 = g . pnt . x
110+ y2 = g . pnt . y
111+ r2 = sqrt ( x2 * x2 + y2 * y2 )
112+ t = atan2 ( y2 , x2 )
113+ x6 = x5 + pow ( r2 , x4 ) * exp ( - y4 * t ) * cos ( t * x4 + y4 * log ( r2 ) )
114+ y6 = y5 + pow ( r2 , x4 ) * exp ( - y4 * t ) * sin ( t * x4 + y4 * log ( r2 ) )
115+ x0 = exp ( x6 )
116+ y0 = log ( abs ( y6 ) + 1 ) * ( y6 < 0 ? - 1 : 1 )
117+ x0 = exp ( x6 )
118+ y0 = log ( abs ( y6 ) + 1 ) * ( y6 < 0 ? - 1 : 1 )
119+ x1 = g . attr . x - g . pnt . x
120+ y1 = g . attr . y - g . pnt . y
121+ x2 = g . pnt . x
122+ y2 = g . pnt . y
123+ r = sqrt ( x1 * x1 + y1 * y1 )
124+ x3 = x2 + ( x0 * x1 - y0 * y1 ) / r
125+ y3 = y2 + ( x0 * y1 + x1 * y0 ) / r
126+ }
127+
128+ function itEI ( ) {
129+ x0 = g . t . x * 2
130+ y0 = g . t . y * 2
131+ x1 = g . attr . x
132+ y1 = g . attr . y
133+ x2 = g . pnt . x
134+ y2 = g . pnt . y
135+ r = sqrt ( x2 * x2 + y2 * y2 )
136+ t = atan2 ( y2 , x2 )
137+ x3 = x1 + pow ( r , x0 ) * exp ( - y0 * t ) * cos ( t * x0 + y0 * log ( r ) )
138+ y3 = y1 + pow ( r , x0 ) * exp ( - y0 * t ) * sin ( t * x0 + y0 * log ( r ) )
139+ }
140+
141+ function itMP ( ) {
142+ x1 = g . attr . x
143+ y1 = g . attr . y
144+ x2 = g . pnt . x
145+ y2 = g . pnt . y
146+ x3 = ( x1 + x2 ) / 2
147+ y3 = ( y1 + y2 ) / 2
148+ }
149+
150+ function itPF ( ) {
151+ n = g . set . length
152+ c = g . polyCs [ g . seti ]
153+ z = zPows ( n )
154+ cx = c [ 0 ] . x
155+ cy = c [ 0 ] . y
156+ zx = z [ 0 ] . x
157+ zy = z [ 0 ] . y
158+ p = createVector ( cx * zx - cy * zy , cx * zy + cy * zx )
159+ for ( i = 1 ; i < n ; i ++ ) {
160+ cx = c [ i ] . x
161+ cy = c [ i ] . y
162+ zx = z [ i ] . x
163+ zy = z [ i ] . y
164+ p . add ( createVector ( cx * zx - cy * zy , cx * zy + cy * zx ) )
165+ }
166+ x3 = p . x
167+ y3 = p . y
168+ //g.pnt=p
169+ }
170+
55171function iterate ( ) {
172+ x3 = 0
173+ y3 = 0
56174 switch ( g . e ) {
57175 //Choose iteration algorithm
58176 case 0 :
59177 //Linear Interpolation
60- R0 = sqrt ( g . t . x * g . t . x + g . t . y * g . t . y )
61- R1 = ( 1 - 1 / ( R0 + 1 ) ) / R0
62- x0 = g . t . x * R1
63- y0 = g . t . y * R1
64- x1 = g . attr . x
65- y1 = g . attr . y
66- x2 = g . pnt . x
67- y2 = g . pnt . y
68- x3 = ( 1 - x0 ) * x1 + y0 * y1 + x0 * x2 - y0 * y2
69- y3 = ( 1 - x0 ) * y1 - y0 * x1 + x0 * y2 + y0 * x2
178+ itLI ( )
70179 break
71180 case 1 :
72181 //Constant Distance
73- x0 = exp ( g . t . x )
74- y0 = log ( abs ( g . t . y ) + 1 ) * ( g . t . y < 0 ? - 1 : 1 )
75- x0 = exp ( g . t . x )
76- y0 = log ( abs ( g . t . y ) + 1 ) * ( g . t . y < 0 ? - 1 : 1 )
77- x1 = g . attr . x - g . pnt . x
78- y1 = g . attr . y - g . pnt . y
79- x2 = g . pnt . x
80- y2 = g . pnt . y
81- R = sqrt ( x1 * x1 + y1 * y1 )
82- x3 = x2 + ( x0 * x1 - y0 * y1 ) / R
83- y3 = y2 + ( x0 * y1 + x1 * y0 ) / R
182+ itCD ( )
84183 break
85184 case 2 :
86185 //Exponential Iteration -> Linear Interpolation
87- x4 = g . t . x * 2
88- y4 = g . t . y * 2
89- x1 = g . attr . x
90- y1 = g . attr . y
91- x2 = g . pnt . x
92- y2 = g . pnt . y
93- R2 = sqrt ( x2 * x2 + y2 * y2 )
94- T = atan2 ( y2 , x2 )
95- x5 = x1 + pow ( R2 , x4 ) * exp ( - y4 * T ) * cos ( T * x4 + y4 * log ( R2 ) )
96- y5 = y1 + pow ( R2 , x4 ) * exp ( - y4 * T ) * sin ( T * x4 + y4 * log ( R2 ) )
97- R0 = sqrt ( x5 * x5 + y5 * y5 )
98- R1 = ( 1 - 1 / ( R0 + 1 ) ) / R0
99- x0 = x5 * R1
100- y0 = y5 * R1
101- x3 = ( 1 - x0 ) * x1 + y0 * y1 + x0 * x2 - y0 * y2
102- y3 = ( 1 - x0 ) * y1 - y0 * x1 + x0 * y2 + y0 * x2
186+ itEItoLI ( )
103187 break
104188 case 3 :
105- //Exponential Iteration -> Constant Distance
106- x4 = g . t . x * 2
107- y4 = g . t . y * 2
108- x5 = g . attr . x
109- y5 = g . attr . y
110- x2 = g . pnt . x
111- y2 = g . pnt . y
112- R2 = sqrt ( x2 * x2 + y2 * y2 )
113- T = atan2 ( y2 , x2 )
114- x6 = x5 + pow ( R2 , x4 ) * exp ( - y4 * T ) * cos ( T * x4 + y4 * log ( R2 ) )
115- y6 = y5 + pow ( R2 , x4 ) * exp ( - y4 * T ) * sin ( T * x4 + y4 * log ( R2 ) )
116- x0 = exp ( x6 )
117- y0 = log ( abs ( y6 ) + 1 ) * ( y6 < 0 ? - 1 : 1 )
118- x0 = exp ( x6 )
119- y0 = log ( abs ( y6 ) + 1 ) * ( y6 < 0 ? - 1 : 1 )
120- x1 = g . attr . x - g . pnt . x
121- y1 = g . attr . y - g . pnt . y
122- x2 = g . pnt . x
123- y2 = g . pnt . y
124- R = sqrt ( x1 * x1 + y1 * y1 )
125- x3 = x2 + ( x0 * x1 - y0 * y1 ) / R
126- y3 = y2 + ( x0 * y1 + x1 * y0 ) / R
127- break
128- case 4 :
129- //Exponential Iteration
130- x0 = g . t . x * 2
131- y0 = g . t . y * 2
132- x1 = g . attr . x
133- y1 = g . attr . y
134- x2 = g . pnt . x
135- y2 = g . pnt . y
136- R = sqrt ( x2 * x2 + y2 * y2 )
137- T = atan2 ( y2 , x2 )
138- x3 = x1 + pow ( R , x0 ) * exp ( - y0 * T ) * cos ( T * x0 + y0 * log ( R ) )
139- y3 = y1 + pow ( R , x0 ) * exp ( - y0 * T ) * sin ( T * x0 + y0 * log ( R ) )
189+ //Polynomial Function
190+ itPF ( )
140191 break
141192 default :
142- x1 = g . attr . x
143- y1 = g . attr . y
144- x2 = g . pnt . x
145- y2 = g . pnt . y
146- x3 = ( x1 + x2 ) / 2
147- y3 = ( y1 + y2 ) / 2
193+ //Midpoint
194+ itMP ( )
148195 }
149196 g . pnt . x = x3
150197 g . pnt . y = y3
@@ -155,6 +202,49 @@ function mod(a,b){
155202 return a - b * int ( a / b )
156203}
157204
205+ function updPolyCs ( ) {
206+ if ( g . e == 3 ) {
207+ g . polyCs = [ attrPolyCs ( g . attrs [ 0 ] ) ]
208+ for ( j = 1 ; j < g . attrs . length ; j ++ ) {
209+ g . polyCs . push ( attrPolyCs ( g . attrs [ j ] ) )
210+ }
211+ }
212+ }
213+
214+ function attrPolyCs ( set ) {
215+ c = [ createVector ( g . t . x , g . t . y ) ]
216+ for ( n = 0 ; n < set . length ; n ++ ) {
217+ c . push ( 0 )
218+ sr = set [ n ] . x
219+ si = set [ n ] . y
220+ for ( i = n ; i > 0 ; i -- ) {
221+ cr = c [ i ] . x
222+ ci = c [ i ] . y
223+ cl = c [ i - 1 ] . copy ( )
224+ c [ i ] = cl . sub ( createVector ( sr * cr - si * cr , sr * ci + si * cr ) )
225+ }
226+ cr = c [ 0 ] . x
227+ ci = c [ 0 ] . y
228+ c [ 0 ] = createVector ( - sr * cr - si * ci , - sr * ci - si * cr )
229+ }
230+ return c
231+ }
232+
233+ function zPows ( n ) {
234+ x = g . pnt . x
235+ y = g . pnt . y
236+ zp = [ createVector ( 1 , 0 ) ]
237+ if ( n > 0 ) {
238+ zp . push ( createVector ( x , y ) )
239+ }
240+ xp = x
241+ yp = y
242+ for ( i = 2 ; i < n ; i ++ ) {
243+ zp . push ( createVector ( xp * x - yp * y , xp * y + yp * x ) )
244+ }
245+ return zp
246+ }
247+
158248function mout ( x , y , a ) {
159249 //Change variable point
160250 switch ( g . mfix ) {
@@ -187,6 +277,7 @@ function mout(x,y,a){
187277 default :
188278 g . t . x = ( x - g . x ) / g . scal
189279 g . t . y = - ( y - g . y ) / g . scal
280+ updPolyCs ( )
190281 }
191282}
192283
@@ -246,7 +337,7 @@ function draw() {
246337 brk . push ( [ i , k ] )
247338 brek = 0
248339 }
249- }
340+ }
250341 }
251342 if ( brek ) {
252343 fill ( 360 * i / len , 360 , 360 )
@@ -288,10 +379,12 @@ function draw() {
288379 _set . push ( g . attrs [ k ] )
289380 }
290381 }
291- g . set = random ( _set )
382+ g . seti = floor ( random ( 0 , _set . length ) )
383+ g . set = _set [ g . seti ]
292384 }
293385 else {
294- g . set = random ( g . attrs )
386+ g . seti = floor ( random ( 0 , g . attrs . length ) )
387+ g . set = g . attrs [ g . seti ]
295388 }
296389 }
297390 if ( ( g . excn != 0 ) && g . set . length > 1 ) {
@@ -502,7 +595,7 @@ function keyPressed() {
502595 }
503596 if ( keyCode == 69 ) {
504597 //e
505- g . e = mod ( g . e + 1 , 5 )
598+ g . e = mod ( g . e + 1 , g . me )
506599 }
507600 if ( keyCode == 72 ) {
508601 //h
@@ -541,11 +634,13 @@ function keyPressed() {
541634 g . mem ++
542635 }
543636 }
637+ updPolyCs ( )
544638}
545639
546640function mouseClicked ( ) {
547641 //Separate event for alt clicking in edit mode
548642 if ( keyCode == 18 && keyIsPressed && g . edit ) {
549643 g . attrs [ g . addr ] . push ( createVector ( mouseX - g . x , g . y - mouseY ) . div ( g . scal ) )
644+ updPolyCs ( )
550645 }
551646}
0 commit comments