Bitmap/Bézier curves/Cubic: Difference between revisions
→{{header|Perl 6}}: Updated to show that the end and control points can be in any order
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 805:
}
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 835:
}
method dot (($px, $py), $pix, $radius = 2) {
for $px - $radius .. $px + $radius -> $x {
for $py - $radius .. $py + $radius -> $y {
Line 843:
}
method cubic ( ($x1, $y1), ($x2, $y2), ($x3, $y3), ($x4, $y4), $pix, $segments = 30 ) {
my @line-segments = map -> $t {
my \a = (1-$t)³;
Line 851:
(a*$x1 + b*$x2 + c*$x3 + d*$x4).round(1),(a*$y1 + b*$y2 + c*$y3 + d*$y4).round(1)
}, (0, 1/$segments, 2/$segments ... 1);
for @line-segments.rotor(2=>-1) ->
}
Line 868:
my Bitmap $b = Bitmap.new( width => 600, height => 400) but PPM;
$b.fill( color(
my @points = (
my %seen;
$b.cubic( |@points, color(255,0,255) );▼
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>
|