失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Photoshop脚本 设置前景色和背景色

Photoshop脚本 设置前景色和背景色

时间:2019-05-28 18:20:45

相关推荐

Photoshop脚本  设置前景色和背景色

源自:/tutorials/menu1lesson8.php

本节将演示如何使用脚本,设置Photoshop的前景色和背景色。首先创建一个空白的脚本文档,并保存在硬盘上某个位置。

并输入脚本代码:

var answer = confirm("您需要随机设置前景色和背景色吗?");

[confirm]命令会弹出一个包含[是/否]的确认框,由用户决定是否执行某一个操作。

选择的结果[是/否]将保存在[answer]变量里。

if(answer) {app.foregroundColor.rgb.red = Math.random() * 255;app.foregroundColor.rgb.green = Math.random() * 255;app.foregroundColor.rgb.blue = Math.random() * 255;app.backgroundColor.rgb.red = Math.random() * 255;app.backgroundColor.rgb.green = Math.random() * 255;app.backgroundColor.rgb.blue = Math.random() * 255;}

判断用户的选择,如果用户选择[是],则执行接下来的动作。

然后就可以设置Photoshop前景色和背景色了。

[Math.random]命令会生成一个0至1之间的随机值,随机值乘以255则生成0-255之间的随机值。

完整的脚本文件:

var answer = confirm("您需要随机设置前景色和背景色吗?");if(answer) {app.foregroundColor.rgb.red = Math.random() * 255;app.foregroundColor.rgb.green = Math.random() * 255;app.foregroundColor.rgb.blue = Math.random() * 255;app.backgroundColor.rgb.red = Math.random() * 255;app.backgroundColor.rgb.green = Math.random() * 255;app.backgroundColor.rgb.blue = Math.random() * 255;}

我们的脚本已经编写完成,现在把它保存下来。

然后切换到Photoshop,然后依次点击[文件] > [脚本] > [浏览],打开刚刚保存的脚本文件。Photoshop将直接调用并执行该脚本。

在弹出的[脚本警告]弹出框窗口,点击[是]按钮,开始设置前景色和背景色,请留意工具条下方前景色和背景色的变化。

如果觉得《Photoshop脚本 设置前景色和背景色》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。