### Recent Posts

Pages: [1] 2 3 ... 10
1
##### Beginner's Help / Re: Random Files and Arrays
« Last post by TempodiBasic on April 04, 2018, 06:14:06 am »
Sorry
I have seen that I have posted the example without array of TYPE of Pete example...
now it is ok
.......

Hi Codeguy,
Good Stuff to go over border of QB64 TYPING

QB64 Community rocks!!!
2
##### Beginner's Help / Re: Pile of balls
« Last post by Make71 on April 03, 2018, 11:06:36 pm »
Code: [Select]
`[quote_TITLE "Dropping Balls pile attempt bplus 2018-04-03"'attempt to build pile by adjusting drop rate, elasticity, gravity' remove sound and adjust dropping to center of screen' built from Dropping balls 4 w snd and STATIC created 2018-04-3' add STATIC's moving ball before figuring bounce from collision' which was a mod of Dropping Balls 2 w sound posted 2018-03-31RANDOMIZE TIMERCONST xmax = 800CONST ymax = 600SCREEN _NEWIMAGE(xmax, ymax, 32)_SCREENMOVE 360, 60elastic = .5gravity = .5balls = 160DIM x(balls), y(balls), r(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)FOR i = 1 TO balls    r(i) = 15    x(i) = xmax / 2 + (i MOD 2) * 8 - 4    y(i) = 0    dx(i) = 0    dy(i) = 3    rr(i) = rand(200, 255)    gg(i) = rand(200, 255)    bb(i) = rand(200, 255)NEXTmaxBall = 0WHILE 1    CLS    loopCnt = loopCnt + 1    IF loopCnt MOD 17 = 0 THEN        IF maxBall < balls THEN maxBall = maxBall + 1    END IF    COLOR _RGB32(255, 255, 255)    _PRINTSTRING (100, 10), "Balls:" + STR\$(maxBall)    FOR i = 1 TO maxBall        'ready for collision        dy(i) = dy(i) + gravity        a(i) = _ATAN2(dy(i), dx(i))        imoved = 0        FOR j = i + 1 TO maxBall            ' The following is STATIC's adjustment of ball positions if overlapping            ' before calcultion of new positions from collision            ' Displacement vector and its magnitude.  Thanks STxAxTIC !            nx = x(j) - x(i)            ny = y(j) - y(i)            nm = SQR(nx ^ 2 + ny ^ 2)            IF nm < 1 + r(i) + r(j) THEN                nx = nx / nm                ny = ny / nm                ' Regardless of momentum exchange, separate the balls along the lone connecting them.                DO WHILE nm < 1 + r(i) + r(j)                    flub = .001 '* RND                    x(j) = x(j) + flub * nx                    y(j) = y(j) + flub * ny                    x(i) = x(i) - flub * nx                    y(i) = y(i) - flub * ny                    nx = x(j) - x(i)                    ny = y(j) - y(i)                    nm = SQR(nx ^ 2 + ny ^ 2)                    nx = nx / nm                    ny = ny / nm                LOOP                imoved = 1                a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))                a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))                'update new dx, dy for i and j balls                power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5                power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5                power = elastic * (power1 + power2) / 2                dx(i) = power * COS(a(i))                dy(i) = power * SIN(a(i))                dx(j) = power * COS(a(j))                dy(j) = power * SIN(a(j))                x(i) = x(i) + dx(i)                y(i) = y(i) + dy(i)                x(j) = x(j) + dx(j)                y(j) = y(j) + dy(j)                'EXIT FOR            END IF        NEXT        IF imoved = 0 THEN            x(i) = x(i) + dx(i)            y(i) = y(i) + dy(i)        END IF        IF x(i) < -r(i) OR x(i) > xmax + r(i) THEN            x(i) = xmax / 2 + (i MOD 2) * 4 * r(i) - 2 * r(i)            y(i) = 0            dx(i) = 0            dy(i) = 3        END IF        IF y(i) + r(i) > ymax THEN y(i) = ymax - r(i): dy(i) = -dy(i) * elastic '???: x(i) = x(i) + .1 * dx(i)        FOR rad = r(i) TO 1 STEP -1            COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)            fcirc x(i), y(i), rad        NEXT    NEXT    _DISPLAY    _LIMIT 20WENDFUNCTION rand (lo, hi)    rand = (RND * (hi - lo + 1)) \ 1 + loEND FUNCTIONFUNCTION rdir ()    IF RND < .5 THEN rdir = -1 ELSE rdir = 1END FUNCTION'Steve McNeil's  copied from his forum   note: Radius is too common a nameSUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)    DIM subRadius AS LONG, RadiusError AS LONG    DIM X AS LONG, Y AS LONG    subRadius = ABS(R)    RadiusError = -subRadius    X = subRadius    Y = 0    IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB    ' Draw the middle span here so we don't draw it twice in the main loop,    ' which would be a problem with blending turned on.    LINE (CX - X, CY)-(CX + X, CY), , BF    WHILE X > Y        RadiusError = RadiusError + Y * 2 + 1        IF RadiusError >= 0 THEN            IF X <> Y + 1 THEN                LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF                LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF            END IF            X = X - 1            RadiusError = RadiusError - X * 2        END IF        Y = Y + 1        LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF        LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF    WENDEND SUBSUB snd (frq, dur)    SOUND frq / 2.2, dur * .01END SUB`[/quote]

