2012-04-15 35 views
0

您好,我最近爲我的UNI Computing課程創建了一個C程序,該課程在localhost:2020生成一個web服務器併發送Mandelbrot集的bmp文件。如果你不知道那是什麼,不用擔心,它的url部分很重要。 該網址的格式爲使
http://localhost:2020/X_-0.15_1.03_56.bmpApplescript或Automator從網站上快速保存Mandelbrot圖像

回報

X如下

http://X_(x coordinate)_(y coordinate)_(Zoom Level).bmp

:-0.15
Y:1.03
變焦:56

我的目標在這裏是有一個自動化的過程,可以取一個x,y的位置(在代碼中是好的),並重復從服務器加載圖像,每次將縮放級別增加.01,並將其保存到一個文件夾中,或者最好將它們全部加載到文件中以視頻形式呈現。 我很清楚,在C中這樣做會更容易,只需將它保存到文件中,但我的目標是讓自己熟悉applescript/automator或類似的程序來處理這類任務。 它的設計是一個有趣的學習經驗,我會很感激任何幫助,我可以得到謝謝。

回答

1

像這樣的東西可能適用於您的任務的一部分。我們正在使用unix命令行工具「curl」下載所有圖像(在每個縮放級別)。每個圖像都會以url的名稱保存到您選擇的文件夾中。我們把這段代碼放在重複循環中,這樣我們可以增加縮放級別。

該腳本顯示了很多東西,特別是如何將變量直接插入到蘋果腳本(例如硬編碼)以及如何從用戶獲取輸入。它還顯示瞭如何從applescript(例如curl)中運行命令行實用程序。

所以這個腳本應該讓你開始。看看它是否有幫助。

-- hard-coded variables 
set minZoomLevel to 0 
set maxZoomLevel to 10 
set zoomIncrement to 0.1 

-- get user input variables 
set outputFolder to choose folder with prompt "Pick the output folder for the images" 
set xDialog to display dialog "Enter the X coordinate" default answer "" 
set yDialog to display dialog "Enter the Y coordinate" default answer "" 

set posixStyleOutputFolder to POSIX path of outputFolder 
set x to text returned of xDialog 
set y to text returned of yDialog 

set i to minZoomLevel 
repeat while i is less than or equal to maxZoomLevel 
    set fileName to "X_" & x & "_" & y & "_" & (i as text) & ".bmp" 
    set theURL to "http://localhost:2020/" & fileName 
    do shell script "curl " & theURL & " -o " & quoted form of (posixStyleOutputFolder & fileName) 
    set i to i + zoomIncrement 
end repeat 
+0

非常感謝你,這工作得很好。什麼是一個好的程序,可以將一組圖像加入到視頻或gif中? – Jordan 2012-04-15 22:31:34

+0

嗨,很高興代碼適合你。我不確定如何從所有圖像中製作一個大圖像文件。不過,您可以輕鬆地從充滿圖像的文件夾製作視頻。舊版本的quicktime(Quicktime Player 7)這樣做......我不確定新玩家(Quicktime Player X)是否具備此功能。有可能爲QT7提供的applescript代碼(谷歌爲它)。 – regulus6633 2012-04-16 14:15:30

+0

我強烈推薦非常強大,靈活且可自定義的命令行程序['mencoder'](http://www.mplayerhq.hu/design7/projects.html#unofficial_packages)(附帶'mplayer')。以下是[如何從一組圖片製作電影]手冊的部分內容(http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-images.html)。 – fanaugen 2012-04-16 14:59:31