|
Crapadilla
|
Alrighty, I've been dipping a toe into the unknown waters of scripting lately. For some foolish reason I decided to begin work on a Logarithmic Spiral generator component. Spirals are so incredibly awesome, so I thought why not?
So far the basics look promising, but I'm only getting one revolution (or segment) of the spiral plotted, i.e. it does not spiral towards infinity or zero. I'm guessing there must be some mathematical reason for it, but currently I don't see it.
In case anyone less mathematically challenged than the current me feels like taking a look, here is the filter: Logarithmic Spiral attempt.ffxml --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 20, 2011 1:31 pm | ||||||
|
Indigo Ray
|
From wikipedia:
You'll have to do a loop if you want a larger range, I think. "Time flies like an arrow; Fruit flies like a banana." -Groucho Marx |
|||||
| Posted: November 20, 2011 6:27 pm | ||||||
|
Crapadilla
|
Indeed. Thank you!
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 21, 2011 4:25 am | ||||||
|
Sphinx.
|
radialCoordinate = math.log(math.sqrt ( x^2 + y^2 ) * 30)
angularCoordinate = 0.5 + math.atan2 (x,y) / (2 * math.pi) spiralGrd = angularCoordinate + radialCoordinate spiralGrd = spiralGrd - math.floor(spiralGrd) route spiralGrd to the output and take a look Njyldgarkn sample cache! |
|||||
| Posted: November 21, 2011 5:08 am | ||||||
|
Crapadilla
|
Nice gradient! And more efficient, apparently. But how does one implement proper aa_zones for this? And how does one offset the damned thing to the image center via script? --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 21, 2011 6:29 am | ||||||
|
Sphinx.
|
Well, I supplied the the code as a starting point. As such it does not make sense to have aa-zones for a gradient (there are no zones...). If you use the gradient to create that threshold like output, it makes sense to use the conditional ("if..then..else") to determine the aa_zone.
you can try using this as aa_zone though: math.floor(spiralGrd * 3), where 3 is the multiplication constant from the radialCoordinate calculation / 10. This should reduce moire aliasing in the center region, while skipping aa calc in the soft large gradients For the centering you need to think "reverse", i.e. subtract 0.5 from x and y initially so you have 0,0 in the visual center region. Njyldgarkn sample cache! |
|||||
| Posted: November 21, 2011 6:58 am | ||||||
|
Crapadilla
|
Sphinx, thanks for your help. I'll get back to experimenting now... --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 21, 2011 9:06 am | ||||||
| James |
Is that a spiral formula Sphinx? If i try to center the XY positions by subtracting a 0.5 value i get more of a radial remapped result from the input.
function prepare() end; function get_sample(x, y) radialCoordinate = math.log(math.sqrt ((x-0.5)^2 + (y-0.5)^2 ) * 30) angularCoordinate = 0.5 + math.atan2 (x,y) / (2 * math.pi) spiralGrd = angularCoordinate + radialCoordinate spiralGrd = spiralGrd - math.floor(spiralGrd) r,g,b,a = get_sample_map(spiralGrd, spiralGrd, SOURCE) return r, g, b, a end; |
|||||
| Posted: November 21, 2011 9:06 am | ||||||
|
Sphinx.
|
James, don't use it for further lookup - just return the value, i.e.: return spiralGrd, spiralGrd, spiralGrd, 1
Dilla - try out radialCoordinate = math.log(math.sqrt ( x^2 + y^2 )) * 30 too, i.e. move the mul. constant outside. It is easier to control the "windings" this way. Njyldgarkn sample cache! |
|||||
| Posted: November 21, 2011 9:25 am | ||||||
| James |
Thanks, it seems no different doing that though. Testing with just a basic gradient to make things more visible i can see rings rather than a spiral -
function prepare() end; function get_sample(x, y) radialCoordinate = math.log(math.sqrt ((x-0.5)^2 + (y-0.5)^2 ) * 30) angularCoordinate = 0.5 + math.atan2 (x,y) / (2 * math.pi) spiralGrd = angularCoordinate + radialCoordinate spiralGrd = spiralGrd - math.floor(spiralGrd) return spiralGrd, spiralGrd, spiralGrd, 1 end; Or is that how it's suppose to be? |
|||||
| Posted: November 21, 2011 9:32 am | ||||||
|
Crapadilla
|
James, you have to use the same offset on the angular coordinate as well, i.e.:
angularCoordinate = 0.5 + math.atan2 (x-0.5,y-0.5) / (2 * math.pi) --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 21, 2011 10:13 am | ||||||
|
Sphinx.
|
Oh I get it now James add this as the first thing in the script, then you don't have to think more about it. x,y = x - 0.5, y - 0.5 Njyldgarkn sample cache! |
|||||
| Posted: November 21, 2011 10:23 am | ||||||
| James |
Thanks, that makes it work great |
|||||
| Posted: November 21, 2011 10:37 am | ||||||
|
Crapadilla
|
This is so much fun! I couldn't resist turning this into a full-featured Spiral Gradient component. Submission to the library pending...
Take a look... constructive criticism on code optimization (and the AA_zones hack) is very welcome, cause - you know - it'll learn me. Also, I'm thinking about adding a 'Fixed Size' option. Spiral Gradient.ffxml --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 21, 2011 11:28 am | ||||||
|
Sphinx.
|
Cool! Looks quite good - also codewise About the aa hack: I think it would be better to do something like math.floor(spiralGrd * 3), since you can't for sure know that the given profile curve works well with your two constants (0.95 and 0.05). I'd strip away the current aa stuff and simply return the above result. Oh and another thing - you might want to check if blend_normal is faster than your current solution (honestly I don't know, since you're not doing alpha blending, but lerping instead which is much simpler) Njyldgarkn sample cache! |
|||||
| Posted: November 21, 2011 1:07 pm | ||||||
|
Sphinx.
|
Oh, I just realized that there is an even better aa_zone to return.
Find the line: spiralGrd = spiralGrd - math.floor(spiralGrd) and replace that with aa_zone = math.floor(spiralGrd) spiralGrd = spiralGrd - aa_zone and ensure that aa_zone is not modified afterwards by old script etc.. Njyldgarkn sample cache! |
|||||
| Posted: November 21, 2011 1:14 pm | ||||||
|
Crapadilla
|
Oh yeah! That works like a charm! --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 21, 2011 1:25 pm | ||||||
| James |
One useful thing might be to maybe add the new Bezier curve control so the user could shape the profile with a custom curve.
Code wise everything seems quite good also. |
|||||
| Posted: November 21, 2011 2:26 pm | ||||||
|
Crapadilla
|
Yup, sounds good. I'll schedule that into a future update.
With Size, pixels at 1 the script throws an error. Hmmm!?.... --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 21, 2011 2:48 pm | ||||||
|
inujima
|
Function math.log(x) returns nil value at x<=0. By such a reason, the value of spiralGrd has been nil value at center coordinate. |
|||||
| Posted: November 21, 2011 4:34 pm | ||||||
| James |
Just wondering how can you fix this error mentioned, maybe with some sort of value limiting? or would it need to be fixed by the FF developers?
Not that i often use a size of 1 pixel but it would be useful to have a fix/workaround if anyone knows one. |
|||||
| Posted: November 22, 2011 7:03 am | ||||||
|
inujima
|
It is necessary to rewrite so that zero must not be parameter of math.log().
For example
rewrite like this
|
|||||
| Posted: November 22, 2011 7:47 am | ||||||
|
Crapadilla
|
Dilla's Scripting Blunders -- Episode 2
The scripting n00b madness continues... Ok, I've got three points and their circumcircle drawn, but how do I draw the triangle between these points? CircumCircle.ffxml --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 23, 2011 8:40 am | ||||||
|
Crapadilla
|
Oh my, there sure are some interesting polygon hit-test algorithms out there -- exciting stuff to dig into... http://paulbourke.net/geometry/insidepoly/ Looks like my next scripting assignment is porting one of these to Lua. Personally, I'd choose the first one... --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: November 23, 2011 11:38 am | ||||||
|
Ghislaine
|
Hi Dilla
I just upload a filter tonight based on your Logarythmic spiral. This base has just a script map + an offset component. And it is great. Let me tell you that we could make wonders with it. I'm asking you if you would add some input in your script. I would appreciate much to work again with this logarythmic spiral with more possibilities. Thanks in advance. I'm creating a second filter with yours. I have discovered a lot of spirograph forms just by playing with logarythmic spiral. I imagine that the possibilities would be multiplied at the infinity with few inputs added to your script. |
|||||
| Posted: May 29, 2012 7:07 pm | ||||||
|
Crapadilla
|
Ghislaine,
unfortunately I'm currently swamped in a project -- which means no time for filter authoring fun. However, feel free to post your suggestions here, and I might look into it once things have calmed down at work. --- Crapadilla says: "Damn you, stupid redundant feature requests!" ;) |
|||||
| Posted: June 4, 2012 1:04 pm | ||||||
Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!
15,510 Registered Users
+14 new last day!
113,374 Posts
+110 new last day!
10,190 Topics
+18 new last day!
Skybase, 9 unregistered users.