This program is close to what I wanted! In fact, it's magnificent! ;-D
3
##### Beginner's Help / Re: Random Files and Arrays
« Last post by codeguy on April 03, 2018, 10:44:08 pm »
http://www.qb64.net/forum/index.php?topic=1647.msg14594#msg14594
the emergency arrays in types workaround.
4
##### Beginner's Help / Re: Pile of balls
« Last post by bplus on April 03, 2018, 08:24:12 pm »
Playing around with the code in reply #6, I came up with this. The result of coding too many air hockey games:
Code: [Select]
`_TITLE "pyramid of circles 2 by bplus 2018-04-03"CONST xmax = 800CONST ymax = 600SCREEN _NEWIMAGE(xmax, ymax, 32)_SCREENMOVE 360, 60DIM SHARED px(154), py(154), rr(154), gg(154), bb(154)FOR i = 1 TO 153    rr(i) = (RND * 55 + 200)    gg(i) = RND * 55 + 200 * INT(RND * 2)    bb(i) = RND * 55 + 200NEXT'let n = number of circles at base of pilen = 10'let r = radius of each circler = 20'let base be total length of pilebaseLength = 2 * r * n' center pyramid in middle of screenstartx = (xmax - baseLength) / 2'stacking circles that form equilateral triangles at their origins have a height change ofdeltaHeight = r * 3 ^ .5 'r times the sqr(3)FOR row = n TO 1 STEP -1    IF row = n THEN y = ymax - r - 1 ELSE y = y - deltaHeight    FOR col = 1 TO row        x = startx + col * 2 * r - r        index = index + 1        target x, y, index    NEXT    startx = startx + rNEXTSLEEPSUB target (x, y, i)    nx = x: ny = y    ra = _PI(1 / (INT(RND * 7) + 4) + 1 / 2)    dx = 10 * COS(ra)    dy = 10 * SIN(ra)    bounce = 0: rb = INT(RND * 7) + 3    WHILE bounce < rb        IF nx + dx > xmax - 20 OR nx + dx < 20 THEN dx = -dx: bounce = bounce + 1        IF ny + dy > ymax - 20 OR ny + dy < 20 THEN dy = -dy: bounce = bounce + 1        nx = nx + dx: ny = ny + dy    WEND    dx = -dx: dy = -dy    WHILE bounce > 0        IF nx + dx > xmax - 20 OR nx + dx < 20 THEN dx = -dx: bounce = bounce - 1        IF ny + dy > ymax - 20 OR ny + dy < 20 THEN dy = -dy: bounce = bounce - 1        nx = nx + dx: ny = ny + dy        CLS        FOR j = 1 TO i - 1            FOR rad = 20 TO 1 STEP -1                COLOR _RGB32(rr(j) - 10 * rad, gg(j) - 10 * rad, bb(j) - 10 * rad)                fcirc px(j), py(j), rad            NEXT        NEXT        FOR rad = 20 TO 1 STEP -1            COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)            fcirc nx, ny, rad        NEXT        _DISPLAY        _LIMIT 200    WEND    'last bit    WHILE SQR((nx - x) ^ 2 + (ny - y) ^ 2) > 20        nx = nx + dx        ny = ny + dy        CLS        FOR j = 1 TO i - 1            FOR rad = 20 TO 1 STEP -1                COLOR _RGB32(rr(j) - 10 * rad, gg(j) - 10 * rad, bb(j) - 10 * rad)                fcirc px(j), py(j), rad            NEXT        NEXT        FOR rad = 20 TO 1 STEP -1            COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)            fcirc nx, ny, rad        NEXT        _DISPLAY        _LIMIT 200    WEND    CLS    FOR j = 1 TO i - 1        FOR rad = 20 TO 1 STEP -1            COLOR _RGB32(rr(j) - 10 * rad, gg(j) - 10 * rad, bb(j) - 10 * rad)            fcirc px(j), py(j), rad        NEXT    NEXT    FOR rad = 20 TO 1 STEP -1        COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)        fcirc x, y, rad    NEXT    _DISPLAY    _DELAY .25    px(i) = x: py(i) = yEND SUB'Steve McNeil's  copied from his forum   note: Radius is too common a nameSUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)    DIM subRadius AS LONG, RadiusError AS LONG    DIM X AS LONG, Y AS LONG    subRadius = ABS(R)    RadiusError = -subRadius    X = subRadius    Y = 0    IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB    ' Draw the middle span here so we don't draw it twice in the main loop,    ' which would be a problem with blending turned on.    LINE (CX - X, CY)-(CX + X, CY), , BF    WHILE X > Y        RadiusError = RadiusError + Y * 2 + 1        IF RadiusError >= 0 THEN            IF X <> Y + 1 THEN                LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF                LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF            END IF            X = X - 1            RadiusError = RadiusError - X * 2        END IF        Y = Y + 1        LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF        LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF    WENDEND SUB`
5
##### Beginner's Help / Re: Pile of balls
« Last post by bplus on April 03, 2018, 02:37:07 pm »
OK pretty darn close thanks to STxAxTIC's help!

