如何将一个对象叠加在另一个对象上

huangapple go评论55阅读模式
英文:

how to superimpose one object on another

问题

为了确保你的代码不被翻译,我只会提供代码注释的翻译。以下是代码注释的翻译:

#!/usr/bin/perl

use strict;
use warnings;
use Curses;

use Term::Animation 2.0;
my $s = Term::Animation->new();
$s->color(1);

my $phrase = "Press q to exit";

my @rocket = (
q{
        ^
      /   \
     |     |
    " |     | "
   | ||     || |
   | || ,^. || |
   |||| | | ||||
   | ||,|_|.|| |
   |||/ |_| \|/|||
   | /  |_|  \ |
   |(___|||___)|
   /_\??^^^??/_\
},
q{
        ^
      /   \
     |     |
    " |     | "
   | ||     || |
   | || ,^. || |
   |||| | | ||||
   | ||,|_|.|| |
   |||/ |_| \|/|||
   | /  |_|  \ |
   |(___|||___)|
   /_\??^^^??/_\
   /|\???????/|\
 /|||\?????/|||\
},
q{
        ^
      /   \
     |     |
    " |     | "
   | ||     || |
   | || ,^. || |
   |||| | | ||||
   | ||,|_|.|| |
   |||/ |_| \|/|||
   | /  |_|  \ |
   |(___|||___)|
   /_\??^^^??/_\
 /|||\?????/|||\
/|||||\???/|||||\
}
);

my @mask = (
q{
        y
      y   y
     y     y
   w y     y w
  w wy     yw w
  w wy KKK yw w
  wwwy W W ywww
  w wyWWWWWyw w
  wwwW WWW Wwww
  w W  WWW  W w
  wWWWWWWWWWWWw
  www  KKK  www
},
q{
        y
      y   y
     y     y
   w y     y w
  w wy     yw w
  w wy KKK yw w
  wwwy W W ywww
  w wyWWWWWyw w
  wwwW WWW Wwww
  w W  WWW  W w
  wWWWWWWWWWWWw
  www  KKK  www
  RYR       RYR 
 RRRRR     RRRRR
},
q{
        y
      y   y
     y     y
   w y     y w
  w wy     yw w
  w wy KKK yw w
  wwwy W W ywww
  w wyWWWWWyw w
  wwwW WWW Wwww
  w W  WWW  W w
  wWWWWWWWWWWWw
  www  KKK  www
 RYYYR     RYYYR
RRRYRRR   RRRYRRR
}
);

my $cloud1 = q#
   .--.
 .(    )
(_   )__)
  '-'
#;

my $cloud2 = q#
   .-.
 .(  _).
