Celestia

Форк
0
/
overlay_demo.celx 
172 строки · 6.9 Кб
1
-- ---------------------------------------------------------------------------------------
2
-- This file demonstrates the 'celestia:overlay' command
3
-- The command allows you to display an image in the format BMP, JPG, PNG, which must be
4
-- Pre-located in the "images" folder or its sub-folders of the Celestia main directory.
5
-- Supports image scaling, transparency and positioning.
6
-- Script author: Vincent (June 2006, contact: vince.gian@free.fr)
7
-- Modified by: Sergey Leonov aka Leserg <leserg@ua.fm>
8
--
9
--  This command accepts 6 arguments:
10
--
11
--  celestia:overlay ( float [duration], float [xoffset], float [yoffset], float [alpha], str [filename], int [fitscreen] )
12
--
13
--  duration  - Determines the duration of the image display.
14
--              If not specified, the default time is 3 seconds.
15
--
16
--  xoffset   - Determines the placement of the image horizontally
17
--              relative to the center of the working area of the Celestia window.
18
--              If not specified,  the default value is 0.0.
19
--              Valid values are in the range from -1 to 1 relative to the center of the Celestia window:
20
--	             > if xoffset = -1 -> The image is placed in the center of the left edge
21
--                 Celestia window => You will only see the right half of the image;
22
--	             > if xoffset = 1 -> The image is placed in the center of the right edge
23
--                 Celestia window => You will only see the left half of the image;
24
--
25
--  yoffset   - Determines the placement of the image vertically
26
--              relative to the center of the working area of the Celestia window.
27
--              If not specified,  the default value is 0.0.
28
--              Valid values are in the range from -1 to 1 relative to the center of the Celestia window:
29
--	             > if yoffset = -1 -> The image is placed in the center of the bottom edge
30
--                 of Celestia window => You will only see the upper half of the image;
31
--	             > if yoffset = 1 -> The image is placed in the center of the upper edge
32
--                 of Celestia window => You will only see the bottom half of the image;
33
-- 	             > if xoffset = 0.0 and yoffset = 0.0 -> The image is centered.
34
--
35
--  alpha     - Determines the transparency of the image on the screen.
36
--              If not specified,  the default value is 1.0
37
--              Valid values are in the range from 0.0 to 1.0
38
--               > if alpha = 0.0 -> The image is completely transparent (ie invisible);
39
--               > if alpha = 1.0 -> The image is opaque (i.e., fully visible).
40
--
41
--  filename  - Specifies the name of the image file to display.
42
--              The search for files is relative to the "images" subfolder,
43
--              which should be located in the Celestia main directory.
44
--              Thus, all the images for display using the script command must be in the
45
--              "images" folder or its subfolders.
46
--
47
--  fitscreen - Determines the image zoom mode:
48
--               > if fitscreen = 0 -> The image will be shown in the original size;
49
--               > if fitscreen = 1 -> The image will be scaled by the Celestia window.
50
--              If not specified,  the default value is 0.
51
--  --------------------------------------------------------------------------------------
52

53
celestia:print ( "Welcome!\n\nYou start a script with examples of displaying the image on the screen.", 5.0, -1, -1, 3, 5 )
54
wait (5)
55

56
-- ======< Example 1 >======
57
-- In the center of the Celestia window, display the image file "image.jpg". Time 6 seconds.
58
-- Set the transparency level to 0.7. The parameter 'fitscreen' is used with default value,
59
-- so do not specify it.
60
celestia:overlay ( 6, 0, 0, 0.7, "image.jpg" )
61
wait(1)
62
celestia:print ( "The image is placed in the center of the window.", 4.0, -1, -1, 3, 5 )
63
wait(4)
64
wait(2)
65

66
-- ======< Example 2 >======
67
-- We will deduce on the center an image file "image.jpg" and we will deploy it on all window Celestia.
68
-- Set the transparency level to 0.5. Time 6 seconds.
69
celestia:overlay ( 6, 0, 0, 0.5, "image.jpg", 1 )
70
wait(1)
71

72
celestia:print ( "The image is maximized on the whole window.", 4.0, -1, -1, 3, 5 )
73
wait(4)
74
wait(2)
75

76
-- ======< Example 3 >======
77
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
-- Now we will display the image sequentially at the corners of the Celestia window.
79
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80

81
-- The original width of the image in pixels
82
image_width = 512
83
-- The original height of the image in pixels
84
image_height = 256
85
-- Determine the width and height for the working area of the Celestia window
86
screen_width, screen_height = celestia:getscreendimension()
87

88
xoffset_left = (image_width/screen_width) - 1
89
-- (xoffset_right = - xoffset_left).
90
xoffset_right = 1 - (image_width/screen_width)
91
yoffset_bottom = (image_height/screen_height) - 1
92
-- (yoffset_top = - yoffset_bottom).
93
yoffset_top = 1 - (image_height/screen_height)
94

95
celestia:print ( "Now the image will be shown at the corners of the window.", 5.0, -1, -1, 3, 5 )
96
wait(6)
97

98
celestia:overlay (3, xoffset_left, yoffset_bottom, 0.5, "image.jpg")
99
wait(3)
100

101
celestia:overlay (3, xoffset_left, yoffset_top, 0.5, "image.jpg")
102
wait(3)
103

104
celestia:overlay (3, xoffset_right, yoffset_top, 0.5, "image.jpg")
105
wait(3)
106

107
celestia:overlay (3, xoffset_right, yoffset_bottom, 0.5, "image.jpg")
108
wait(3)
109
wait(1)
110

111

112
-- ======< Example 4 >======
113
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114
--   Now the image will move around the screen with the 'ping-pong' effect.
115
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116

117
x_pos = 0
118
y_pos = 0
119
x_mod = 0.05
120
y_mod = 0.05
121
script_running = true
122

123
celestia:print ( "Now the image will move around the screen.", 5.0, -1, -1, 3, 5 )
124
wait(5)
125
wait(1)
126

127
-- Define the keystroke processing function
128
function celestia_keyboard_callback(str)
129
		script_running = false
130
end
131
-- Enable event handling by keystrokes
132
celestia:requestkeyboard(true)
133

134
-- Run the execution of the loop, which will work until you press any key on the keyboard.
135
while script_running do
136
	image_width = 512
137
	image_height = 256
138
	screen_width, screen_height = celestia:getscreendimension()
139
	xoffset_left = (image_width/screen_width) - 1
140
	xoffset_right = - xoffset_left
141
	yoffset_bottom = (image_height/screen_height) - 1
142
	yoffset_top = - yoffset_bottom
143

144
	if x_pos <  xoffset_left then
145
		x_pos = xoffset_left
146
		x_mod = 0.02
147
	end
148

149
	if x_pos >  xoffset_right then
150
		x_pos = xoffset_right
151
		x_mod = -0.02
152
	end
153

154
	if y_pos <  yoffset_bottom then
155
		y_pos = yoffset_bottom
156
		y_mod = 0.02
157
	end
158

159
	if y_pos >  yoffset_top then
160
		y_pos = yoffset_top
161
		y_mod = -0.02
162
	end
163

164
-- Display the image on the screen, according to the calculated coordinates.
165
	celestia:overlay (0.01, x_pos, y_pos, 0.5, "image.jpg")
166
-- Calculate the new coordinates of the image.
167
	x_pos = x_pos + x_mod
168
	y_pos = y_pos + y_mod
169

170
	celestia:print("Press any key to end the script ...", 0.5, -1, -1, 2, 4)
171
	wait (0.01)
172
end
173

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.