Code: [Select]
`_TITLE "Dropping Balls pile attempt bplus 2018-04-03"'attempt to build pile by adjusting drop rate, elasticity, gravity' remove sound and adjust dropping to center of screen' built from Dropping balls 4 w snd and STATIC created 2018-04-3' add STATIC's moving ball before figuring bounce from collision' which was a mod of Dropping Balls 2 w sound posted 2018-03-31RANDOMIZE TIMERCONST xmax = 800CONST ymax = 600SCREEN _NEWIMAGE(xmax, ymax, 32)_SCREENMOVE 360, 60elastic = .5gravity = .5balls = 160DIM x(balls), y(balls), r(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)FOR i = 1 TO balls    r(i) = 15    x(i) = xmax / 2 + (i MOD 2) * 8 - 4    y(i) = 0    dx(i) = 0    dy(i) = 3    rr(i) = rand(200, 255)    gg(i) = rand(200, 255)    bb(i) = rand(200, 255)NEXTmaxBall = 0WHILE 1    CLS    loopCnt = loopCnt + 1    IF loopCnt MOD 17 = 0 THEN        IF maxBall < balls THEN maxBall = maxBall + 1    END IF    COLOR _RGB32(255, 255, 255)    _PRINTSTRING (100, 10), "Balls:" + STR\$(maxBall)    FOR i = 1 TO maxBall        'ready for collision        dy(i) = dy(i) + gravity        a(i) = _ATAN2(dy(i), dx(i))        imoved = 0        FOR j = i + 1 TO maxBall            ' The following is STATIC's adjustment of ball positions if overlapping            ' before calcultion of new positions from collision            ' Displacement vector and its magnitude.  Thanks STxAxTIC !            nx = x(j) - x(i)            ny = y(j) - y(i)            nm = SQR(nx ^ 2 + ny ^ 2)            IF nm < 1 + r(i) + r(j) THEN                nx = nx / nm                ny = ny / nm                ' Regardless of momentum exchange, separate the balls along the lone connecting them.                DO WHILE nm < 1 + r(i) + r(j)                    flub = .001 '* RND                    x(j) = x(j) + flub * nx                    y(j) = y(j) + flub * ny                    x(i) = x(i) - flub * nx                    y(i) = y(i) - flub * ny                    nx = x(j) - x(i)                    ny = y(j) - y(i)                    nm = SQR(nx ^ 2 + ny ^ 2)                    nx = nx / nm                    ny = ny / nm                LOOP                imoved = 1                a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))                a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))                'update new dx, dy for i and j balls                power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5                power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5                power = elastic * (power1 + power2) / 2                dx(i) = power * COS(a(i))                dy(i) = power * SIN(a(i))                dx(j) = power * COS(a(j))                dy(j) = power * SIN(a(j))                x(i) = x(i) + dx(i)                y(i) = y(i) + dy(i)                x(j) = x(j) + dx(j)                y(j) = y(j) + dy(j)                'EXIT FOR            END IF        NEXT        IF imoved = 0 THEN            x(i) = x(i) + dx(i)            y(i) = y(i) + dy(i)        END IF        IF x(i) < -r(i) OR x(i) > xmax + r(i) THEN            x(i) = xmax / 2 + (i MOD 2) * 4 * r(i) - 2 * r(i)            y(i) = 0            dx(i) = 0            dy(i) = 3        END IF        IF y(i) + r(i) > ymax THEN y(i) = ymax - r(i): dy(i) = -dy(i) * elastic '???: x(i) = x(i) + .1 * dx(i)        FOR rad = r(i) TO 1 STEP -1            COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)            fcirc x(i), y(i), rad        NEXT    NEXT    _DISPLAY    _LIMIT 20WENDFUNCTION rand (lo, hi)    rand = (RND * (hi - lo + 1)) \ 1 + loEND FUNCTIONFUNCTION rdir ()    IF RND < .5 THEN rdir = -1 ELSE rdir = 1END FUNCTION'Steve McNeil's  copied from his forum   note: Radius is too common a nameSUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)    DIM subRadius AS LONG, RadiusError AS LONG    DIM X AS LONG, Y AS LONG    subRadius = ABS(R)    RadiusError = -subRadius    X = subRadius    Y = 0    IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB    ' Draw the middle span here so we don't draw it twice in the main loop,    ' which would be a problem with blending turned on.    LINE (CX - X, CY)-(CX + X, CY), , BF    WHILE X > Y        RadiusError = RadiusError + Y * 2 + 1        IF RadiusError >= 0 THEN            IF X <> Y + 1 THEN                LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF                LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF            END IF            X = X - 1            RadiusError = RadiusError - X * 2        END IF        Y = Y + 1        LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF        LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF    WENDEND SUBSUB snd (frq, dur)    SOUND frq / 2.2, dur * .01END SUB`
6
##### Beginner's Help / Re: Decision Algorythms
« Last post by TempodiBasic on April 03, 2018, 06:46:29 am »
Thank's QBExile
very interesting
Quote
MarI/O is a program made of neural networks and genetic algorithms that kicks butt at Super Mario World.
The solution is coming Dimster
here we need only a model of neural networks and of genetic algorithms for recognizing and evaluating an experience. And then for using experience stored in memory for building more functions to use with an experience.

