YOUR ACCOUNT

Login or Register to post new topics or replies
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
This is my first attempt at scripting in FF.

I am trying to create a script that takes a source and resizes, duplicates and stacks it.
I have figured out the resizing and duplicating part, but I can only get it to stack the shapes from the center towards a corner instead of on top of each other.
And yes, I fail at math smile:p

If anyone has any idea what I´m doing wrong and how to make it work, I´d much appreciate your help smile:-)

Thx,
Shar

stacking mapscript.ffxml
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Code
function prepare()
   -- This function is called once,
   -- before the rendering begins.
   -- Use it for querying non-mapped
   -- inputs and precalculation.
   opa = get_slider_input(OPACITY)
   count = get_intslider_input(REPEAT)
   hdr = false
   if(get_checkbox_input(REVERSE)) then
      rev = true
   else
      rev = false
   end
   if(get_checkbox_input(FADE)) then
      fade = true
   else
      fade = false
   end
end;

function get_sample(x, y)
   -- Image generation code goes here.
   dir = get_sample_grayscale(x, y, DIRECTION)
   spacing = get_sample_grayscale(x, y, SPACING)
   ofx = get_sample_grayscale(x, y, OFFX)
   ofy = get_sample_grayscale(x, y, OFFY)
   r, g, b, a = get_sample_map(x + ofx, y + ofx, IMAGE)
   ofx = get_sample_grayscale(x, y, OFFX)
   ofy = get_sample_grayscale(x, y, OFFY)
   local opacity = opa
   density = 1
   i = 0
   if fade then
      fad = 0.1
   else
      fad = 0
   end

   while (i < count ) do
      ri,gi,bi,ai = get_sample_map((x  * density )+ ofx , (  y  * density)+ ofy, IMAGE)
      r, g, b, a = blend_normal   (r, g, b, a, ri, gi, bi, ai, opacity - fad, hdr)
      if (rev)   then   
         density = density + spacing
      else
         density = density - spacing
      end
      i = i + 1
      if fade then
      fad = fad + 0.1
      end
   end;
   return r, g, b, a
end;


  Details E-Mail
Morgantao
Can't script

Posts: 2185
Filters: 20
Is there a way for a script to know the image dimentions?
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
try
Code
...
ri,gi,bi,ai = get_sample_map((x - 0.5)  * density + ofx + 0.5, (y - 0.5)  * density + ofy + 0.5, IMAGE)
...
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Yay! smile:D Thank you so much Sphinx! smile:love:

stacking mapscript.ffxml
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Works like a charm now smile:-)

  Details E-Mail
Morgantao
Can't script

Posts: 2185
Filters: 20
I'm sorry, but I can't reproduce that image you posted... What's your secret?
Also, I can't seem to get the direction slider do anything... What am I missing?

Thanks!
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
The image was done with my new filter Bubble fun, thats why you can´t reproduce it with the script smile;-)
And the direction slider currently does nothing, it was left over from trying to figure out how to change the stacking direction smile:)
I want to make some more changes to the script, will post an update then.
  Details E-Mail
Morgantao
Can't script

Posts: 2185
Filters: 20
Ah, OK.
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
while the stacking part works now, and I can offset it, or have it centered now, I´m still having issues with the script.

Above certain values for repeating and spacing it starts multiplying the whole stack instead the image, which leads to a kaleidoscope like effect. While that is interesting and fun, it´s not what I really wanted. And I have no clue why smile:-(

Sphinx, or anyone else, do you have any idea why that happens and could you try to explain it to me?
  Details E-Mail
Morgantao
Can't script

Posts: 2185
Filters: 20
I think I know WHY this happens, I just don't know how to avoid it.
The reason is that whenever FF goes out of the bounds of the image, it mirrors the image as a filler. You can see the same thing happen when you use the scale or rotate components.

I suppose in your script, when the offset is too great, FF mirrors what it already has inside the image bounds, and duplicates it on top of what you have, as if this is an actual part of the image.
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Yeah, I think that´s exactly the problem. I had a play with the scale component and it does the same thing. I tricked it by putting a frame around the scaled imaged, but that has it´s limits too.

I hope they add some components for effects like this in the future.
Juggling 50 components just for one simple effect is annoying.

I can do this in Photoshop in like 30 seconds by just duplicating and scaling the layers, and record an action for future use. It´s even faster than waiting for FF to render it smile:p
No need to create a filter for it I guess.
Apart from the pleasure to create something for other people to have fun with smile:-)
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Multiplying scales, adding and substracting offsets the image, what makes it rotate?
  Details E-Mail
Morgantao
Can't script

Posts: 2185
Filters: 20
Sorry, didn't understand the question...
  Details E-Mail
SpaceRay
SpaceRay

Posts: 12299
Filters: 35
Quote
Sharandra wrote:

I can do this in Photoshop in like 30 seconds by just duplicating and scaling the layers, and record an action for future use. It´s even faster than waiting for FF to render it
smile:D
No need to create a filter for it I guess.



Well, yes, is true that you can do it and make it much better in Photoshop and much faster than in FF, and get the effect as you want, and do not need a FF filter for this and I agree...

