Stop-Motion Calc

Talk about anything at all....

Stop-Motion Calc

Postby imacat » Fri Aug 24, 2012 5:40 am

This is a talk I presented in the Lightning Talk in COSCUP 2012 Taiwan. The origin of this is a video "Stop-Motion Excel" posted on YouTube a week ago:

http://www.youtube.com/watch?v=Fq9EV2fYF2E

This video quickly caught the media discusussion. Not only because it is cool, but also that the viewers found the author was not using Excel, but OpenOffice Calc. This drew a discussion in the OpenOffice development list, too. After watching the video, I felt I can do it programmatically.

http://www.youtube.com/watch?v=AlA7HFwxDSU

(The original Apple iPod Ad)

http://www.youtube.com/watch?v=NlHUz99l-eo

And then I presented it in the lightning talk in COSCUP 2012 Taiwan a week after:

http://www.youtube.com/watch?v=tEhz0zNmTFQ

The files used in the presentation is here for download. ^_*' There is a hidden black button at A1 of the first sheet. Click on the button to start the animation.

It seems that the talk without talk and the fresh-typed presentation is too cool that many people did not notice what I presented. :p But it helps to fill up the room when I presented an introduction to Apache OpenOffice 3.4 the next day.

Welcome to download and try Calc Mosaic.

Hope you like it! Your comment is welcome! ^_*'
User avatar
imacat
Site Admin
 
Posts: 48
Joined: Sun May 20, 2012 1:13 am
Location: Taipei, Taiwan

Re: Stop-Motion Calc

Postby imacat » Fri Aug 24, 2012 3:37 pm

Sorry I forgot: The files used in the presentation is here for download. ^_*' There is a hidden black button at A1 of the first sheet. Click on the button to start the animation.
User avatar
imacat
Site Admin
 
Posts: 48
Joined: Sun May 20, 2012 1:13 am
Location: Taipei, Taiwan

Re: Stop-Motion Calc

Postby Villeroy » Fri Aug 24, 2012 11:43 pm

Your program exposes a weak point of UNO. You access each cell one by one and set the CellBackColor property which is so slow that you can watch a single picture grow pixel by pixel. Do the same in Excel and you will see that API access in Excel is much faster.

The attached document plays a simple stop motion with 16 grey scale colors entirely in Calc. It uses a tiny Basic script to loop the offset value between 0 and frames count -1.
Download the Calc document to some directory where you can execute macros.
Open the document and push the button on the last sheet.
Ctrl+Shift+Q stops the macro loop.

Horse_Movie.ods
Gallop horse by Eadweard Muybridge in a stop motion movie
(65.87 KiB) Downloaded 417 times


 Edit: [2012-08-25] I noticed that yesterday's first draft did not work properly with LibreOffice 3.5 and automatic calculation mode. I uploaded a second version with manual calculation and optional delay parameter. The Movie sheet is protected now (no password). 
Last edited by Villeroy on Sat Aug 25, 2012 8:40 am, edited 2 times in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Stop-Motion Calc

Postby imacat » Sat Aug 25, 2012 5:53 am

Waoh... That looks so cool! It is another approach, and it is faster when populating the cells. Although I suppose you still need a way to paste the color data into the spreadsheet.

Anyway, your work looks so cool! ^_*'
User avatar
imacat
Site Admin
 
Posts: 48
Joined: Sun May 20, 2012 1:13 am
Location: Taipei, Taiwan

Re: Stop-Motion Calc

Postby Villeroy » Sat Aug 25, 2012 8:10 am

:) There is no copy and paste happening. Watch cell Setup.A1 while the movie runs.
Spreadsheets can not loop so I wrote a macro to do the required loop in this particular cell. There is no more macro magic involved other than this most simple loop in this particular cell. The cell is named "offset" and its value is used to dump the right block of color data from the Data sheet into the Frame sheet.
Watch the Frame sheet while the movie runs.

