B-spline: Difference between revisions

m
syntax highlighting fixup automation
(Added Processing implementation)
m (syntax highlighting fixup automation)
Line 29:
=={{header|ALGOL 68}}==
{{Trans|Lua}}Which is {{Trans|Wren}}Suppresses unused parts of the plot.
<langsyntaxhighlight lang=algol68>BEGIN # construct a B-Spline #
 
# mode to hold a B Spline #
Line 178:
plot bspline( bs, plot, scale x, scale y );
print plot( plot )
END</langsyntaxhighlight>
{{out}}
leading blank lines removed...
Line 225:
=={{header|Julia}}==
Choose BSpline D of 2, ie degree 1.
<langsyntaxhighlight lang=julia>using Graphics, Plots
 
Point(t::Tuple) = Vec2(Float64(t[1]), Float64(t[2]))
Line 231:
(208, 254), (241, 330), (164,252), (69, 278), (139, 208), (72, 148), (168, 172)])
plt = plot(map(a -> a.x, controlpoints), map(a -> a.y, controlpoints))
savefig(plt, "BSplineplot.png")</langsyntaxhighlight>
 
=={{header|Lua}}==
Line 237:
{{trans|Wren}}
 
<langsyntaxhighlight lang=Lua>local function Range(from, to)
local range = {}
for n = from, to do table.insert(range, n) end
Line 363:
plotBspline(bspline, plot)
 
printPlot(plot)</langsyntaxhighlight>
 
{{out}}
Line 408:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight lang=Mathematica>Graphics[
BSplineCurve[{{171, 171}, {185, 111}, {202, 109}, {202, 189}, {328,
160}, {208, 254}, {241, 330}, {164, 252}, {69, 278}, {139,
208}, {72, 148}, {168, 172}}, SplineClosed -> True,
SplineDegree -> 2]]</langsyntaxhighlight>
{{out}}
Outputs a graphical representation of a B-spline.
Line 418:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang=perl>use strict;
use warnings;
use Class::Struct;
Line 473:
}
$cr->stroke;
$surf->write_to_png($OUTPUT);</langsyntaxhighlight>
Output: [https://raw.githubusercontent.com/SqrtNegInf/Rosettacode-Perl-Smoke/master/ref/b-spline.png b-spline.png] (offsite image)
 
Line 481:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/bspline.htm here].
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\B-spline.exw
Line 568:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Processing}}==
<langsyntaxhighlight lang=java>
//Aamrun, 26th June 2022
 
Line 598:
}
 
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
A minimal translation of [https://www.cypherpunk.at/download/bspline/bspline_1.1.tbz2 this C program], by [https://github.com/rahra Bernhard R. Fischer].
<langsyntaxhighlight lang=perl6># 20211112 Raku programming solution
 
use Cairo;
Line 673:
};
.write_png(OUTPUT) and die # C return
}</langsyntaxhighlight>
 
Output: [https://drive.google.com/file/d/1dInRJeecA18meybDF2D0usEaWMGFqoBj/view (Offsite image file) ]
Line 682:
 
If one uses a value for k of 1, then the script will simply plot the control points as in the Julia example.
<langsyntaxhighlight lang=ecmascript>import "dome" for Window, Process
import "graphics" for Canvas, Color
 
Line 743:
]
var k = 4 // polynomial degree is one less than this i.e. cubic
var Game = BSpline.new(400, 400, cpoints, k)</langsyntaxhighlight>
10,327

edits