7
##### Beginner's Help / Re: Random Files and Arrays
« Last post by TempodiBasic on April 03, 2018, 06:32:25 am »
Hi MLambert

I can agree that knowing nothing about file data with so many fields, our contribution to solve the issue can be so unuseful because it has been thought on an abstract model with so poor informations....

1.
Quote
The data was created by a QB64 program.
and
Quote
I want to use the data structure to make it easier to read for doco.

Solution A:

So using the same language to write, you can manage also the structure of the data_file....
IMHO you can use a Sub/Function to access ( NO MSAccess https://en.wikipedia.org/wiki/Microsoft_Access) inverting PUT# instruction into GET# instruction
see here http://www.qb64.net/wiki/index.php/PUT PUT
http://www.qb64.net/wiki/index.php/GET GET

Solution B:
Quote
I want to use the data structure to make it easier to read for doco.

sorry my bad understanding this sentence....
Do you want to read/load easily in a document data type this data_file ?

If you say this,

you simply need to use a data field  delimiter as in CSV file that uses ";" as delimiter....
Solution B.1:
if you use CSV delimiter your data file is openable by all spreadsheet  and database softwares, see here https://en.wikipedia.org/wiki/Comma-separated_values

Solution B.2:
you can use an your personalized delimiter from 1 to so many bytes to get difficult to access data from external softwares but with an easy file parser you can get manually each field with personalized block_code routine ....

2.
I must understand better this...
Quote
The data was created by a QB64 program. I am already writing and accessing large random files using QB64 and it works
please can you explain it to me with other words?

With your routine to save data to file do you use one record type? I think no, because in this case you have already the solution. So my thinking about your questions go on

Solution C:
I remarke here solution of SkyCharger...
You say
Quote
I have over 200 fields of the same length that I want to define for a random file. The file also contains other different fields of different data types. How can I easily code these 200 fields without doing Fld\$(1) Fld\$(2) etc..

Quote
My first idea is to switch to BINARY and start with an offset-table.
EG:
byte 0-F = offset-pointers
byte 0-3 = start of field-type A
byte 4-7 = start of field-type B
byte 8-B = start of field-type C
byte C-F = start of field-type D

and
you say
Quote
Thank you for your input. I want to avoid having to code 200 lines ..what you are showing me is the same as fld\$(1) fld\$(2) fld\$(3) etc.... 200 times
sorry but you miss the idea behind the answer

so with permission of SkyCharger  I make the idea of ​​the offset table more explicit
hey MLambert why do yo want to make the work of PC?  Let write the offset table to the Writing Routine of your QB64 program when it stores the data into the file....  I think it is better this than write 200 and over lines of assignation code
you can create a file of offset for each record (if you have a record that you write in a file) and then you can load this to access to data...
Your database needs two files one for offset of each record and the second for storing data into it...
you use a DataType to load the record of offset of fields and then you can access to the record_block data into datafile, the first file is a simple integer or longinteger sequence of data/variable that are the pointers to the specific data stored in the second file called datafile
( in a more complicated way you can merge the two files into one just using the offset table as a file head). The offsetfile can be accessed as RAfile and you get smartly the location of your data in the datafile...

Solution D:
in a similar manner if you have no record type in storing data but only fields you can use the offset datafile for get pointers to each field of the second datafile that brings the informations.... the idea is the same of the HAS TABLE used from OSes to manage disk and ram storages see here for info https://www.tutorialspoint.com/data_structures_algorithms/hash_data_structure.htm https://en.wikipedia.org/wiki/Page_table
https://www.tutorialspoint.com/dbms/dbms_indexing.htm DBMS and https://en.wikipedia.org/wiki/Database_index Indexing

3.
and I must remarke these previous answers....
Pete says
Quote
For a RANDOM file, just feed the file contents into the array. Just make sure you figure out what the longest record is, because your array and the LEN of the RA file will need to be dimensioned to that length or greater.
Quote
Hi Pete, Thank you for your input ... but I don't understand what you are doing.  My random file contain 400,000+ records . Each record is made up of many different data fields .. of which 200 of them contain values. Using a 'Type' would give me a good data structure and offers good documentation of the sequence and properties of the various fields within the records.

IMHO Pete has posted a good example code and with so little effort mutatis mutandis https://en.wikipedia.org/wiki/Mutatis_mutandis you get the solution code.... or
Solution E:
if you are lazy in this moment you can download the code of Pete modded by me to use Nested Type Data and attached at the bottom of this kilometer post.
But please remember to define the lenght of the record and use that master storage space for all records....in writing and in reading RA files... in this moment there are so large HDD or SSD

and more
if you love RA file and record structure I hardly agree with Fellippe
Quote
You need to rethink  your data logic
IMHO
Solution F:
you can modelling  the data TYPE to your need without needing  arrays into TYPE if you love in the same intensity QB64...
and if you don't want write more than 200 lines of code to define it .... let do this work to PC using a second file that defines datatype while it writes database file....so in different file the saving routing put the code of the record that it can be used the next time to write and load... in many words with pseudo_code, imagining that there is no record structure in saving routine, so in a way you run among many different fields/variables for reading and saving in the file.... at a point you have thought: why don't use a record with data types? I can save time and make code more readable....but.... so many similar variables...they can be grouped into an array().... and BASIC (QBASIC and QB64 don't let this!!!!)

__________________
FIRST STEP
SUB Saving dataToFile
open FileDataBase as RANDOM #1
open RecordCodeFile as Output #2
print #2, " TYPE DATA "

for rec 1 to MaxRec
put #1 , Var(rec)
print #2, " Var"+str\$(rec)+" as typedef(rec)"
next rec
END SUB
_______________
surely you don't must discover the type of each field/variable that you save into the file.

Solution G:
because I think you'll find GREAT this solution....coming from the GREAT Steve
as  that black duck (meself) time ago said here http://www.qb64.net/forum/index.php?topic=13548.msg117527#msg117527
http://www.qb64.net/forum/index.php?topic=7151.0

and here http://www.petesqbsite.com/phpBB3/viewtopic.php?t=4034 to come back here http://www.qb64.net/wiki/index.php/SQL_Client
while here there are some informations http://forum.qbasicnews.com/index.php?topic=12618.0

PS Yeah this community rocks...
while I'm writing you've got  other two answers...(Fellippe's reply, Bplus's solution using JOIN before writing and SPLIT before reading
8
##### Beginner's Help / Re: Decision Algorythms
« Last post by bplus on April 03, 2018, 05:39:20 am »
Neat, thanks QBExile!
9
##### Beginner's Help / Re: Decision Algorythms
« Last post by QBExile on April 03, 2018, 05:25:14 am »
Have a look at this video i think its exactly what you would want.
10
##### Beginner's Help / Re: Random Files and Arrays
« Last post by bplus on April 03, 2018, 04:49:35 am »
Make one field that contains the 200 "fields" with with the same length, before you save to file.

When you load data file into program THEN split the 200 data fields from the one giant one to an array to process data from an array.

When ready to restore data, combine the 200 fields from the array back into one giant field.

Better yet split the 200 fields out in a JIT basis when you need an item from one of the fields, like JB's word\$(source\$, index, delimiter) only instead of delimiter use... well heck I am just describing using the mid\$ function to get the 200 "fields" out of the giant field. It's just substrings from a giant string.

Pages: [1] 2 3 ... 10