use SDL; use SDLx::App; my $app=SDLx::App->new(w=>400,h=>400,d=>32,t=>"我的第二个程序"); #画大地 $app->draw_rect([0,0,400,400],[0,0,100,255]); #画夜空 my $sky=SDLx::Surface->new(width=>400,height=>200); $sky->draw_rect([0,0,400,200],[0,0,0,255]); #画月亮 $sky->draw_circle_filled([150,50],25,[255,255,0,255]); #画星星 for (my $i = 1; $i < 50; $i++) { my $x=int(rand(400)); my $y=int(rand(200)); if (not ($x>125 and $x<175 and $y >25 and $y<75)) { $sky->draw_circle_filled([$x,$y],2,[0,0,200,255]); } } $sky->blit($app); $app->update(); sleep(5);
use SDL; use SDLx::App; my $app=SDLx::App->new(w=>400,h=>400,d=>32,t=>"我的第二个程序"); #画大地 $app->draw_rect([0,0,400,400],[0,100,0,255]); #随机生成大地的麻点 for (my $i = 1; $i < 500; $i++){ $app->[int(rand(400))][200+int(rand(200))]=[10,10,10,255]; } #画夜空 my $sky=SDLx::Surface->new(width=>400,height=>200); $sky->draw_rect([0,0,400,200],[0,0,0,255]); #画树 my $tree=SDLx::Surface->new(width=>400,height=>150); for (my $i = 1; $i < 30; $i++){ $x=int(20+rand(375)); $y=int(15+rand(100)); $tree->draw_circle_filled([$x,$y],15,[0,150,0,255]); $tree->draw_rect([$x,$y+15,2,15],[0,0,15,255]); } #画月亮 $sky->draw_circle_filled([150,50],25,[255,255,0,255]); #画星星 for (my $i = 1; $i < 50; $i++) { my $x=int(rand(400)); my $y=int(rand(200)); if (not ($x>125 and $x<175 and $y >25 and $y<75)) { $sky->draw_circle_filled([$x,$y],2,[0,0,200,255]); } } $sky->blit($app); $tree->blit($app,[0,0,400,150],[0,200,400,150]); $app->update(); sleep(5);
读取PNG图片
use SDL; use SDLx::App; my $app=SDLx::App->new(w=>400,h=>400,d=>32,t=>"我的第二个程序"); #画大地 $app->draw_rect([0,0,400,400],[10,80,10,255]); #随机生成大地的麻点 for (my $i = 1; $i < 500; $i++){ $app->[int(rand(400))][200+int(rand(200))]=[10,10,10,255]; } #画夜空 my $sky=SDLx::Surface->new(width=>400,height=>200); $sky->draw_rect([0,0,400,200],[0,0,0,255]); #画月亮 $sky->draw_circle_filled([150,50],25,[255,255,0,255]); #画星星 for (my $i = 1; $i < 50; $i++) { my $x=int(rand(400)); my $y=int(rand(200)); if (not ($x>125 and $x<175 and $y >25 and $y<75)) { $sky->draw_circle_filled([$x,$y],2,[0,0,200,255]); } } $sky->blit($app); #画树 for (my $i = 1; $i < 20; $i++){ $x=int(rand(350)); $y=150+int(rand(100)); my $tree=SDL::Image::load('tree.png'); $tree= SDLx::Surface->new(surface =>$tree); $tree->blit($app,[0,0,100,133],[$x,$y,100,133]); } $app->update(); sleep(5);