Get the stylist window (F11) and choose the hierarchical view at the bottom of that window. You see a custom cell style "HiddenValue". Its only property is number format "" which simply hides any numeric cell value. This style has 16 children, each with a different background color. So each of these cell styles shows no number in a particular color as demonstrated in column E of the Setup sheet.
The formula in cell A1 on the Movie sheet is =STYLE(LOOKUP($Frame.A1;LookupRange))
Range name LookupRange refers to Setup.B16:C31. $Frame.A1 refers to the relative cell address A1 on the Frame sheet.
Function LOOKUP looks up the current frame's pixel value from the first column of LookupRange and returns the corresponding style name from the last column of LookupRange.
Function STYLE returns zero and applies the looked up cell style. The zero is hidden by the parent style "HiddenValue", the looked up style name applies the color.
Column E of the Setup sheet demonstrates the STYLE function with static values.

memu:Tools>Macros>Organize ... [Horse_Movie.ods]>[Standard]>[Module1], button [Edit...] shows the embedded Basic code. The document has a second macro in Module2 which I used to generate the colored cell styles as substyles of "HiddenValue". When you run that macro while the cells Setup.C16:D31 are selected, the stlye names are taken from the first column and property [int] CellBackColor is taken from the second column of the selected cells.

Where did I get the movie data from?
http://vision.xitek.com/gallery/201204/09-82654.html [Chinese page with animated gif]
http://de.wikipedia.org/wiki/Eadweard_Muybridge [same gif on English Wikipedia]
I used the Gimp image software to export each frame as a C header file which includes the array of decimal values.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Stop-Motion Calc

Postby hanya » Sat Aug 25, 2012 4:05 pm

Hi,
Thanks for both your examples.

I have tried to make my funny macro changes background color faster using conditional format with style: http://hermione.s41.xrea.com/pukiwiki/i ... obbs3%2F27
At that time, I did not try to use STYLE function. But I want to know which one is faster. I made one based on Villeroy's Horse_Movie.ods. But the file is copied sheet by sheet because of I can not edit its style by crash.

Changes are:
- Set 16 conditional formats to the movie range by macro in Module3
- Removed STYLE function but LOOKUP remained searchs in LookupRange2
- LookupRange2 introduced to make ease to compare
Attachments
h1.ods
Based on Villeroy's Horse_Movie.ods.
Using conditional styles.
(69.28 KiB) Downloaded 299 times
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Stop-Motion Calc

Postby Villeroy » Sat Aug 25, 2012 5:46 pm

Indeed, conditional formatting is twice as fast as the STYLE function.
Add a cell named FPS and this modified loop:
Code: Select all   Expand viewCollapse view
Sub StartMovie2()
n=0
With ThisComponent.NamedRanges
   c = .getByName("offset").getReferredCells.getCellByPosition(0,0)
   f = .getByName("Frames").getReferredCells.getCellByPosition(0,0).getValue()
   d = .getByName("Delay").getReferredCells.getCellByPosition(0,0).getValue()
   fps = .getByName("FPS").getReferredCells.getCellByPosition(0,0)
End With
t = timer
do
   x = n Mod f
   c.setValue(x)
   ThisComponent.calculate()
   n = n +1
   if (n mod 50)=0 then fps.setValue(n/(timer - t))
   wait d
loop
ThisComponent.setModified(False)
End Sub


Let's implement an action shooter in Calc.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Stop-Motion Calc

Postby hanya » Sat Aug 25, 2012 6:41 pm

Once I add the following line at the the start of StartMovie2, running the horse is very somooth.
Code: Select all   Expand viewCollapse view
ThisComponent.lockControllers()
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Stop-Motion Calc

Postby Villeroy » Sun Aug 26, 2012 8:31 am

The LOOKUP is no longer needed when your format conditions compare by 2 expressions (between <expr1> and <expr2>). You can dump the frame sheet's formula array right into the movie sheet and delete the frame sheet.
With a frame rate of 90 on my fast new machine it makes sense to apply the delay parameter. A delay of 25ms gives a natural speed again. When I find some time this Sunday, I'll try the full color space 256 shades of grey.
Thank you very much for your important contribution to my little experiment.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Stop-Motion Calc

Postby Villeroy » Mon Aug 27, 2012 5:29 pm