(_. (___)
#;

my $cloud3 = q#
    .-.
 .-(   ).
(        )
 (_(__.___)
#;

my @sun = (q{
  \  |  /
   .---.
- |     | -
   '---'
  /  |  \
},
q{
   .---.
  |     |
   '---'
});

my $tree = q#
     ,-
    (  }
  ,^    '),
 (         )
{           )
 '-.       /,
  {         }
   -.    ,-';
     |  }
     | |
     | |
  .-'   '-.
#;

my $tree_fg_mask = q#
     GG
    G  G
  GG    GGG
 G         G
G           G
 GGG       GG
  G         G
   GG    GGG
     K  G
     K K
     K K
  KKK   KKK
#;
$s->new_entity(
    shape           => $cloud1,
    position        => [ 2, 1, 10],
    callback_args   => [1,0,0,0],
    wrap            => 1,
    default_color   => 'WHITE',
    auto_trans      => 1,
);
$s->new_entity(
        shape           => $cloud2,
        position        => [ 10, 5, 10],
        callback_args   => [1,0,0,0],
        wrap            => 1,
        default_color   => 'WHITE',
        auto_trans      => 1,
);

$s->new_entity(
        shape           => $cloud3,
        position        => [ 15, 1, 10],
        callback_args   => [1,0,0,0],
        wrap            => 1,
        default_color   => 'WHITE',
        auto_trans      => 1,
);

$s->new_entity(
        shape           => \@sun,
        position        => [ 60, 2, 20],
        callback_args   => [-1,0,0,1],
        wrap            => 1,
        default_color   => 'YELLOW',
);
my @launch;
        push(@launch, [0,0,0,0]) for(1..10);
        push(@launch, [0,0,0,1]) for(1..3);
        push(@launch, [0,-.25,0,1]) for(1..10);
        push(@launch, [0,-.5,0,2]) for(1..10);
        push(@launch, [0,-1,0,2]) for(1..30);
$s->new_entity(
                shape           => \@rocket,
                position        => [50, 12, 15],
                callback_args   => [0, [@launch]],
                wrap            => 1,
                color           => \@mask,
                auto_trans      => 1,
        );
$s->new_entity(
        shape           => $tree,
        position        => [ 35, 5, 5],
        color           => $tree_fg_mask,
        auto_trans      => 1,
);
halfdelay( 2 );

for(1..500) {
  $s->animate();
  my $in = lc( getch() );
  if($in eq 'q') { last; }
}

请注意,以上只提供了代码注释的翻译,不包括实际代码部分。如果需要代码的翻译,请提供具体的代码部分。

英文:

Why do clouds pass in front of the sun but not behind the rocket?
The reason I believe this is that the sun and the rocket is defined as @rocket and @Sun; already clouds defined only with the dollar sign $nuvem.
Which doesn't make much sense, since the tree entity is called by $ and even then the clouds pass behind it.

#!/usr/bin/perl
use strict;
use warnings;
use Curses;
use Term::Animation 2.0;
my $s = Term::Animation->new();
$s->color(1);
my $phrase = "Press q to exit";
my @rocket = (
q{
^
/   \
|     |
" |     | "
| ||     || |
| || ,^. || |
|_|| | | ||_|
| ||,|_|.|| |
|_|/ |_| \|_|
| /  |_|  \ |
|(___|||___)|
/_\??^^^??/_\
},
q{
^
/   \
|     |
" |     | "
| ||     || |
| || ,^. || |
|_|| | | ||_|
| ||,|_|.|| |
|_|/ |_| \|_|
| /  |_|  \ |
|(___|||___)|
/_\??^^^??/_\
/|\???????/|\
/|||\?????/|||\
},
q{
^
/   \
|     |
" |     | "
| ||     || |
| || ,^. || |
|_|| | | ||_|
| ||,|_|.|| |
|_|/ |_| \|_|
| /  |_|  \ |
|(___|||___)|
/_\??^^^??/_\
/|||\?????/|||\
/|||||\???/|||||\
}
);
my @mask = (
q{
y
y   y
y     y
w y     y w
w wy     yw w
w wy KKK yw w
wwwy W W ywww
w wyWWWWWyw w
wwwW WWW Wwww
w W  WWW  W w
wWWWWWWWWWWWw
www  KKK  www
},
q{
y
y   y
y     y
w y     y w
w wy     yw w
w wy KKK yw w
wwwy W W ywww
w wyWWWWWyw w
wwwW WWW Wwww
w W  WWW  W w
wWWWWWWWWWWWw
www  KKK  www
RYR       RYR 
RRRRR     RRRRR
},
q{
y
y   y
y     y
w y     y w
w wy     yw w
w wy KKK yw w
wwwy W W ywww
w wyWWWWWyw w
wwwW WWW Wwww
w W  WWW  W w
wWWWWWWWWWWWw
www  KKK  www
RYYYR     RYYYR
RRRYRRR   RRRYRRR
}
);
my $cloud1 = q#
.--.
.(    )
(_   )__)
'-'
#;
my $cloud2 = q#
.-.
.(  _).
(_. (___)
#;
my $cloud3 = q#
.-.
.-(   ).
(        )
(_(__.___)
#;
my @sun = (q{
\  |  /
.---.
- |     | -
'---'
/  |  \
},
q{
.---.
|     |
'---'
});
my $tree = q#
,-
(  }
,^    '),
(         }
{           )
'-.       /,
{         }
-.    ,-'
|  }
| |
| |
.-'   '-.
#;
my $tree_fg_mask = q#
GG
G  G
GG    GGG
G         G
G           G
GGG       GG
G         G
GG    GGG
K  G
K K
K K
KKK   KKK
#;
$s->new_entity(
shape           => $cloud1,
position        => [ 2, 1, 10],
callback_args   => [1,0,0,0],
wrap            => 1,
default_color   => 'WHITE',
auto_trans      => 1,
);
$s->new_entity(
shape           => $cloud2,
position        => [ 10, 5, 10],
callback_args   => [1,0,0,0],
wrap            => 1,
default_color   => 'WHITE',
auto_trans      => 1,
);
$s->new_entity(
shape           => $cloud3,
position        => [ 15, 1, 10],
callback_args   => [1,0,0,0],
wrap            => 1,
default_color   => 'WHITE',
auto_trans      => 1,
);
$s->new_entity(
shape           => \@sun,
position        => [ 60, 2, 20],
callback_args   => [-1,0,0,1],
wrap            => 1,
default_color   => 'YELLOW',
);
my @launch;
push(@launch, [0,0,0,0]) for(1..10);
push(@launch, [0,0,0,1]) for(1..3);
push(@launch, [0,-.25,0,1]) for(1..10);
push(@launch, [0,-.5,0,2]) for(1..10);
push(@launch, [0,-1,0,2]) for(1..30);
$s->new_entity(
shape           => \@rocket,
position        => [50, 12, 15],
callback_args   => [0, [@launch]],
wrap            => 1,
color           => \@mask,
auto_trans      => 1,
);
$s->new_entity(
shape           => $tree,
position        => [ 35, 5, 5],
color           => $tree_fg_mask,
auto_trans      => 1,
);
halfdelay( 2 );
for(1..500) {
$s->animate();
my $in = lc( getch() );
if($in eq 'q') { last; }
}

答案1

得分: 3

位置有三个坐标,其中第三个是z坐标。

如果你希望火箭在云的前面,可以改变它们的相对z坐标。例如,你可以将火箭的z坐标改为8。

英文:

The positions have three coordinates, the third of which is the z coordinate.

        z
--
tree    5   Front
cloud1 10
cloud2 10
cloud3 10
rocket 15
sun    20   Back

If you want the rocket to be front of the clouds, change their relative z coordinates. For example, you could change the rocket's z to be 8.

huangapple
  • 本文由 发表于 2023年2月24日 04:23:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75549960.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定