B-spline: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
||
Line 25: | Line 25: | ||
* [https://www.cl.cam.ac.uk/teaching/2000/AGraphHCI/SMEG/node4.html B-splines] |
* [https://www.cl.cam.ac.uk/teaching/2000/AGraphHCI/SMEG/node4.html B-splines] |
||
<br><br> |
<br><br> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{Trans|Lua}}Which is {{Trans|Wren}}Suppresses unused parts of the plot. |
{{Trans|Lua}}Which is {{Trans|Wren}}Suppresses unused parts of the plot. |
||
<syntaxhighlight lang=algol68>BEGIN # construct a B-Spline # |
<syntaxhighlight lang="algol68">BEGIN # construct a B-Spline # |
||
# mode to hold a B Spline # |
# mode to hold a B Spline # |
||
Line 222: | Line 220: | ||
</pre> |
</pre> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Choose BSpline D of 2, ie degree 1. |
Choose BSpline D of 2, ie degree 1. |
||
<syntaxhighlight lang=julia>using Graphics, Plots |
<syntaxhighlight lang="julia">using Graphics, Plots |
||
Point(t::Tuple) = Vec2(Float64(t[1]), Float64(t[2])) |
Point(t::Tuple) = Vec2(Float64(t[1]), Float64(t[2])) |
||
Line 232: | Line 229: | ||
plt = plot(map(a -> a.x, controlpoints), map(a -> a.y, controlpoints)) |
plt = plot(map(a -> a.x, controlpoints), map(a -> a.y, controlpoints)) |
||
savefig(plt, "BSplineplot.png")</syntaxhighlight> |
savefig(plt, "BSplineplot.png")</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="lua">local function Range(from, to) |
||
local range = {} |
local range = {} |
||
for n = from, to do table.insert(range, n) end |
for n = from, to do table.insert(range, n) end |
||
Line 406: | Line 402: | ||
@@@ |
@@@ |
||
</pre> |
</pre> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="mathematica">Graphics[ |
||
BSplineCurve[{{171, 171}, {185, 111}, {202, 109}, {202, 189}, {328, |
BSplineCurve[{{171, 171}, {185, 111}, {202, 109}, {202, 189}, {328, |
||
160}, {208, 254}, {241, 330}, {164, 252}, {69, 278}, {139, |
160}, {208, 254}, {241, 330}, {164, 252}, {69, 278}, {139, |
||
Line 415: | Line 410: | ||
{{out}} |
{{out}} |
||
Outputs a graphical representation of a B-spline. |
Outputs a graphical representation of a B-spline. |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
<syntaxhighlight lang=perl>use strict; |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use Class::Struct; |
use Class::Struct; |
||
Line 475: | Line 469: | ||
$surf->write_to_png($OUTPUT);</syntaxhighlight> |
$surf->write_to_png($OUTPUT);</syntaxhighlight> |
||
Output: [https://raw.githubusercontent.com/SqrtNegInf/Rosettacode-Perl-Smoke/master/ref/b-spline.png b-spline.png] (offsite image) |
Output: [https://raw.githubusercontent.com/SqrtNegInf/Rosettacode-Perl-Smoke/master/ref/b-spline.png b-spline.png] (offsite image) |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
Line 481: | Line 474: | ||
{{libheader|Phix/online}} |
{{libheader|Phix/online}} |
||
You can run this online [http://phix.x10.mx/p2js/bspline.htm here]. |
You can run this online [http://phix.x10.mx/p2js/bspline.htm here]. |
||
<!--<syntaxhighlight lang= |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #000080;font-style:italic;">-- |
<span style="color: #000080;font-style:italic;">-- |
||
-- demo\rosetta\B-spline.exw |
-- demo\rosetta\B-spline.exw |
||
Line 569: | Line 562: | ||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</syntaxhighlight>--> |
<!--</syntaxhighlight>--> |
||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
<syntaxhighlight lang=java> |
<syntaxhighlight lang="java"> |
||
//Aamrun, 26th June 2022 |
//Aamrun, 26th June 2022 |
||
Line 599: | Line 591: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Raku}}== |
=={{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]. |
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]. |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="raku" line># 20211112 Raku programming solution |
||
use Cairo; |
use Cairo; |
||
Line 676: | Line 667: | ||
Output: [https://drive.google.com/file/d/1dInRJeecA18meybDF2D0usEaWMGFqoBj/view (Offsite image file) ] |
Output: [https://drive.google.com/file/d/1dInRJeecA18meybDF2D0usEaWMGFqoBj/view (Offsite image file) ] |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|DOME}} |
{{libheader|DOME}} |
||
Line 682: | Line 672: | ||
If one uses a value for k of 1, then the script will simply plot the control points as in the Julia example. |
If one uses a value for k of 1, then the script will simply plot the control points as in the Julia example. |
||
<syntaxhighlight lang=ecmascript>import "dome" for Window, Process |
<syntaxhighlight lang="ecmascript">import "dome" for Window, Process |
||
import "graphics" for Canvas, Color |
import "graphics" for Canvas, Color |
||