|
Post by tenochtitlanuk on Mar 24, 2022 16:52:31 GMT -5
|
|
|
Post by tenochtitlanuk on Mar 19, 2022 18:24:15 GMT -5
Haven't had time to much change my boids- but they now are attracted to the centre of the screen and the CofG of the flock. They lose energy if they bounce of the wall, and as time passes. So they end in swooping orbits round /near each other. And I've improved their world wit a photo I took a couple of days ago... I need a big slot of time to examine exactly what others have achieved- and how. Won't be soon..
|
|
|
Post by tenochtitlanuk on Mar 16, 2022 15:48:01 GMT -5
I'm coming into this a bit late, with little spare time, and as always I'm more interested in the appearance and flocking-rules than in speed. Can always save a series of images and play as an animated GIF... This image shows how it displays- each boid as a circle and velocity-vector arrow. Now to implement the usual boid-rules.. The Boids Rules Rule 1: Boids try to fly towards the centre of mass of neighbouring boids. Rule 2: Boids try to keep a small distance away from other objects (including other boids). Rule 3: Boids try to match velocity with near boids. Lots of others to add- edge behaviour ( bounce or wrap). goal-setting, obstacles. EDIT - present code- velocities not yet being changed, but looks good! '******************************************** '** ** '** tenochBoids2.bas 16/03/21 ** '** ** '** create a field of flocking boids ** '** ** '********************************************
nomainwin
WindowWidth =620 WindowHeight =620
'Each boid represented in a csv string of x, y, vx, vy 'x/y onscreen if in o...600. Velocity of 1 represents one pixel per cycle.
N =100 dim boid$( N)
open "Tenochtitlanuk Boids" for graphics_nsb as #wg
#wg "trapclose quit"
#wg "down ; size 10 ; fill 80 80 255"
gosub [createBoidField]
for H = 1 to N gosub [drawBoidField] gosub [updateBoidField] next H
wait ' __________________________________________________________
[createBoidField] for i =0 to N -1 ' create a random flock, all on-screen x =600 *rnd( 1) y =600 *rnd( 1) vx = 10 *rnd( 1) -5 vy = 10 *rnd( 1) -5 boid$( i) =str$( x) +"," +str$( y) +"," +str$( vx) +"," +str$( vy) next i return
[drawBoidField] #wg "cls ; fill 80 80 255" for i =0 to N -1 ' draw current state of flock, call drawBoid boid$( i) scan next i return
[updateBoidField] for K =0 to N -1 ' create a random flock, all on-screen x =val( word$( boid$( K), 1,",")) y =val( word$( boid$( K), 2,",")) vx =val( word$( boid$( K), 3,",")) vy =val( word$( boid$( K), 4,",")) if x <=1 or x >=600 then vx =0 -vx if y <=1 or y >=600 then vy =0 -vy x =x +vx y =y +vy boid$( K) =str$( x) +"," +str$( y) +"," +str$( vx) +"," +str$( vy) scan next K return
sub drawBoid i$ ' draw an individual boid #wg "color darkblue" #wg "size 10" x =val( word$( i$, 1,",")) y =val( word$( i$, 2,",")) #wg "set "; int( x); " "; int( y) vx =val( word$( i$, 3,",")) vy =val( word$( i$, 4,",")) magn =( vx^2 +vy^2)^0.5 dirn =Atan2( vy, vx) nx =x +vx ny =y +vy #wg "color white" #wg "size 1" #wg "goto "; x -4 *vx; " "; y -4 *vy end sub
Function Atan2( y, x) If x = 0 Then If y < 0 Then Atan2 = -1.5707963267948967 Else Atan2 = 1.5707963267948967 End If Else chk = atn(y/x) If x < 0 Then If y < 0 Then chk = chk - 3.1415926535897932 Else chk = chk + 3.1415926535897932 End If End If Atan2 = chk End If 'thanks Andy Amaya End Function
sub quit h$ close #h$ end end sub
|
|
|
Post by tenochtitlanuk on Mar 5, 2022 16:24:22 GMT -5
Here's a version which shows the corrections/alterations from your version. The changes are I think all flagged with '<<<<<<< It produces a 'ping' of exponentially decaying 880Hz. Not tested on other sample frequencies or stereo etc....
I'll be posting soon on my LB site a fuller version, including the reason your waveforms would have come out wrong because you missed the need for twos complement.
' ***** bluatigroWorking.bas *****
'Two speed-ups for sine, which is slow and repeatedly used- '1 calculate in advance an array called sine( ) at every 1 degree. ' Use int( ) to find sine() rather than using LB's sin() over and over. '2 work out one complete cycle of your sine wave, then add it multiple times to wav$. ' NB this doesn't work if you are calculating sine waves with decaying amplitudes.
WindowWidth = 650 WindowHeight = 460
nomainwin
' wav file sections.... global rID$ : rID$ = "RIFF" global rLen ' file size minus 8 global wID$ : wID$ = "WAVE" global fID$ : fID$ = "fmt " global fLen : fLen = 16 global FmtTag : FmtTag = 1 'NB I use Channels here not Channels$ '<<<<<<<<<<<< global Channels : Channels = 1 ' 1 = Mono, 2 = Stereo '<<<<<<< global SampleRate : SampleRate = 11025 ' 11025 = 11kHz, 22050 = 22 kHz, etc. global AvgBytesPerSec : AvgBytesPerSec = SampleRate *Channels *BitsPerSample /8 '<<<<<<<< global BlockAlign : BlockAlign = 4 ' BlockAlign = Channels * BitsPerSample / 8 '<<<<<<< global BitsPerSample : BitsPerSample = 16 ' 8, 16, etc. global dID$ : dID$ = "data"
global dLen ' length in bytes of the sound buffer
global sec : sec = 1 global bufsize : bufsize = SampleRate * sec * 2 global hz : hz = 880 global pi
rLen = 44 + bufsize - 8
AvgBytesPerSec = SampleRate * Channels * BitsPerSample / 8'<<<<<<<<< 'BlockAlign = Channels * BitsPerSample / 8'<<<<<<<<< dLen = bufsize
pi = atn( 1 ) * 4 sound$ = ""
for i = 1 to bufsize step 2 '<<<<<<<< 'byte = sin( i * pi * 2 * hz / bufsize ) * 32765'<<<<<<<<<<< byte = (exp( ( 0 -T) /400) *sin( i / bufsize * pi * 2 * hz ) ) * 32765 scan sound$ = sound$ + sample$( byte ) T =T +0.08 ' to make exponential decay next
call savewav "expSin" , sound$'<<<<<<< name change playwave "expSin.wav" notice "Ready" wait
sub savewav file$ , wav$ rLen = 44 + len( wav$) - 8 dLen = len( wav$) open file$ + ".wav" for output as #wav #wav rID$; #wav ul$( rLen); #wav wID$; #wav fID$; #wav ul$( fLen); #wav b16$( FmtTag); '<<<<< #wav b16$( Channels); '<<<<< #wav ul$( SampleRate); #wav ul$( AvgBytesPerSec); #wav b16$( BlockAlign); '<<<<< #wav b16$( BitsPerSample); '<<<<< #wav dID$; #wav ul$( dLen) #wav wav$ close #wav end sub
function sample$( in ) ' <<<<<<<< Your routine produces a weird inverted wave select case in ' This is a twos-complement two-byte that is neeeded case in >=0 in =2^16 -in case in <0 in =0 -in end select low = int( in / 256 ) and 255 hi = ( in - low ) / 256 and 255 sample$ = chr$( low ) + chr$( hi ) end function
function b16$( in ) ' '<<<<<<< New function to generate two byte, lo-hi pairs a = int( in ) and 255 b = int( in / 256 ) and 255 b16$ = chr$( a ) + chr$( b ) end function
function ul$( in ) a = int( in ) and 255 b = int( in / 256 ) and 255 c = int( in / 256 ^ 2 ) and 255 d = int( in / 256 ^ 3 ) and 255 ul$ = chr$( a) +chr$( b) +chr$( c) +chr$( d) '<<<<<< you had wrong way round.. end function
sub printAscii in$ for k =1 to len( in$) print right$( "00" +dechex$( asc( mid$( in$, k, 1))), 2); " "; next k print "" end sub
function asAscii$( in$) asAscii$ ="" for k =1 to len( in$) asAscii$ =asAscii$ +" " +right$( "00" +dechex$( asc( mid$( in$, k, 1))), 2) +" " next k end function
|
|
|
Post by tenochtitlanuk on Mar 4, 2022 17:33:24 GMT -5
After much tinkering I've modified your version to work correctly. Unfortunately I added lots of spaces and diagnostic lines- I'll need to remove them for it to be any use.
One important thing was you were generating an offset value rather than the twos complement. This makes a tone but the positive and negative parts swoop down/up to mid-range, rather then up/down from mid-range. You also were generating twice the correct number of samples.
I'm travelling until end of next week- so will post code as soon as I can suitably tidy it.
|
|
|
Post by tenochtitlanuk on Mar 4, 2022 6:00:24 GMT -5
Fun. I'd noticed before that it was a Rosetta Code task with no LB entry. Boids On these tasks I get carried away with the fun of making it more sophisticated- and end up not bothering to cut it back to basics as an RC solution. I look forward to examining your code- I'm a bit busy at the moment..
|
|
|
Post by tenochtitlanuk on Mar 1, 2022 4:38:00 GMT -5
Totally random colouring looks formlessand senseless. So I took a random-colour starting version.. ..and filled with colours using HSV palette coding for distance from centre. Much more aesthetic and soothing feel to it!
|
|
|
Post by tenochtitlanuk on Feb 28, 2022 16:49:25 GMT -5
I do 99% of my LB stuff on Linux Mint, on machines 6 or more years old. Snappy, always up-to-date. And free.
I occasionally use my wife's W10 machine- too old to upgrade to W11. It had become incredibly slow. Then I realised 99% of the time it was spinning a process called something like EoA ( as in Ease of Access) I do all the usual MS checks/updates/etc regularly, That MS can allow Windows to run such process killers without telling me is the kind of thing that put me off MS years ago.
I've played with Virtual Machines, hosted on both Linux and MS, but I prefer to select separate installations at boot on different disks or partitions.
|
|
|
Post by tenochtitlanuk on Feb 25, 2022 12:27:22 GMT -5
Blatigro and I have played with some AI stuff. See my website for things like fuzzy logic; k means; etc.
The Fisher/Iris database was one of the things I played with. It is regarded as a salutary example to beginning AI programmers because the data contains three species of iris, but you can only distinguish one from the grouped set of the other two. If I find time I'll try it on the penguins..
I was particularly interested because my father was a Cambridge mathematician in the Thirties. He was R W Fisher, and every so often people with a maths background have asked 'Was he THAT R Fisher?'. Sadly not, but he was a much better mathematician than me! I'm much more interested in science/technology, and struggled with the abstractions of high-level maths. ( that's UK-speak for what my US friends call 'math'.)
|
|
|
Post by tenochtitlanuk on Feb 24, 2022 13:11:16 GMT -5
Your ul$ function is bigendian rather than little endian
See the following, with the four bytes in the correct order. There are other problems too. However A file should be appearing, even if not recognised as wav file so not heard. Will try further debugging.
num =11025 ' should give '11 2B 00 00' ( ie littleendian hex '00002B11'), and does...
blua$ =ul$( num ) for k =1 to len( blua$) print right$( "00" +decHex$( asc( mid$( blua$, k, 1))), 2); " "; next k print ""
wait
function ul$( in ) a = int( in ) and 255 b = int( in / 256 ) and 255 c = int( in / 256 ^ 2 ) and 255 d = int( in / 256 ^ 3 ) and 255 ul$ = chr$( a) +chr$( b) +chr$( c) +chr$( d) end function
|
|
|
Post by tenochtitlanuk on Feb 23, 2022 11:00:32 GMT -5
I'm suspicious of your 2 and 4 byte routines, but only on a 'pad at present. Examining your code ( to generate the preamble part) in a hex editor shows improbable values. You could look at my code at www.diga.me.uk/makeMusic.html where I essentially cheated, using sections copied from a known-good wav file with just two parts altered, plus my generated wav values. My code on there did basically what you are trying... Can't look at your code in detail until home at the weekend.
EDIT There's also Thomas Watson's wave file creator from 2003! See Alyce Watson's site...
|
|
|
Post by tenochtitlanuk on Feb 22, 2022 13:22:44 GMT -5
You've got a 'Channels.struct' in there that I do not understand..
EDIT also a 'BitPerSample' has crept in one line- missing an 's'.
|
|
|
Post by tenochtitlanuk on Feb 20, 2022 13:08:29 GMT -5
I always like fun graphics, and happened to be sheltering from the storms in Hexham Abbey this morning. It has glorious Victorian and modern stained glass windows.
As soon as I was back with my computer I just had to try a random colour fill on a screen from 'Flower of Justice' on the JB proboard forum. Using dll in LB for the fast fills ( the flickering colours are hypnotic when you run the code). The animation just cycles screengrabs at random times through about 1 minute on my old laptop. Now I need to try radial- and angle- and time-influenced colour choices. Will put on my website shortly- it's just re-use of code from other similar tasks.
|
|
|
Post by tenochtitlanuk on Feb 11, 2022 19:48:17 GMT -5
An animated GIF of the latest version. It demonstrates the ability to do more than flood TO a border or THROUGHOUT a color area. But of course pretty slow. Hypnotic to watch it fill in real time! Using the dll call wouldn't work here- may try working on an in-memory image....
|
|
|
Post by tenochtitlanuk on Feb 11, 2022 16:40:24 GMT -5
You'll find various things that might help you on my website- eg www.diga.me.uk/makeMusic.htmlwww.diga.me.uk/fourier.htmlwww.diga.me.uk/ExplainFourier.htmlwww.diga.me.uk/2DfourierFFT.html...so all very do-able. Read the whole file into a single string, and parse out the sampling rate, bytes/sample, and address the data directly from the string. No need to move into an array. Manipulate and write to a new string. Save... Sampling to lower rate would be easy. To higher rates, harder. To save, write the header modified appropriately and then append. But might be easier to convert formats with something like 'Audacity' ( I use LB/Linux)
|
|