## Problem with a Fractal fern generation

Nov 18, 2007 at 7:02pm

# Problem with a Fractal fern generation

Hi! I made a patch to generate a fractal fern but it is not working… I think the problem is related to matrix dimensions or bang ordering… Would someone advise me how to fix my patch or, even better, how to make it faster and eficient? I also need to manipulate some of the coeficients of the equations.

I pasted the patch below, attached the expected image result and here is the theory behind (a sort of algorithm):

Set a random number

If random < 0.01

Xnew = 0
Ynew = 0.16*Yold

If random >= 0.01 AND random < 0.86

Xnew = 0.20*Xold – 0.26*Yold
Ynew = -0.23*Xold + 0.22*Yold + 1.6

If random >= 0.86 AND random < 0.93

Xnew = A*Xant + B*Yant + E
Ynew = C*Xant + D*Yant + F

If random >= 0.93

Xnew = -0.15*Xold + 0.28*Yold
Ynew = 0.26*Xold + 0.24*Yold + 0.44

Plot (Xnew, Ynew)

Xold = Xnew
Yold = Ynew

PATCH

max v2;
#N vpatcher 119 44 1058 537;
#P origin 27 30;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 161 141 53 196617 s to_prob;
#P newex 320 397 254 196617 jit.gl.handle ” ” @auto_rotate 1 @inherit_transform 1;
#P newex 143 162 66 196617 s to_helecho;
#P comment 884 120 21 196617 m7;
#P comment 834 120 21 196617 m6;
#P comment 783 120 21 196617 m5;
#P flonum 871 140 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 820 140 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 769 140 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 718 140 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 732 120 21 196617 m4;
#P user jit.fpsgui 404 195 60 196617 3;
#P newex 514 230 63 196617 s to_render;
#P comment 681 120 21 196617 m3;
#P comment 630 120 21 196617 m2;
#P comment 578 120 21 196617 m1;
#P flonum 667 140 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 616 140 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 565 140 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 514 140 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N vpatcher 161 44 1068 482;
#P window setfont “Sans Serif” 9.;
#P newex 42 343 64 196617 jit.op @op +;
#P newex 42 286 64 196617 jit.op @op +;
#P newex 42 366 124 196617 jit.matrix 2 float32 1 50;
#P newex 42 227 64 196617 jit.op @op +;
#P window linecount 1;
#P newex 96 321 654 196617 jit.expr @inputs 2 @expr “(in[1]>=0.93)*(-0.15*in[0].p[0]+0.28*in[0].p[1])” “(in[1]>=0.93)*(0.26*in[0].p[0]+0.24*in[0].p[1]+0.44)”;
#P newex 96 264 751 196617 jit.expr @inputs 2 @expr “(in[1]>=0.86&&in[1]<0.93)*(0.20*in[0].p[0]-0.26*in[0].p[1])" "(in[1]>=0.86&&in[1]<0.93)*(0.23*in[0].p[0]+0.22*in[0].p[1]+1.6)";
#P newex 96 205 767 196617 jit.expr @inputs 2 @expr “(in[1]>=0.01&&in[1]<0.86)*(0.85*in[0].p[0]+0.04*in[0].p[1])" "(in[1]>=0.01&&in[1]<0.86)*(-0.04*in[0].p[0]+0.85*in[0].p[1]+1.6)";
#P newex 323 107 53 196617 r to_prob;
#P newex 323 129 116 196617 jit.noise 1 float32 1 50;
#P newex 42 169 291 196617 jit.expr @inputs 2 @expr “0″ “(in[1]<0.01)*0.16*in[0].p[1]";
#P inlet 772 42 15 0;
#P inlet 725 42 15 0;
#P flonum 772 74 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 725 74 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P outlet 42 390 15 0;
#P inlet 678 42 15 0;
#P inlet 631 42 15 0;
#P inlet 588 42 15 0;
#P inlet 545 42 15 0;
#P newex 42 59 66 196617 r to_helecho;
#P newex 42 85 124 196617 jit.matrix 2 float32 1 50;
#P flonum 678 74 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 631 74 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 588 74 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 545 74 35 9 0. 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 0;
#P comment 544 100 263 196617 For further coeficient manipulation;
#P connect 6 0 5 0;
#P connect 5 0 16 0;
#P connect 16 0 22 0;
#P connect 22 0 24 0;
#P connect 24 0 25 0;
#P connect 25 0 23 0;
#P connect 23 0 11 0;
#P fasten 5 0 19 0 47 125 101 125;
#P connect 19 0 22 1;
#P fasten 5 0 20 0 47 125 101 125;
#P connect 20 0 24 1;
#P fasten 5 0 21 0 47 125 101 125;
#P connect 21 0 25 1;
#P connect 18 0 17 0;
#P connect 17 0 16 1;
#P connect 7 0 1 0;
#P connect 8 0 2 0;
#P connect 9 0 3 0;
#P connect 10 0 4 0;
#P connect 14 0 12 0;
#P fasten 17 0 21 1 328 161 745 161;
#P connect 15 0 13 0;
#P fasten 17 0 20 1 328 155 842 155;
#P fasten 17 0 19 1 328 150 858 150;
#P pop;
#P newobj 514 177 371 196617 p genera_helecho;
#P comment 526 120 22 196617 m0;
#P window setfont “Fixedwidth Serif” 12.;
#P hidden newex 822 392 66 1441804 r to_win;
#P toggle 197 316 23 0;
#P window setfont “Sans Serif” 9.;
#P message 197 345 96 196617 smooth_shading \$1;
#P toggle 102 316 23 0;
#P message 102 345 90 196617 lighting_enable \$1;
#P hidden newex 312 326 56 196617 loadmess 1;
#P button 11 62 31 0;
#N vpatcher 10 59 403 446;
#P inlet 51 29 15 0;
#P window setfont “Fixedwidth Serif” 12.;
#P window linecount 2;
#P comment 104 68 248 1441804 Click to move the jit.window object’s window to the 2nd display;
#P window linecount 1;
#P newex 124 333 66 1441804 s to_win;
#P newex 124 310 87 1441804 prepend pos;
#P message 124 254 45 1441804 \$1 \$2;
#P newex 51 193 45 1441804 sel 1;
#P newex 51 168 31 1441804 > 1;
#P window linecount 0;
#P message 147 196 115 1441804 1280 0 2080 600;
#P window linecount 1;
#P newex 147 172 87 1441804 prepend set;
#P newex 124 146 59 1441804 route 1;
#P number 51 146 35 12 0 0 0 22 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 51 122 156 1441804 route count coords;
#P message 51 218 66 1441804 coords 1;
#P message 51 73 45 1441804 count;
#P newex 51 97 185 1441804 jit.displays @resetmode 1;
#B color 5;
#P window linecount 2;
#P comment 147 214 137 1441804 The coordinates of your 2nd monitor;
#P window linecount 3;
#P comment 171 245 130 1441804 We’re only interested in the top-left position;
#P window linecount 1;
#P newex 124 287 108 1441804 vexpr \$i1 + 50;
#P window linecount 4;
#P comment 47 278 100 1441804 Adding 50 pixels to avoid any menubars.;
#P connect 18 0 5 0;
#P fasten 6 0 4 0 56 242 34 242 34 93 56 93;
#P connect 5 0 4 0;
#P connect 4 0 7 0;
#P connect 7 0 8 0;
#P connect 8 0 12 0;
#P connect 12 0 13 0;
#P connect 13 0 6 0;
#P connect 7 1 9 0;
#P connect 9 0 14 0;
#P connect 14 0 1 0;
#P connect 1 0 15 0;
#P connect 15 0 16 0;
#P connect 9 0 10 0;
#P connect 10 0 11 0;
#P pop;
#P newobj 11 100 58 196617 p inicializa;
#P message 745 394 68 196617 fullscreen \$1;
#P toggle 728 394 15 0;
#P hidden newex 770 369 35 196617 sel 27;
#P hidden newex 728 369 40 196617 key;
#P toggle 32 394 15 0;
#P message 32 413 75 196617 geom_rows \$1;
#P hidden newex 247 137 62 196617 s to_render;
#P newex 125 184 62 196617 s to_render;
#P hidden newex 596 326 60 196617 loadmess 1;
#P flonum 479 345 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 518 345 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 557 345 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 596 345 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 478 365 169 196617 pak color 0. 0. 0. 0.;
#P flonum 312 345 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 351 345 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 390 345 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 429 345 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 311 365 138 196617 pak erase_color 0. 0. 0. 0.;
#P hidden newex 153 365 62 196617 r to_render;
#P flonum 112 394 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 111 413 97 196617 pak camera 0. 0. 0.;
#P flonum 215 394 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 215 413 72 196617 near_clip \$1;
#P toggle 605 387 23 0;
#P toggle 628 418 22 0;
#P toggle 587 417 22 0;
#P newex 546 444 92 196617 pak poly_mode 0 0;
#P user ubumenu 221 365 68 196617 0 1 1 0;
#X prefix_set 0 0 0;
#X pattrmode 1;
#P hidden newex 728 411 271 196617 jit.window ” ” @floating 0 @depthbuffer 1 @size 320 240;
#P window linecount 2;
#P newex 294 431 240 196617 jit.gl.render ” ” @lighting_enable 1 @smooth_shading 1 @depth_enable 1 @erase_color 1. 1.1. 1.;
#P window linecount 1;
#P newex 125 98 60 196617 qmetro 0.5;
#P newex 125 119 66 196617 t b b b erase;
#P toggle 125 64 29 0;
#P window linecount 0;
#P comment 1 33 100 196617;
#P connect 36 0 35 0;
#P connect 30 0 29 0;
#P hidden connect 39 0 38 0;
#P connect 1 0 3 0;
#P connect 3 0 2 0;
#P connect 2 0 27 0;
#P connect 2 1 62 0;
#P connect 2 2 64 0;
#P hidden connect 41 0 40 0;
#P hidden connect 14 0 13 3;
#P connect 12 0 11 0;
#P hidden connect 2 3 28 0;
#P hidden connect 63 0 4 0;
#P hidden connect 29 0 4 0;
#P hidden fasten 15 0 4 0 158 388 299 388;
#P hidden connect 13 0 4 0;
#P hidden connect 11 0 4 0;
#P hidden connect 7 0 4 0;
#P hidden fasten 6 1 4 0 255 401 299 401;
#P hidden connect 16 0 4 0;
#P hidden connect 21 0 4 0;
#P hidden connect 40 0 4 0;
#P hidden connect 38 0 4 0;
#P hidden connect 26 0 20 0;
#P hidden connect 37 0 20 0;
#P hidden connect 20 0 16 1;
#P hidden connect 26 0 19 0;
#P hidden connect 37 0 19 0;
#P hidden connect 19 0 16 2;
#P hidden connect 26 0 18 0;
#P hidden connect 37 0 18 0;
#P connect 44 0 53 0;
#P hidden connect 18 0 16 3;
#P hidden connect 26 0 17 0;
#P hidden connect 37 0 17 0;
#P hidden connect 17 0 16 4;
#P hidden connect 26 0 25 0;
#P hidden connect 37 0 25 0;
#P connect 45 0 44 0;
#P connect 44 0 52 0;
#P hidden connect 25 0 21 1;
#P hidden connect 37 0 24 0;
#P hidden connect 24 0 21 2;
#P hidden connect 37 0 23 0;
#P connect 46 0 44 1;
#P fasten 10 0 8 0 610 413 592 413;
#P connect 8 0 7 1;
#P hidden connect 23 0 21 3;
#P hidden connect 26 0 22 0;
#P hidden connect 37 0 22 0;
#P fasten 10 0 9 0 610 413 633 413;
#P connect 9 0 7 2;
#P hidden connect 22 0 21 4;
#P connect 47 0 44 2;
#P hidden fasten 32 0 33 0 775 391 733 391;
#P hidden connect 34 0 5 0;
#P hidden connect 42 0 5 0;
#P connect 48 0 44 3;
#P hidden fasten 33 0 34 0 744 409 744 394;
#P hidden fasten 31 0 32 0 769 386 769 371;
#P connect 55 0 44 4;
#P connect 56 0 44 5;
#P pop;

#34658
Nov 21, 2007 at 2:32am

have you tried using an l-system?

jit.linden

But you need Jitter, lindemeyer systems are in Jitter.

I found this paper that may help too.

http://www-gs.informatik.tu-cottbus.de/~wwwgs/ima_lsy.pdf

#117350
Nov 21, 2007 at 3:41am

Donk, thank you very much… no one have replyed!

I tried to use an L-system but didn’t realize how to transform the equations that i’ve got to an L-system. I will check the PDF you suggested, maybe i can find something interesting.

Now I fixed the patch and it is working, also with the coeficient manipulation that I needed, but my question is… how to make the points rendered to be bigger, they are really small… I’m still using jit.gl.render and a window of 480 X 480 pixels. If I make the camera get closer the pixels are still little and if I make a kind of downsampling (use a intermediate little jit.matrix and display it onto a bigger jit.window) but the matrix has to be a 4 plane char and the quality really decreases…

I’m stucked! any suggestions?

Thanks!

Miguel

#117351
Nov 21, 2007 at 9:55am

I don

#117352

You must be logged in to reply to this topic.