[英]Replace characters in a table - ADA
I created a table ( 62 x 35 ) with characters in the table. 我用表中的字符创建了一个表(62 x 35)。 I'm trying to replace the characters in a 10 x 10 table from the middle by others.
我正在尝试从中间替换10 x 10表格中的字符。
For example, if I have a table that looks like that: (62 x 35) 例如,如果我有一个看起来像这样的表:(62 x 35)
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
I want to be able to load a file containing (10x10): 我希望能够加载包含(10x10)的文件:
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
so that the characters in this file replace the characters in the table created previously 以便此文件中的字符替换先前创建的表中的字符
ie have a table that looks like 即有一张看起来像的桌子
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##########################//////////##########################
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
I don't think what I'm trying to do is very clear, so if you want more details please ask. 我认为我要做的事情不是很清楚,所以如果您想了解更多细节,请询问。
procedure Grid_Pilliers(A: out Grid) is -- creates grid with pilliers --
begin
for I in 0..31 loop
for J in 0..75 loop
if (I mod 4 = 1 or I mod 4 = 0) and (J mod 4 = 1 or J mod 4 = 0) then
A(I,J) := true ;
else
A(I,J) := false ;
end if ;
end loop ;
end loop ;
end Grid_Pilliers ;
procedure New_Grid_Random_Fill(A : in out New_Grid) is
type Numero is range 0 .. 1;
package Grid_Random is new Ada.Numerics.Discrete_Random (Numero);
use Grid_Random;
Random_Number : Numero;
G : Generator;
begin
Reset (G);
for I in A'Range(1) loop
for J in A'Range(2) loop
Random_Number := Random (G);
A(I,J) := (Random_Number = 1);
end loop;
end loop;
end New_Grid_Random_Fill;
You should probably use slicing... but for this example I'll use a pair of for-loops. 您可能应该使用切片...但是在此示例中,我将使用一对for循环。 Assuming you have the table-type (
Grid
) defined as Array (Positive Range <>, Positive Range <>) of Character
... 假设您已将表类型(
Grid
)定义为Array (Positive Range <>, Positive Range <>) of Character
...
procedure copy_into( Working : in out Grid; subimage : in Grid;
Offset_X, Offset_Y : Natural ) is
begin
-- insert checks for subimage lengths [plus offsets]
-- to be less than Working's lengths.
for index_x in subimage'Range(1) loop
for index_y in subimage'Range(2) loop
Working(index_x+offset_x, index_y+offset_y):= subimage(index_x, index_y);
end loop;
end loop;
end copy_into;
To get the offsets is simple: 获取偏移量很简单:
offset_x = big_grid_width + small_grid_width / 2. offset_x = big_grid_width + small_grid_width / 2。
offset_y = the above, but using height. offset_y =以上,但使用高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.