B-spline: Difference between revisions
Content added Content deleted
(Added Processing implementation) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 29: | Line 29: | ||
=={{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 # |
||
# mode to hold a B Spline # |
# mode to hold a B Spline # |
||
Line 178: | Line 178: | ||
plot bspline( bs, plot, scale x, scale y ); |
plot bspline( bs, plot, scale x, scale y ); |
||
print plot( plot ) |
print plot( plot ) |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
leading blank lines removed... |
leading blank lines removed... |
||
Line 225: | Line 225: | ||
=={{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 |
||
Point(t::Tuple) = Vec2(Float64(t[1]), Float64(t[2])) |
Point(t::Tuple) = Vec2(Float64(t[1]), Float64(t[2])) |
||
Line 231: | Line 231: | ||
(208, 254), (241, 330), (164,252), (69, 278), (139, 208), (72, 148), (168, 172)]) |
(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)) |
plt = plot(map(a -> a.x, controlpoints), map(a -> a.y, controlpoints)) |
||
savefig(plt, "BSplineplot.png")</ |
savefig(plt, "BSplineplot.png")</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
Line 237: | Line 237: | ||
{{trans|Wren}} |
{{trans|Wren}} |
||
< |
<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 363: | Line 363: | ||
plotBspline(bspline, plot) |
plotBspline(bspline, plot) |
||
printPlot(plot)</ |
printPlot(plot)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 408: | Line 408: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<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, |
||
208}, {72, 148}, {168, 172}}, SplineClosed -> True, |
208}, {72, 148}, {168, 172}}, SplineClosed -> True, |
||
SplineDegree -> 2]]</ |
SplineDegree -> 2]]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Outputs a graphical representation of a B-spline. |
Outputs a graphical representation of a B-spline. |
||
Line 418: | Line 418: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang=perl>use strict; |
||
use warnings; |
use warnings; |
||
use Class::Struct; |
use Class::Struct; |
||
Line 473: | Line 473: | ||
} |
} |
||
$cr->stroke; |
$cr->stroke; |
||
$surf->write_to_png($OUTPUT);</ |
$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) |
||
Line 481: | Line 481: | ||
{{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=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 568: | Line 568: | ||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
< |
<syntaxhighlight lang=java> |
||
//Aamrun, 26th June 2022 |
//Aamrun, 26th June 2022 |
||
Line 598: | Line 598: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{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=perl6># 20211112 Raku programming solution |
||
use Cairo; |
use Cairo; |
||
Line 673: | Line 673: | ||
}; |
}; |
||
.write_png(OUTPUT) and die # C return |
.write_png(OUTPUT) and die # C return |
||
}</ |
}</syntaxhighlight> |
||
Output: [https://drive.google.com/file/d/1dInRJeecA18meybDF2D0usEaWMGFqoBj/view (Offsite image file) ] |
Output: [https://drive.google.com/file/d/1dInRJeecA18meybDF2D0usEaWMGFqoBj/view (Offsite image file) ] |
||
Line 682: | 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. |
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 |
||
import "graphics" for Canvas, Color |
import "graphics" for Canvas, Color |
||
Line 743: | Line 743: | ||
] |
] |
||
var k = 4 // polynomial degree is one less than this i.e. cubic |
var k = 4 // polynomial degree is one less than this i.e. cubic |
||
var Game = BSpline.new(400, 400, cpoints, k)</ |
var Game = BSpline.new(400, 400, cpoints, k)</syntaxhighlight> |