Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Created March 23, 2021 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gro-Tsen/0ed229246fd5dc87d657b14c0e272dd2 to your computer and use it in GitHub Desktop.
Save Gro-Tsen/0ed229246fd5dc87d657b14c0e272dd2 to your computer and use it in GitHub Desktop.
#! /usr/local/bin/perl -w
use strict;
use warnings;
use Math::Trig ':pi';
use Pango;
use Cairo;
use POSIX;
my $size = 720;
my $height = 1;
my $width = 1.9;
my $hoist = 7/13;
my $fly = 0.76;
my $stripe = 1/13;
my $stardiam = 0.0616;
my $surface = Cairo::ImageSurface->create ('rgb24', $width*$size, $height*$size);
my $cr = Cairo::Context->create ($surface);
$cr->set_source_rgb (1., 1., 1.);
$cr->rectangle(0,0,$width*$size,$height*$size);
$cr->fill;
$cr->set_source_rgb (0.698, 0.132, 0.203);
for ( my $i=0 ; $i<13 ; $i+=2 ) {
$cr->rectangle(0,$i*$stripe*$size,$width*$size,$stripe*$size);
$cr->fill;
}
$cr->set_source_rgb (0.234, 0.233, 0.430);
$cr->rectangle(0,0,$fly*$size,$hoist*$size);
$cr->fill;
sub draw_star {
my $x = shift;
my $y = shift;
$cr->set_source_rgb (1., 1., 1.);
$cr->new_path;
for ( my $k=0 ; $k<5 ; $k++ ) {
$cr->line_to ($x - ($stardiam/2)*$size*sin(pi2*2*$k/5),
$y - ($stardiam/2)*$size*cos(pi2*2*$k/5));
}
$cr->close_path;
$cr->fill;
}
if ( 1 ) {
## 50 stars
for ( my $i=0 ; $i<9 ; $i++ ) {
for ( my $j=0 ; $j<11 ; $j++ ) {
draw_star(($j+1)/12*$fly*$size, ($i+1)/10*$hoist*$size) if ($i+$j)%2 == 0;
}
}
} elsif ( 0 ) {
## 51 stars
for ( my $i=0 ; $i<6 ; $i++ ) {
for ( my $j=0 ; $j<17 ; $j++ ) {
draw_star(($j+1)/18*$fly*$size, ($i+1)/7*$hoist*$size) if ($i+$j)%2 == 0;
}
}
} elsif ( 0 ) {
## 52 stars
for ( my $i=0 ; $i<8 ; $i++ ) {
for ( my $j=0 ; $j<13 ; $j++ ) {
draw_star(($j+1)/14*$fly*$size, ($i+1)/9*$hoist*$size) if ($i+$j)%2 == 0;
}
}
}
$cr->show_page;
$surface->write_to_png("flag.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment