C语言 Applescript或Automator,用于从网站逐步保存曼德布洛特图像



>您好,我最近为我的UNI计算课程创建了一个C程序,该程序在localhost:2020上生成一个Web服务器,并发送曼德布洛特集合的bmp文件。如果您不知道那是什么,请不要担心,重要的是 url 部分。网址的格式如下

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

所以
http://localhost:2020/X_-0.15_1.03_56.bmp

返回

x: -0.15
y:1.03
变焦:56

我的目标是有一个自动化过程,可以采取x,y位置(在代码中很好)并从服务器重复加载图像,每次缩放级别增加.01并将其保存到文件夹中,或者最好将它们全部加载到文件中以呈现为视频。我很清楚这在 C 中更容易完成,只需将其保存到文件中,但我的目标是熟悉 applescript/automator 或具有此类任务的类似程序。它旨在为我自己提供有趣的学习体验,我将非常感谢我能得到的任何帮助。

这样的事情可能适用于您的部分任务。我们正在使用 unix 命令行实用程序"curl"下载所有图像(在每个缩放级别)。每个图像都以 url 中的名称保存到您选择的文件夹中。我们将此代码放在重复循环中,以便可以增加缩放级别。

该脚本显示了很多东西,特别是如何将变量直接插入Applescript(例如硬编码)以及如何从用户那里获取输入。它还展示了如何从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

最新更新