YOUR ACCOUNT

Login or Register to post new topics or replies
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
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?

smile:| smile;) smile:D

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. smile:blush:

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!" ;)
  Details E-Mail
Indigo Ray
Adam

Posts: 1442
Filters: 82
From wikipedia:
Quote
Many programming languages also provide the two-argument atan2 function, which computes the arctangent of y / x given y and x, but with a range of (−π, π].

You'll have to do a loop if you want a larger range, I think.
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
Indeed. Thank you! smile:)

Quote
If desired an angle in the range [0, 2Ï€) may be obtained by adding 2Ï€ to the value if it is negative.
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
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 smile:-)
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
Nice gradient! And more efficient, apparently. smile:)

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!" ;)
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
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.
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
Sphinx, thanks for your help. I'll get back to experimenting now...
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
James
James
Posts: 676
Filters: 46
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;
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
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.
  Details E-Mail
James
James
Posts: 676
Filters: 46
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?
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
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!" ;)
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Oh I get it now James smile:-D well I meant:

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
  Details E-Mail
James
James
Posts: 676
Filters: 46
Thanks, that makes it work great smile:D
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
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. smile;) smile:D

Also, I'm thinking about adding a 'Fixed Size' option.

Spiral Gradient.ffxml
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Cool! Looks quite good - also codewise smile:)

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)
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
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..
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
Quote
Sphinx. wrote:
aa_zone = math.floor(spiralGrd)
spiralGrd = spiralGrd - aa_zone


Oh yeah! That works like a charm! smile:)
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
James
James
Posts: 676
Filters: 46
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. smile:)
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
Quote
James wrote:
Bezier curve control


Yup, sounds good. I'll schedule that into a future update.

Quote
Message log wrote:
Script error (line 35): Invalid floating-point value passed to get_sample_curve


With Size, pixels at 1 the script throws an error. Hmmm!?.... smile:|
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
inujima

Posts: 176
Filters: 26
Quote
With Size, pixels at 1 the script throws an error. Hmmm!?....


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. smile:)
  Details E-Mail
James
James
Posts: 676
Filters: 46
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. smile:)
  Details E-Mail
inujima

Posts: 176
Filters: 26
It is necessary to rewrite so that zero must not be parameter of math.log().

For example
Code

   -- calculate spiral gradient map
   radialCoordinate = math.log (math.sqrt ( spiralX*spiralX + spiralY*spiralY )) * windings


rewrite like this

Code

   -- calculate spiral gradient map
   local radial = math.sqrt ( spiralX*spiralX + spiralY*spiralY )
   radial = math.max(radial, 0.00001)
   radialCoordinate = math.log (radial) * windings
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
Dilla's Scripting Blunders -- Episode 2
The scripting n00b madness continues... smile;) smile:D

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!" ;)
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
Oh my, there sure are some interesting polygon hit-test algorithms out there -- exciting stuff to dig into... smile:eek: smile;)

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... smile8)
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
Ghislaine
Ghislaine

Posts: 3142
Filters: 270
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. smile:)
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
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!" ;)
  Details E-Mail
David Roberson
Artist
Posts: 404
Filters: 36
Quote
Ghislaine wrote:
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.


I could not figure out what filter you meant in this comment. Though it's been a while, do you remember which one it was?
  Details E-Mail
Ghislaine
Ghislaine

Posts: 3142
Filters: 270
Hi dear !

I do not remember either.

Glad to get news from you. Have a nice day my friend. smile:)
  Details E-Mail
David Roberson
Artist
Posts: 404
Filters: 36
Yeah, sometimes these things just slip our minds. Ah, well. No harm, no foul. Thanks for responding, and have a good day as well! smile:D
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,711 Registered Users
+18 new in 30 days!

153,531 Posts
+36 new in 30 days!

15,347 Topics
+72 new in year!

Create an Account

Online Users Last minute:

17 unregistered users.