Fix a small bug: Test this lin x=(1,2,3,4,5) : Print x#max()-x#min()
A nice task from rosettacode.org
Module Pairs {
\\ written in version 9.5 rev. 13
\\ use Gdi+ antialiasing (not work with Wine in Linux, but we get no error)
smooth on
Const center=2, right=3, left=1, blue=1, angle=0, dotline=3
Const size9pt=9, size11pt=11
Cls ,0 ' use current background color, set split screen from line 0
Cursor 0,3
Report center, "Coordinate pairs"
x = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
y = (2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0)
dx=scale.x/2/len(x)
dy=dx 'ratio 1:1
graH=dy*len(x)
Basex=scale.x/4
Basey=(scale.y+graH)/2
Move Basex, Basey
\\ draw use relative coordinates
Draw 0,-graH
\\ Step just move graphic cursor
Step 0, graH
Draw scale.x/2
Step -scale.x/2
\\ scX is 1, not used
max=Y#max()
\\ Auto scale for Y, using 0 for start of axis Y
scY=-graH/((max+5^log(max) ) div 100)/100
\\ make vertical axis using dots with numbers center per dx
j=1
For i=basex+dx to basex+dx*x#max() Step dx
Move i, basey
Step 0, twipsy*10
Legend format$("{0}",array(x,j)), "courier", size9pt, angle, center
Width 1, dotline { draw 0, -graH-twipsy*10,7}
j++
Next i
\\ the same for horizontal axis
HalfTextHeight=Size.y("1","courier", size9pt)/2
For i=basey-dy to basey-dy*x#max() Step dy
Move basex, i
Step -twipsx*10
Width 1, dotline { draw scale.x/2+twipsx*10,,7}
Move basex-100, i+HalfTextHeight
Legend format$("{0}",(i-basey)/scY), "courier", size9pt, angle, left
Next i
ex=each(x) : ey=each(y)
\\ start from first point. We use Draw to for absolute coordinates
Move array(x,0)*dx+Basex, array(y,0)*scy+Basey
While ex, ey {
Width 2 {
Draw to array(ex)*dx+Basex, array(ey)*scy+Basey, blue
}
}
\\ second pass for marks and labels
ex=each(x) : ey=each(y)
While ex, ey {
Move array(ex)*dx+Basex, array(ey)*scy+Basey
Step -75, -75
Pen 12 {draw 150: draw 0,150 : draw -150 : draw 0,-150}
Pen 13 {
Step 200, -200
Legend format$("({0}-{1})",array(ex),array(ey) ), "courier bold", size11pt, angle, right
}
}
\\ screenshot to clipboard
Screenshot$=""
Move 0,0
Copy scale.x, scale.y to Screenshot$
Clipboard Screenshot$
a$=key$
}
Pairs
A nice task from rosettacode.org
Module Pairs {
\\ written in version 9.5 rev. 13
\\ use Gdi+ antialiasing (not work with Wine in Linux, but we get no error)
smooth on
Const center=2, right=3, left=1, blue=1, angle=0, dotline=3
Const size9pt=9, size11pt=11
Cls ,0 ' use current background color, set split screen from line 0
Cursor 0,3
Report center, "Coordinate pairs"
x = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
y = (2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0)
dx=scale.x/2/len(x)
dy=dx 'ratio 1:1
graH=dy*len(x)
Basex=scale.x/4
Basey=(scale.y+graH)/2
Move Basex, Basey
\\ draw use relative coordinates
Draw 0,-graH
\\ Step just move graphic cursor
Step 0, graH
Draw scale.x/2
Step -scale.x/2
\\ scX is 1, not used
max=Y#max()
\\ Auto scale for Y, using 0 for start of axis Y
scY=-graH/((max+5^log(max) ) div 100)/100
\\ make vertical axis using dots with numbers center per dx
j=1
For i=basex+dx to basex+dx*x#max() Step dx
Move i, basey
Step 0, twipsy*10
Legend format$("{0}",array(x,j)), "courier", size9pt, angle, center
Width 1, dotline { draw 0, -graH-twipsy*10,7}
j++
Next i
\\ the same for horizontal axis
HalfTextHeight=Size.y("1","courier", size9pt)/2
For i=basey-dy to basey-dy*x#max() Step dy
Move basex, i
Step -twipsx*10
Width 1, dotline { draw scale.x/2+twipsx*10,,7}
Move basex-100, i+HalfTextHeight
Legend format$("{0}",(i-basey)/scY), "courier", size9pt, angle, left
Next i
ex=each(x) : ey=each(y)
\\ start from first point. We use Draw to for absolute coordinates
Move array(x,0)*dx+Basex, array(y,0)*scy+Basey
While ex, ey {
Width 2 {
Draw to array(ex)*dx+Basex, array(ey)*scy+Basey, blue
}
}
\\ second pass for marks and labels
ex=each(x) : ey=each(y)
While ex, ey {
Move array(ex)*dx+Basex, array(ey)*scy+Basey
Step -75, -75
Pen 12 {draw 150: draw 0,150 : draw -150 : draw 0,-150}
Pen 13 {
Step 200, -200
Legend format$("({0}-{1})",array(ex),array(ey) ), "courier bold", size11pt, angle, right
}
}
\\ screenshot to clipboard
Screenshot$=""
Move 0,0
Copy scale.x, scale.y to Screenshot$
Clipboard Screenshot$
a$=key$
}
Pairs
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.