...BUT what I think would be interesting is to be able to customize and define the effect in many different ways and to be able to multiply the image as required and as many or few as you want, and change the orientation and offset and some other settings that would not be possible to make in a Photoshop Action.
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Quote
Sorry, didn't understand the question...


ri,gi,bi,ai = get_sample_map(x,y IMAGE)

Adding or subtracting from x and y offsets the image, multiplying scales it. As far as I could figure it out.
How can you add a rotation? For example the image around its center, or the duplicates in my script around the center.
Dunno if that makes it any clearer.

Quote
...BUT what I think would be interesting is to be able to customize and define the effect in many different ways and to be able to multiply the image as required and as many or few as you want, and change the orientation and offset and some other settings that would not be possible to make in a Photoshop Action.


I agree. That was the reason I started creating this script anyway, to have a customizable component that does this which we can use in our filters.
  Details E-Mail
Morgantao
Can't script

Posts: 2185
Filters: 20
Yep that makes your question much clearer. now we need Sphinx to answer it smile:D
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
I managed to get rid of the unwanted repetitions. It was the spacing settings that caused it. It can only be between 0.01 and 0.04 to work, so I just set it to 0.04 and got rid of the input. Also apparently 30 is the maximum for repetitions for some reason.
Still got some things to fix, but here is an updated version for now. I added in some example shapes, play around with it and try out adding your own smile:-)

stacking mapscript 2.ffxml
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
smile:-)

  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
smile;-)

  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Tiles

  Details E-Mail
Morgantao
Can't script

Posts: 2185
Filters: 20
Looking good!
  Details E-Mail
SpaceRay
SpaceRay

Posts: 12299
Filters: 35
Quote
Sharandra wrote

I managed to get rid of the unwanted repetitions. It was the spacing settings that caused it. It can only be between 0.01 and 0.04 to work, so I just set it to 0.04 and got rid of the input. Also apparently 30 is the maximum for repetitions for some reason.


very good that you found the reason of the unwanted repetitions and have been able to fix it. I like the results and looks good.

Quote
Sharandra wrote
I added in some example shapes, play around with it and try out adding your own


Good idea to add this added shapes and is better for looking at the results and get this nice ball and rings designs. Like how you have done it.

The one I like more is the example shown below, if it would be possible to replace a image with transparency in the place of the balls shown and with the same spacing, it would be really great!!

Thanks very much for working on this and you are doing it very well.

  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Well the spacing setting is fixed, but you could just give your original image more space around it to increase the spacing.

lifesaver with transparency fed into kaleidoscope

  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
with fade and reverse checked

  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Ok, need help again:

Lets say I have a free ellipse. Now I want that to always be for example in the center of the image, no matter what size it is.
How can I convert the OUTPUT_HEIGHT, OUTPUT_WIDTH values to values the offset wants?

Edit: this is what I got so far

Code
function prepare()
   
end;

function get_sample(x, y)
d = ((OUTPUT_HEIGHT/OUTPUT_WIDTH)/2 - 0.5 )

return d, d, d, 1
end;


My problem is that I can get it to work either if the image is higher than wide, or wider than high, but not at the same time.
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Here is an example of what I´m trying to do:

  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
You probably need an IF statement that does a different calculation depending on whether OUTPUT_HEIGHT is bigger or smaller than OUTPUT_WIDTH.
  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
Quote
Sharandra wrote: How can you add a rotation? For example the image around its center, or the duplicates in my script around the center.


Sine, Cosine, ArcSine and ArcCosine can be used to get linear coordinates converted to rotation angles and vice versa. You have to calculate them from the center point (.5,.5) to get the rotation around center.
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Quote
ThreeDee wrote:
You probably need an IF statement that does a different calculation depending on whether OUTPUT_HEIGHT is bigger or smaller than OUTPUT_WIDTH.


Doh! Simple! Why didn´t I think of that?! >.< Thanks Threedee, you´re a star! smile:D

Quote
ThreeDee wrote:
Sine, Cosine, ArcSine and ArcCosine can be used to get linear coordinates converted to rotation angles and vice versa. You have to calculate them from the center point (.5,.5) to get the rotation around center.


Too much Math in one sentence (no offence ment).smile:p But thanks smile:-) Good to know anyway, even tho I have no clue how to calculate that :S
  Details E-Mail
Indigo Ray
Adam

Posts: 1442
Filters: 82
You have to use polar coordinates, Shar.


You already know X (horizontal position) and Y (vertical position).
To convert to polar coordinates:

X = r*cos(theta)
Y = r*sin(theta)

where r = radial distance from the center
and theta = angle around the center

If you want to rotate around the center, you keep r the same but you shift theta.

Hmmm... I should assign you some homework...by next Friday, replicate all of these graphs: smile;)
  Details E-Mail
Sharandra
Filter Forge Addict

Posts: 863
Filters: 26
Oh wow, thx Indigo! You´re a star aswell! smile:-)
I´ll give it a try when I´m finished with my other stuff!!
Not sure about the homework, but I think I can do a simple rotation based on your explanation. 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,712 Registered Users
+19 new in 30 days!

153,534 Posts
+31 new in 30 days!

15,348 Topics
+72 new in year!

Create an Account

Online Users Last minute:

34 unregistered users.