|
Post by tenochtitlanuk on Nov 9, 2021 9:39:44 GMT -5
Anyone looking for a bit of coding fun might like to try Harmonic Series on Rosetta Code. Calculate the sum of the reciprocals of the first n natural numbers Hn = 1 + 1/2 + 1/3 + ... + 1/nEasy with LB. Try it and then take advantage of LB's number ( or string) handling qualities to display more precision. Don't look at Diga Me until you've tried it!
|
|
|
Post by tenochtitlanuk on Nov 5, 2021 16:23:03 GMT -5
Another example showing colour fill cycling through the whole range of hues, up and down.
|
|
|
Post by tenochtitlanuk on Nov 3, 2021 10:18:37 GMT -5
Just adding to Rod's post. Try the code below on your machine. Results will vary with your processor and clock speed. I graph machine processor usage in Linux System Monitor. I gave each 'notice' 5 seconds before responding. to separate the times. print "Starting a long empty loop" for i =1 to 1000000 ' next i notice "OK"
print "Pausing 5 seconds" call pause 5000
print "Sleeping 5 seconds" call sleep 5000 notice "OK"
print "Starting 5 sec timer" timer 5000, [on] wait [on] timer 0 notice "OK"
print "Starting a long empty loop" for i =1 to 1000000 ' next i notice "OK"
print "Done"
end
sub pause mil t =time$( "ms") +mil while time$( "ms") <t scan wend end sub
sub sleep ms calldll #kernel32, "Sleep",_ ms as ulong,_ ret as void end sub
|
|
|
Post by tenochtitlanuk on Nov 2, 2021 17:51:00 GMT -5
Very computer-busy ways to implement a delay. Better is probably
call Sleep 1000 'Sleep for 1000 milliseconds
Sub Sleep ms CallDLL #kernel32, "Sleep",_ ms as long,_ ret as void End Sub
|
|
|
Post by tenochtitlanuk on Nov 2, 2021 11:59:35 GMT -5
I'd encourage you to play with this example... you can easily modify horizontal and vertical scale and offset and colours.
nomainwin
WindowWidth =1000 WindowHeight = 650
open "Three sin waves" for graphics_nsb as #wg
#wg "trapclose quit"
' trig functions in LB expect radians not degrees ' convert by multiplying by pi/180 P =3.14159265 /180
' sine lies between +/-1. Scale this to +/-80 and offset vertically for each curve.
#wg "fill lightgray ; down"
call grid
for theta =0 to 4 *360 step 0.5 xS =int( 20 +theta /4 /360 *1000) ' xScreen scaled to fit window
amplitude1 =sin( theta *P) #wg "color red ; set "; xS; " 100 ; set "; xS; " "; 100 +80 *amplitude1
amplitude2 =sin( theta *P +60 *P) #wg "color green ; set "; xS; " 300 ; set "; xS; " "; 300 +80 *amplitude2
amplitude3 =sin( theta *3 *P) #wg "color blue ; set "; xS; " 500 ; set "; xS; " "; 500 +80 *amplitude3 next theta
wait end
sub grid for theta =0 to 4 *360 step 90 ' draw vertical gridline every 90 degrees. #wg "line "; int( 20 +theta /4 /360 *1000); " 0 "; int( 20 +theta /4 /360 *1000); " 600" next theta end sub
sub quit h$ close #wg end sub
|
|
|
Post by tenochtitlanuk on Nov 2, 2021 8:03:27 GMT -5
Just catching up with this- a fun project.
Caution to others- you'll need to delete the preamble lines at the start of the downloaded dictionaries, and there is an errant 'paths$' that should be 'path$'. And ld should really be set to 0 at the start? As a user of LB under Wine/Linux I always make sure datafiles use CRLF separators...
dkl... just because you don't get much reaction doesn't mean your code and messages are not appreciated! I happen to have other things on the go at the moment but it was well worth my time having a look at this. Keep posting!
|
|
|
Post by tenochtitlanuk on Nov 1, 2021 17:11:08 GMT -5
Does this do what you want? I saved your data as 'original.fil' and 'control.fil', and it wrote 'newFile.txt'.
' Read the file. If 'VN990004' present in a line, skip- otherwise write to file count =0
CR$ =chr$( 13) +chr$( 10)
open "newFile.txt" for output as #fOut2 open "original.fil" for input as #fIn do line input #fIn, row$
I =instr( row$, "VN990004") if I <>0 then cowNumber =val( mid$( row$, I +9, 6))
if found( cowNumber) then #fOut2 row$; CR$; print "."; ' showing progress.. else count =count +1 print "!"; end if
end if
loop until row$ ="" or eof( #fIn) <0 close #fIn close #fOut2
print "" print " I removed "; count; " rows of data referring to 'VN990004' but cow's number was not in 'control.fil'."
end ' _________________________________________________
function found( cN) open "control.fil" for input as #fIn2 cN$ =input$( #fIn2, lof( #fIn2)) close #fIn2 if instr( cN$, str$( cN)) then found =1 else found =0 end function
function rndChrs$( N) ' generate random alpha content for i =1 to N rndChrs$ =rndChrs$ +chr$( 65 +int( 26 *rnd( 1))) next i 'rndChrs$ ="asdfghjkl" end function
|
|
|
Post by tenochtitlanuk on Nov 1, 2021 6:33:57 GMT -5
How about this? For testing, I skip the file-generation code after first run so the starting file is always the same, and I have a file 'cowNumber.fil' with the acceptable cow numbers. I open/check/close this, but you could open at start of code and close only on clean exit. goto [fileCreatedAlready]
' Create a file with dummy data in format 'asdfghjkl VN9900xx zxcxvbnm'. open "file.txt" for output as #fOut for i =1 to 20 s1$ =rndChrs$( 10) s2$ =" VN990004"
s4$ =right$( " " +str$( int( 1 +9 *rnd( 1))), 6) s5$ =" " +rndChrs$( 30)
#fOut s1$ +s2$ +s3$ +s4$ +s5$ next i close #fOut
[fileCreatedAlready] ' Read the file. If 'VN990004' present in a line, skip- otherwise write to file count =0
open "newFile.txt" for output as #fOut2
open "file.txt" for input as #fIn do line input #fIn, row$ 'print row$ I =instr( row$, "VN990004") if I <>0 then cowNumber =val( mid$( row$, I +9, 6))
if I <>0 and found( cowNumber) then #fOut2 row$ print "."; ' showing progress.. else count =count +1 print "!"; end if loop until row$ ="" or eof( #fIn) <0 close #fIn
close #fOut2
print "" print " I removed "; count; " rows of data referring to 'VN990004' but cow number not in 'cowNumber.fil'."
end ' _________________________________________________
function found( cN) open "cowNumber.fil" for input as #fIn2 cN$ =input$( #fIn2, lof( #fIn2)) close #fIn2 if instr( cN$, str$( cN)) then found =1 else found =0 end function
function rndChrs$( N) ' generate random alpha content for i =1 to N rndChrs$ =rndChrs$ +chr$( 65 +int( 26 *rnd( 1))) next i 'rndChrs$ ="asdfghjkl" end function
|
|
|
Post by tenochtitlanuk on Oct 31, 2021 11:35:21 GMT -5
This may help you a bit.I create a file of random lines or rows with different version numbers in the format you show embedded in some random text. Code reads this file and creates a new, shortened file. You might want instead to over write the old file- but be careful not to overwrite wanted data!
' Create a file with dummy data in format 'asdfghjkl VN9900xx zxcxvbnm'. open "file.txt" for output as #fOut for i =1 to 100 s1$ =rndChrs$( 10) s2$ =" VN9900"
t$ =str$( int( 25 *rnd( 1))) s3$ =right$( "00" +t$, 2)
s4$ =" " s5$ =rndChrs$( 30)
#fOut s1$ +s2$ +s3$ +s4$ +s5$ next i close #fOut
' Read the file. If 'VN990004' present in a line, skip- otherwise write to file count =0
open "newFile.txt" for output as #fOut2
open "file.txt" for input as #fIn do line input #fIn, row$ 'print row$ if instr( row$, "VN990004") =0 then #fOut2 row$ print "."; ' showing progress.. else count =count +1 print "!"; end if loop until row$ ="" or eof( #fIn) <0 close #fIn
close #fOut2
print "" print " I removed "; count; " rows of data referring to 'VN990004'"
end ' _________________________________________________
function rndChrs$( N) ' generate random alpha content for i =1 to N rndChrs$ =rndChrs$ +chr$( 65 +int( 26 *rnd( 1))) next i 'rndChrs$ ="asdfghjkl" end function
|
|
|
Post by tenochtitlanuk on Oct 27, 2021 14:37:52 GMT -5
Diolch i ti hefyd. Nice to see some Welsh on here. My wife comes from a row of Welsh terrace houses in Swansea- so it's now my spiritual home.
JohnF
|
|
|
Post by tenochtitlanuk on Oct 25, 2021 16:43:34 GMT -5
...and for completeness...
|
|
|
Post by tenochtitlanuk on Oct 24, 2021 13:32:58 GMT -5
....HSV coloured houses...
|
|
|
Post by tenochtitlanuk on Oct 24, 2021 11:01:32 GMT -5
'....and they ( no longer!) all come out the same....'
Pete Seeger 1963 for those who weren't there......
Little boxes on the hillside Little boxes made of ticky tacky Little boxes Little boxes Little boxes all the same There's a green one and a pink one And a blue one and a yellow one And they're all made out of ticky tacky And they all look just the same And the people in the houses all go to the university And they all get put in boxes, little boxes all the same And there's doctors and there's lawyers And business executives And they're all made out of ticky tacky and they all look just the same And they all play on the golf course and drink their martini dry And they all have pretty children and the children go to school And the children go to summer camp And then to the university And they all get put in boxes, and they all come out the same And the boys go into business and marry and raise a family And they all get put in boxes, little boxes all the same There's a green one, and a pink one And a blue one and a yellow one And they're all made out of ticky tacky And they all look just the same
|
|
|
Post by tenochtitlanuk on Oct 20, 2021 17:16:18 GMT -5
Old hands will remember that LB4 turtle graphic moves go to an (integer) pixel and don't store the 'precise' value. In LB5, they retain the precise position but we don't yet have dll calls. When I add the fill routine, some of the figures do not close, and leak. In LB5 the new turtle does not suffer this problem. The graphic cycles through spiral-of-houses with LB4 with size =1 ( leaves gaps occasionally), with size =2 ( less neat, but tends to close the gaps), and with LB5 ( figures close, but can't be filled).
|
|
|
Post by tenochtitlanuk on Oct 18, 2021 16:50:58 GMT -5
Have to run this in LB5 to get the figures accurate and closing the path. Now add the fill..
|
|