安装主题
我按照你的要求创建了一个带有淡化的Ubuntu标志的主题(此外,我还添加了一个Ubuntu标志的动画。希望你会喜欢它 :-P)
截图
![Spinning Ubuntu logo and the Ubuntu text logo with a moving fade effect.](https://istack.dev59.com/taN7r.gif)
想要亲眼看看吗?
点击http://www.youtube.com/watch?v=zPo50gM3txU查看。
你从哪里可以获得这个主题?
我已经上传到Mediafire云端,点击这里。
如何安装它?
从上面的链接下载,保存在桌面上,然后逐个执行以下命令。
如果你使用的是16.04或更新版本,请将命令中的/lib/plymouth/themes
替换为/usr/share/plymouth/themes
。
cd ~/Desktop/
tar -xf ubuntufaded.tar
sudo cp -r ubuntu-faded-screen '/lib/plymouth/themes'
sudo rm '/lib/plymouth/themes/default.plymouth'
sudo ln -s '/lib/plymouth/themes/ubuntu-faded-screen/ubuntu-faded-screen.plymouth' '/lib/plymouth/themes/default.plymouth'
sudo update-initramfs -u
如何检查它?
1. 重新启动Ubuntu,您将在启动和关闭时看到一个漂亮的动画。或者
2. 将下面的整个命令复制并粘贴到终端中,然后按回车键。(您可能需要安装一个软件包:sudo apt-get install plymouth-x11)
sudo plymouthd --debug --debug-file=/tmp/plymouth-debug-out ; sudo plymouth --show-splash ; for ((I=0;I<10;I++)); do sleep 1 ; sudo plymouth --update=event$I ; done ; sudo plymouth --quit
如何自己创建Plymouth主题
Plymouth脚本语言与C或JavaScript非常相似。如果您了解这些语言,那么自己创建Plymouth脚本将非常容易。
让我们从基础知识开始,比如运算符、循环、注释等。支持三种类型的注释。
# comment like in bash
// single line comment like in C
/* block comments */
语句以分号结束,例如:
foo = 10;
语句块可以用花括号创建,例如:
{
foo = 10;
z = foo + foo;
}
支持的运算符有
+
、
-
、
*
、
/
、
%
。
还支持简写赋值运算符
+=, -=, *=,
等等。
也支持一元运算符,例如。
foo *= ++z;
+ 用于连接字符串,例如:
foo = "Jun" + 7; # here foo is "Jun7"
比较运算符示例:
x = (3 >= 1); # assign 1 to x because it's true
y = ("foo" == "bar"); # assign 0 to y because it's false
条件操作和循环:
if (foo > 4)
{
foo--;
z = 1;
}
else
z = 0;
while (foo--)
z *= foo;
&&
, ||
, !
也是受支持的。
if ( foo > 0 && foo <4 )
这对许多读者来说可能是新鲜事物:哈希,类似于数组。可以通过使用“点”或“[ ]”括号来访问它们的内容来创建哈希,例如。
foo.a = 5;
x = foo["a"] ; # x equals to 5
使用
fun
关键字来定义函数,例如。
fun animator (param1, param2, param3)
{
if (param1 == param2)
return param2;
else
return param3;
}
两个基本的Plymouth对象
图像
要创建一个新的图像,请将主题目录中的图像文件名提供给Image()
。请记住,只支持.png文件。例如:
background = Image ("black.png");
要显示文本消息,您必须创建一个文本的
Image
。(这可能会让您感到惊讶。)例如:
text_message_image = Image.Text("I love Ubuntu");
可以使用
GetWidth()
和
GetHeight()
来获取宽度和高度;例如:
image_area = background.GetWidth() * background.GetHeight();
一个可以旋转或改变图像大小的例子是:
down_image = logo_image.Rotate (3.1415); # Image can be Rotated. Parameter to Rotate is the angle in radians
fat_image = background.Scale ( background.GetWidth() * 4 , background.GetHeight () ) # make the image four times the width
精灵
使用 精灵
在屏幕上放置一个 图像
。
创建一个 精灵
:
first_sprite = Sprite ();
first_sprite.SetImage (background);
通过向其构造函数提供图像,
first_sprite = Sprite (background);
如何将不同的精灵设置到屏幕上的不同位置(x,y,z):
first_sprite.SetX (300); # put at x=300
first_sprite.SetY (200); # put at y=200
background.SetZ(-20);
foreground.SetZ(50);
或者你可以使用
SetPosition()
一次性设置所有位置:
first_sprite.Setposition(300, 200, 50) # put at x=300, y=200, z=50
改变透明度:
faded_sprite.SetOpacity (0.3);
invisible_sprite.SetOpacity (0);
一些常用的杂项方法包括:
Window.GetWidth();
Window.GetHeight();
Window.SetBackgroundTopColor (0.5, 0, 0); # RGB values between 0 to 1.
Window.SetBackgroundBottomColor (0.4, 0.3, 0.6);
Plymouth.GetMode(); # returns a string of one of: "boot", "shutdown", "suspend", "resume" or unknown.
etc.
预定义函数
Plymouth.SetRefreshFunction (function); # Calling Plymouth.SetRefreshFunction with a function will set that function to be called up to 50 times every second
Plymouth.SetBootProgressFunction(); # function is called with two numbers, time spent booting so far and the progress (between 0 and 1)
Plymouth.SetRootMountedFunction(); # function is called when a new root is mounted
Plymouth.SetKeyboardInputFunction(); # function is called with a string containing a new character entered on the keyboard
Plymouth.SetUpdateStatusFunction(); # function is called with the new boot status string
Plymouth.SetDisplayPasswordFunction(); # function is called when the display should display a password dialogue. First param is prompt string, the second is the number of bullets.
Plymouth.SetDisplayQuestionFunction(); # function is called when the display should display a question dialogue. First param is prompt string, the second is the entry contents.
Plymouth.SetDisplayNormalFunction(); # function is called when the display should return to normal
Plymouth.SetMessageFunction(); # function is called when new message should be displayed. First arg is message to display.
数学函数
Math.Abs()
Math.Min()
Math.Pi()
Math.Cos()
Math.Random()
Math.Int()
etc.
修改现有脚本比从头开始更好。
打开我上传的主题中的.script
文件,并尝试理解它的功能。你可以在这里找到一个很棒的指南。
我相信你会学会的,这并不难。如果你需要任何帮助,请告诉我。
希望这对你自己创建一个脚本有所帮助。
回答Roshan George的评论:
是否可能将默认Plymouth主题“ubuntu-logo”中的紫色背景替换为图像?
background = Image ("your-image.png");
sprite = Sprite (background.Scale (Window.GetWidth(), Window.GetHeight()));
sprite.SetX (0); # put at x=0
sprite.SetY (0); # put at y=0
你可能需要添加
sprite.SetZ (-10);
你应该移除
Window.SetBackgroundTopColor (p, q, r);
Window.SetBackgroundBottomColor (a, b, c);
其中 p, q, r, a, b, c
是一些值。
更多链接
sudo ln -s '/lib/plymouth/themes/your-theme/your-script.plymouth' '/lib/plymouth/themes/default.plymouth'; sudo update-initramfs -u
吗?这个命令会改变你的默认 plymouth 主题并更新 initrd 文件。 - Rahul Virparaplymouth-x11
进行检查吗? - Rahul Virparainitrd
文件放进了你的squashfs
和iso
文件里吗? - Rahul Virparachroot
来完成这个任务。你不应该将你的/boot/initrd
放到提取出来的文件系统(从.squashfs
中)。请等一天或两天。我会在这里发布完整的指南。 - Rahul Virpara/usr/share/plymouth/themes
。 - Olivier