Short update on this little project:
I created another test document with 256 styles covering the color space of the original stop motion video using the same grid of 47x32 cells. I think with 256 RGB colors we could play attractive colorful stuff.
I measured frame rates with conditional formatting and some cell functions with STYLE and lookup tables or directly calculating the style name from a number.
With 16 and 32 colors conditional formatting is much faster. Locked controllers get you some other 20%. When you lock the controllers while using the function approach you don't see anything move.
With 256 colors, both versions are darn slow but the STYLE version is several times faster still giving the impression of a stop motion movie.
64 colors seem to be a good compromise. Both versions run at natural speed on my fairly recent 2x2GHz laptop.

I found that my little macro suite for conditional formatting is very helpful in this context. It lets you fill out a named range with many format conditions and a macro reads the conditions from the name range into a selected range just like the built-in dialog would do.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Stop-Motion Calc

Postby Villeroy » Sun Sep 02, 2012 4:49 pm

The attached version is the best I can achieve for this little experiment.
It includes slightly improved Basic macros, including a macro to stop the movie and reset the document's controller and modified state.
The downloadable spreadsheet comes with the full set of 256 styles representing the entire greyscale of the raw data.
The currently set color space reflects the 215 colors that actually occur in the raw data.

Then there is a some documentation, a performance table, a scenario range for different color spaces and blue push buttons that linked to a global Python module <user_profile>/Scripts/python/pyCalc/ConditionalFormats.py which is downloadable here: http://user.services.openoffice.org/en/ ... =21&t=6039
That Python macro is not required to run the demo. It adds the ability to apply hundreds of conditional formattings. The AOO GUI dialog is still limited to 3 (which is a shame).
Attachments
Horse_Movie_CF.ods
Stop motion with conditional formatting and color spaces in scenarios.
(96.61 KiB) Downloaded 289 times
Last edited by Villeroy on Thu Dec 06, 2012 8:02 pm, edited 1 time in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Stop-Motion Calc

Postby imacat » Sun Oct 07, 2012 7:54 pm

Villeroy wrote:The attached version is the best I can achieve for this little experiment.
It includes slightly improved Basic macros, including a macro to stop the movie and reset the document's controller and modified state.
The downloadable spreadsheet comes with the full set of 256 styles representing the entire greyscale of the raw data.
The currently set color space reflects the 215 colors that actually occur in the raw data.
Then there is a some documentation, a performance table, a scenario range for different color spaces and blue push buttons that linked to a global Python module <user_profile>/Scripts/python/pyCalc/ConditionalFormats.py which is downloadable here: http://user.services.openoffice.org/en/ ... =21&t=6039


I tried to read your code. To tell the truth, I do not understand. ^^; How do these data become the horse? I have no idea. You are really smart!

Anyway, I was inspired by your idea to put the color values in the cells for the BASIC macros to read and process it, though I ended up with another approach that is slightly faster and has shorter codes. (8 times than faster than the previous version. Not faster than your approach. But we are doing two different things, though.) I will present it in my talk in ApacheCon EU 2012. For those who are interested, you may download it at: http://sf.net/p/calcmosaic . ^_*'
User avatar
imacat
Site Admin
 
Posts: 48
Joined: Sun May 20, 2012 1:13 am
Location: Taipei, Taiwan

Re: Stop-Motion Calc

Postby Villeroy » Sun Oct 07, 2012 11:07 pm

The latest version (inspired by hanya) uses Format>Conditional Formatting... with 215 different cell styles based on the 215 distinct color values existing on the first sheet.
The GUI dialog can only handle 3 conditions in AOO. In LibreOffice the dialog has been extended to show all conditions. I use a Python macro to apply the 215 conditional formattings.
The base style is "Black" with color code 0x000000 and number format "". Number format "" displays nothing for any numeric value.
Based on that "Black" cell style there are 214 child styles with different background colors.
Now the simple macro loops the offset counter BB1 and the screen's OFFSET formula in A1:AU32 pulls the right color value from the data sheet without showing any value but showing the right background color by means of conditional formatting.

All this has been programmed in C++ by the clever programmers of the Calc component.
All I added is a tiny Basic macro for the loop, another macro to add the colored cell styles and a Python macro which makes the creation of 215 format conditions quick and easy. Only the first Basic macro not required to run the movie.

My first version uses cell function STYLE which is a little bit slow but much easier to use. STYLE("FFFFFF") returns zero and applies the style named "FFFFFF".
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests