Bitmap/Bézier curves/Quadratic: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) m →{{header|Perl 6}}: remove some debug code |
Thundergnat (talk | contribs) →{{header|Perl 6}}: Updated to show that the end and control points can be in any order |
||
Line 627:
method set-pixel ($i, $j, Pixel $p) {
return if $j >= $!height;
self.pixel($i, $j) = $p.clone;
}
Line 633 ⟶ 634:
}
method line(($x0 is copy, $y0 is copy), ($x1 is copy, $y1 is copy), $pix) {
my $steep = abs($y1 - $y0) > abs($x1 - $x0);
if $steep {
Line 663 ⟶ 664:
}
method dot (($px, $py), $pix, $radius = 2) {
for $px - $radius .. $px + $radius -> $x {
for $py - $radius .. $py + $radius -> $y {
Line 671 ⟶ 672:
}
method quadratic ( ($x1, $y1), ($x2, $y2), ($x3, $y3), $pix, $segments = 30 ) {
my @line-segments = map -> $t {
my \a = (1-$t)²;
Line 678 ⟶ 679:
(a*$x1 + b*$x2 + c*$x3).round(1),(a*$y1 + b*$y2 + c*$y3).round(1)
}, (0, 1/$segments, 2/$segments ... 1);
for @line-segments.rotor(2=>-1) ->
}
Line 695 ⟶ 696:
my Bitmap $b = Bitmap.new( width => 600, height => 400) but PPM;
$b.fill( color(
my @points = (65,25), (85,380), (570,15);
my %seen;
$b.quadratic( |@points, color(0,255,0) );▼
my $c = 0;
for @points.permutations -> @this {
%seen{@this.reverse.join.Str}++;
next if %seen{@this.join.Str};
}
@points.map: { $b.dot( $
$*OUT.write: $b.P6;</lang>
|