YOUR ACCOUNT

Login or Register to post new topics or replies
David Roberson
Artist
Posts: 404
Filters: 36
I'm not entirely sure what I've done with this script. I was trying for a script that would do distance mapping of an arbitrary shape, using the function I created for my Spherical Worley Noise. The problem is, it doesn't respond to a binary mask at all. What I got instead was a kind of split distance mapping of the bevel of an arbitrary shape. Whimsically, I turned that into a little heart scrippet, but I'm really curious about how I got the result I did. Here's the code:

Code
function prepare()
   dtype = get_intslider_input(DISTANCE_TYPE)
   p = get_intslider_input(P)
end;

function get_sample(x, y)
   local v = get_sample_grayscale(x, y, SOURCE)
   local min_dist = 10000
   for x = 0, 1 do
      for y = 0, 1 do
         local dist =  distcalc(x, y, v, v)
         min_dist = math.min(dist, min_dist) --
      end --
   end --
   -- min_dist = 1.0 - min_dist
   v = min_dist

   return v, v, v, a
end;

function distcalc(sx,sy,dx,dy)
   local dist = 0
   if dtype == 1 then
      -- Euclidean
      dist = math.sqrt((sx - dx)^2 + (sy - dy)^2)   
   elseif dtype == 2 then
      -- Chebyshev
      dist = math.max(math.abs(sx - dx), math.abs(sy - dy))   
   elseif dtype == 3 then
      -- Manhattan
      dist = (math.abs(sx - dx) + math.abs(sy - dy)) / 1.5   
   else
      -- Minkowski
      local pe = 1/p
      dist = (math.abs(sx - dx)^p + math.abs(sy - dy)^p)^pe
   end   
   return dist
end;


Distance Heart Scrippet.ffxml
  Details E-Mail
David Roberson
Artist
Posts: 404
Filters: 36
I suppose the question I should be asking is, how do you reference the x and y components of a sampled image. In the example above, I stuck v in for x and y on a whim and was surprised to get any kind of result. I had tried doing vx, vy = get_sample_grayscale(x, y, Source) but got an error saying dy was a nil value when I provided vy in my function call with vx. I can't recall another script I've seen that features a reference to the x and y from a sample image.
  Details E-Mail
Indigo Ray
Adam

Posts: 1442
Filters: 82
David, I also have trouble with scripting in FF, but don't you need to specify a step size for your loops?

The function get sample iterates over x and y (pixels)
When you call get_sample_grayscale(x, y, SOURCE)
it gives you the brightness at each sample point - there's only one output
You can input something other than "x" and "y" to do a transformation

Distance Transform is iterative a.k.a. slow. See our efforts here. But these were not scripting methods.
  Details E-Mail
David Roberson
Artist
Posts: 404
Filters: 36
Indigo, I modeled my script after the API Worley Noise script, so my loops follow its example. I didn't really think about step size, and wonder if you have an example where it is used properly I could see?

Good point about how get_sample iterates over an image. Unfortunately, most examples of distance mapping I've seen (in various scripting languages) iterate over x and y per pixel (which I do) and have access to the x and y coordinates you sample the distance from. I'm not sure I'm getting that part entirely right. I'm still learning about transformations in Lua, so I don't quite know what you mean in your fourth point. Can you elaborate?

Thanks for the link! I'll check it out!
  Details E-Mail
David Roberson
Artist
Posts: 404
Filters: 36
Just to clarify my objectives in this script, I am trying to map distance from the current x,y in my nested loop and the closest pixel of value 1. I'm getting distance from both 0 and 1 with distance mapping in between, centered around the 0.5 value. I'm clearly not identifying those white pixels (or sample points) in an effective way. So, yes, I am getting distance mapping, but in a useless context of an existing bevel.

Please tell me someone gets what I'm obviously missing here?
  Details E-Mail
David Roberson
Artist
Posts: 404
Filters: 36
Okay, looking at it again, the problem I am running into is tied to the get_sample_grayscale() part, which gives me the value (brightness) of the current sample, but my distance calculations are designed to compare the position of the current sample and the nearest "brightest" point. Without a way of getting the coordinates for that I'm not providing the equation what it needs. Worley noise was working inside a cell grid in some way I'm not understanding very well, but which was defined in x and y coordinates.

I still can't figure out how I get the results I'm getting from a bevel, but I'm guessing it's the result of feeding a value between 0 and 1 as if that was a coordinate. I really wish there were more documentation for Lua graphics scripting. I may eventually sort this out, but it's not going to be easy.
  Details E-Mail

Join Our Community!

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

33,712 Registered Users
+19 new in 30 days!

153,537 Posts
+6 new in 7 days!

15,348 Topics
+72 new in year!

Create an Account

Online Users Last minute:

171 unregistered users.