Data update

This commit is contained in:
Ingy döt Net 2025-06-11 20:16:52 -04:00
parent 72eb4943cb
commit 4d5544505c
2347 changed files with 62432 additions and 16731 deletions

View file

@ -3,25 +3,24 @@ subr home
x = 50
y = 50
down = 0
move x y
.
home
#
proc forward n . .
proc forward n .
px = x
py = y
x += cos deg * n
y += sin deg * n
if down = 1
line x y
else
move x y
gline px py x y
.
sleep 0.1
sleep 0.05
.
proc turn a . .
proc turn a .
deg -= a
.
#
proc house . .
proc house .
turn 180
forward 45
turn 180
@ -43,7 +42,7 @@ proc house . .
.
house
#
proc bar a[] . .
proc bar a[] .
turn 90
forward 30
turn -90

View file

@ -0,0 +1,69 @@
Module TurtleGraphics {
cls 15,0
pen 0
single penangle=pi
boolean pendraw=true
hlen=min.data(scale.x, scale.y)/4
move scale.x/4, scale.y/2
house(hlen)
penup()
forward(hlen)
pendown()
d=(50, 33, 200, 130, 50)
items=len(d)
dspan=d#max()
ratio=scale.y/4/dspan
ditem=each(d)
while ditem
barvalue(scale.x/4, scale.y/3 ,items, ditem^, array(ditem)/dspan)
end while
sub house(n)
for i=1 to 3
right(120)
forward(n)
next
right(90)
bar(n, n)
right(90)
end sub
sub bar(w, h)
local i
for i=1 to 2
right(90)
forward(h)
right(90)
forward(w)
next
end sub
sub barvalue(maxW, maxH, bars, barno, valratio)
local bW=maxW/bars
forward(bw)
bar(bw, -maxH*valratio)
end sub
// Turtle Minimum Pack
// need:
// single penangle=pi
// boolean pendraw=true
//
sub penup()
pendraw=false
end sub
sub pendown()
pendraw=true
end sub
sub forward(distance)
if pendraw then
draw angle penangle, distance
else
step angle penangle, distance
end if
end sub
sub backward(distance)
forward(-distance)
end sub
sub right(angle)
penangle-=angle/180*pi
end sub
}
TurtleGraphics

View file

@ -0,0 +1,54 @@
# 20250303 Raku programming solution
use Cairo;
sub house(Cairo::Context $cr, $x, $y, $size) {
$cr.save;
$cr.rgb(1.0, 1.0, 1.0);
$cr.rectangle($x, $y, $size, $size);
$cr.stroke;
$cr.move_to($x + $size / 2, $y - $size / 2);
$cr.line_to($x, $y);
$cr.line_to($x + $size, $y);
$cr.close_path;
$cr.stroke;
$cr.restore;
}
sub barchart(Cairo::Context $cr, @data, $x is copy, $y, $size) {
$cr.save;
$cr.rgb(1.0, 1.0, 1.0);
my $maxdata = @data.max || 1;
my $bar-width = $size / (@data.elems || 1);
my $bar-spacing = $bar-width * 0.1;
for @data -> $n {
my $bar-height = ($n / $maxdata) * $size;
$cr.rectangle($x, $y - $bar-height, $bar-width - $bar-spacing, $bar-height);
$cr.stroke;
$x += $bar-width;
}
$cr.restore;
}
sub testturtle($width = 400, $height = 600) {
my $image = Cairo::Image.create(Cairo::FORMAT_ARGB32, $width, $height);
my $cr = Cairo::Context.new($image);
$cr.rgb(0.0, 0.0, 0.0);
$cr.paint;
$cr.line_width = 2.0;
barchart($cr, [15, 10, 50, 35, 20], $width * 0.6, $height, $width / 3);
house($cr, $width / 4, $height / 3, $width / 3);
$image.write_png('turtle-raku.png');
}
testturtle();