Author Topic: PanAndScan module v1.2 release  (Read 22918 times)

chrisvg

  • Full Member
  • ***
  • Posts: 78
    • View Profile
PanAndScan module v1.2 release
« on: March 13, 2016, 03:18:58 PM »
Code: [Select]
CHANGELOG
    Version 0.1     (8th December 2015)     - Initial release (included in Blastcity layout)
    Version 1.0     (14th March 2016)       - Complete rewrite to extend PreserveArt module
    Version 1.1     (14th March 2016)       - Added start_scale and randomize_on_transition
    Version 1.2     (22th March 2016)       - Fixed bug with bounce animation when art is smaller than surface

After a bit of prodding from Verion (ouch!), I finally got around to rewriting the PanAndScan module I included with my previous Blastcity layout! :P

This version of the module extends liquid8d's excellent PreserveArt module.  I have included the most recent version (1.0) of his module in the archive.  You can find this and his other projects hosted at his github repo.

With liquid8d's module you can define an arbitrary space on the screen and place an art or image object in there, either scaled to fit within the space, or to fill it, while preserving the original aspect ratio.

My module extends this functionality by adding a "Pan and Scan" style animation to it.  This allows you to either scroll the art/image object side to side, up and down, or in all four directions.  It also allows you to zoom in to the image to a desired scale (happy now Verion? ;)).

Example usage:

Code: [Select]
fe.load_module("pan-and-scan");

local my_art = PanAndScanArt("flyer", 0, 0, 640,480);

my_art.set_fit_or_fill("fill");
my_art.set_anchor(::Anchor.Center);
my_art.set_zoom(4.5, 0.00008);
my_art.set_animate(::AnimateType.Bounce, 0.07, 0.07)
my_art.set_randomize_on_transition(true);
my_art.set_start_scale(1.15);


Breakdown of each command:

First thing we load the module into the layout...
Code: [Select]
fe.load_module("pan-and-scan");
Then create an instance of the module class. Arguments are: art type, x pos, y pos, surface width, surface height
(Also, you can replace PanAndScanArt() with PanAndScanImage() if you want to use an image in your layout directory)
Code: [Select]
local my_art = PanAndScanArt("flyer", 0, 0, 640, 480);
Tell the module whether you want to make the loaded art/image "fit" the size of the surface you've created, or to "fill" the surface.  I'd recommend sticking with "fill" for the purpose of this module, though you may find a use for "fit" in some cases.
Code: [Select]
my_art.set_fit_or_fill("fill");
Configure the anchor point for the art/image.  When you have zooming and scrolling going on, I find Center to be the best option here. Other choices for the ::Anchor table include .Left, .Top, .Center, .Centre (same as .Center), .Right, and .Bottom.
Code: [Select]
my_art.set_anchor(::Anchor.Center);
Here is where the fun stuff starts (no offence to liquid8d!).  Arguments are: zoom scale, zoom speed
For the scale, note that 1.0 is the actual art/image scale displayed on the surface prior to zooming. So, if you want to end up with the image doubled in size at the end of the zoom animation, you'd enter 2.0
Code: [Select]
my_art.set_zoom(2.5, 0.0002);
This sets the pan and scan animation.  Arguments are: animation type, x/y speed, [y speed].
Choices for the ::AnimateType table include .Bounce, .HorizBounce, and .VertBounce.  If using Horiz or Vert, only 1 speed argument is needed.
Code: [Select]
my_art.set_animate(::AnimateType.Bounce, 0.1, 0.1)
Enabling this will randomize the pan animation direction when transitioning to another list item.
Code: [Select]
my_art.set_randomize_on_transition(true);
Alter the starting scale of the image after it has been processed by PreserveArt.  I found this helps to remove some of the initial "wiggle" as the pan animation bounces from side to side at the beginning.
Code: [Select]
my_art.set_start_scale(1.15);

I think I've covered everything.  Have a play around with it and see what you think.  I mostly created this to have animated backgrounds, zooming and panning around large flyer images and such.  Let me know if you manage to break it some how and I'll take a look, or if anyone has some suggestions for improvements then I'm all ears!
« Last Edit: March 21, 2016, 06:31:49 AM by chrisvg »

verion

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 861
    • View Profile
    • new projects
Re: PanAndScan module v1.0 release
« Reply #1 on: March 13, 2016, 03:34:42 PM »
Quote
happy now Verion?

You bet!
I'm gonna test it tomorrow - because today I have to beat the clock and get one of my payed projects finished in time.

bionictoothpick

  • Sr. Member
  • ****
  • Posts: 320
  • He who laughs lasts.
    • View Profile
Re: PanAndScan module v1.0 release
« Reply #2 on: March 13, 2016, 04:43:09 PM »
This is exciting. Don't know how I'll use it yet, but I have an idea.

Is there another module I should be loading? I'm only getting a static image and this error:
Script Error in /home/toothpick/.attract/layouts/Panning/layout.nut - wrong number of parameters

_______Code Below

fe.load_module("pan-and-scan");
fe.layout.width=1024;
fe.layout.height=768;

local my_art = PanAndScanArt("fanart", 0, 0, 480, 480);
my_art.set_fit_or_fill("fill");
my_art.set_anchor(::Anchor.Center);
my_art.set_zoom(true, 2.5, 0.0002);
my_art.set_animate(::AnimateType.Bounce, 0.1, 0.1);
« Last Edit: March 13, 2016, 04:47:43 PM by bionictoothpick »

