Babylonian spiral: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Raku}}: Reduce unnecessary calculations, use more efficient abstractions, reduce execution time about another 50%, other minor style twiddles) |
(→{{header|Wren}}: Converted to a DOME script so we can use Wren-plot to plot the points.) |
||
Line 538: | Line 538: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
{{libheader|DOME}} |
|||
{{libheader|Wren-trait}} |
{{libheader|Wren-trait}} |
||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
{{libheader|Wren-plot}} |
|||
⚫ | |||
Generates an image similar to the OEIS one. |
|||
⚫ | |||
import "graphics" for Canvas, Color |
|||
import "./trait" for Indexed, Stepped |
|||
import "./seq" for Lst |
import "./seq" for Lst |
||
import "./fmt" for Fmt |
import "./fmt" for Fmt |
||
import " |
import "./plot" for Axes |
||
// Python modulo operator (not same as Wren's) |
// Python modulo operator (not same as Wren's) |
||
Line 604: | Line 609: | ||
// find first 10,000 points |
// find first 10,000 points |
||
var |
var Points10000 = babylonianSpiral.call(9998) // first two added automatically |
||
// print first 40 to terminal |
// print first 40 to terminal |
||
System.print("The first 40 Babylonian spiral points are:") |
System.print("The first 40 Babylonian spiral points are:") |
||
for (chunk in Lst.chunks( |
for (chunk in Lst.chunks(Points10000[0..39], 10)) Fmt.print("$-9s", chunk) |
||
class Main { |
|||
// create .csv file for all 10,000 points for display by an external plotter |
|||
construct new() { |
|||
File.create("babylonian_spiral.csv") { |file| |
|||
Window.title = "Babylonian spiral" |
|||
for (p in points10000) { |
|||
Canvas.resize(1000, 1000) |
|||
Window.resize(1000, 1000) |
|||
Canvas.cls(Color.white) |
|||
var axes = Axes.new(100, 900, 800, 800, -1000..11000, -5000..10000) |
|||
axes.draw(Color.black, 2) |
|||
var xMarks = Stepped.new(0..10000, 2000) |
|||
var yMarks = Stepped.new(-5000..10000, 5000) |
|||
axes.label(xMarks, yMarks, Color.black, 2, Color.black) |
|||
axes.line(-1000, 10000, 11000, 10000, Color.black, 2) |
|||
axes.line(11000, -5000, 11000, 10000, Color.black, 2) |
|||
axes.lineGraph(Points10000, Color.black, 2) |
|||
} |
} |
||
}</lang> |
|||
init() {} |
|||
update() {} |
|||
draw(alpha) {} |
|||
} |
|||
var Game = Main.new()</lang> |
|||
{{out}} |
{{out}} |