chrisvg

  • Full Member
  • ***
  • Posts: 78
    • View Profile
Re: PanAndScan module v1.0 release
« Reply #3 on: March 13, 2016, 08:11:19 PM »
Script Error in /home/toothpick/.attract/layouts/Panning/layout.nut - wrong number of parameters

Ahh, there was a typo in my post.  use this line instead:

Code: [Select]
my_art.set_zoom(2.5, 0.0002);
ie: get rid of the "true" param and you should be sweet!


chrisvg

  • Full Member
  • ***
  • Posts: 78
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #4 on: March 13, 2016, 10:22:31 PM »
VERSION 1.1 RELEASED

added the following functions:

set_randomize_on_transition(bool)
set_start_scale(float)

See initial post for updated download and explanation.

bionictoothpick

  • Sr. Member
  • ****
  • Posts: 320
  • He who laughs lasts.
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #5 on: March 14, 2016, 03:10:59 AM »
Chrisvg, thanks. Removing the true did indeed work.

Would it be time consuming to have the zoom choose an x,y to be the center of the final zoom?
« Last Edit: March 14, 2016, 03:17:16 AM by bionictoothpick »

chrisvg

  • Full Member
  • ***
  • Posts: 78
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #6 on: March 14, 2016, 04:07:08 AM »
Would it be time consuming to have the zoom choose an x,y to be the center of the final zoom?

If you just want it to zoom without panning around, you can simply omit the set_animate() function call.

Upon reflection set_animate() is probably a misleading name, but it will only set the panning animation, which is handled separately from the zoom animation.

Also, while it is not possible to set x,y coordinates for the zoom direction, you can use the set_anchor() function to make the zoom to go towards one of the edges instead of the center of the image.

The ::Anchor table includes the following members: Left, Top, Center, Centre (same as Center), Right, Bottom.

So you could call:
Code: [Select]
my_art.set_anchor(::Anchor.Left);and it will make the zoom go towards the left edge of the image.

Is that what you are looking for?
« Last Edit: March 14, 2016, 04:14:01 AM by chrisvg »

bionictoothpick

  • Sr. Member
  • ****
  • Posts: 320
  • He who laughs lasts.
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #7 on: March 14, 2016, 04:14:38 AM »
What I mean is say your image is 1000,1000 but you want the end of the zoom to show the center as 300,325.

chrisvg

  • Full Member
  • ***
  • Posts: 78
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #8 on: March 14, 2016, 04:23:23 AM »
What I mean is say your image is 1000,1000 but you want the end of the zoom to show the center as 300,325.

I see.  I don't currently have plans to add support for zooming in to an arbitrary location of the image other than the current anchor points, I'll certainly keep it in mind for future updates to the module.

Alternatively, I don't have any issues with people making changes to the module to suit their own needs.  If you want to add the functionality you want, go right ahead! :)

bionictoothpick

  • Sr. Member
  • ****
  • Posts: 320
  • He who laughs lasts.
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #9 on: March 14, 2016, 11:47:15 AM »
This does allow customization, but it's not working as hoped...more of a proof of concept...or proof of failure.

I am enjoying your plugin...the zoom feature reminds me of a Prezi...

layout.nut:
customx <- 1; <2 this is what the width is divided by for the zoom until it's reached.
customy <- 2; <2 this is what the height is divided by for the zoom until it's reached.

preserve-art-nut
::Anchor <-
{
   Custom = "Custom",
___________________________
case ::Anchor.Custom:
art.x -= (art.width - _prev_art_width) / ::customx
art.y -= (art.height - _prev_art_height) / ::customy
break;

pan-and-scan.nut
case ::Anchor.Custom:
art.x -= (art.width - _prev_art_width) / ::customx
art.y -= (art.height - _prev_art_height) / ::customy
break;
« Last Edit: March 14, 2016, 06:01:43 PM by bionictoothpick »

chrisvg

  • Full Member
  • ***
  • Posts: 78
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #10 on: March 15, 2016, 09:40:02 PM »
Ninja update - 1.1a

No changes to the PanAndScan module, I just noticed that I had left debug mode enabled in the PreserveArt module by mistake.  Debug mode is now disabled by default.

I have updated the original post with a new download link.

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #11 on: March 16, 2016, 11:10:22 PM »
This looks great!  I hope you don't mind but I'm going to include this in the package for the next version of Attract-Mode

chrisvg

  • Full Member
  • ***
  • Posts: 78
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #12 on: March 16, 2016, 11:34:17 PM »
This looks great!  I hope you don't mind but I'm going to include this in the package for the next version of Attract-Mode

Hey raygun!

By all means, I'm happy for it to be included with AM :)

You may also want to include a couple of other things I've posted today - an updated LEDBlinky plugin that resolves the crashes at startup, and an enhanced version of the intro video script that handles aspect ratios and monitor rotation.

bionictoothpick

  • Sr. Member
  • ****
  • Posts: 320
  • He who laughs lasts.
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #13 on: March 20, 2016, 06:11:06 PM »
If you choose horizontal, is it supposed to bounce back and forth? It seems to stop when using Horiz when it reaches edge.

chrisvg

  • Full Member
  • ***
  • Posts: 78
    • View Profile
Re: PanAndScan module v1.1 release
« Reply #14 on: March 20, 2016, 08:18:14 PM »
If you choose horizontal, is it supposed to bounce back and forth? It seems to stop when using Horiz when it reaches edge.

could you please post a code sample and the image you are using that is causing the bug?
also, which version of the module are you using?