|
Post by bplus on May 11, 2023 23:08:50 GMT
Hi dbox I was testing this code and no go on QBJS: _Title "Impossible Oval" 'b+ 2023-01-23 ' FYI start a file with a Title ' and when you go to save it the QB64 IDE will try that name first for yoy
Screen _NewImage(800, 600, 32) ' this sets up a screen width = 800 here, height = 600 here ' 32 gives us _RGB32 colors millions! including alpha = transparent blends
Dim As Long block, r, x, y ' I am setting up a handle for calling an image like a side worksheet for drawing Dim As Single a block = _NewImage(80, 40, 32) ' now I am setting up memory block for image and assigning the handle
_Dest block ' now I am telling QB64 to do all drawing or printing in my side image
For y = 0 To 40 ' here I am drawing a block that is color gradient Line (0, y)-(100, y), midInk~&(80, 0, 0, 255, 100, 100, 1 - y / 40), BF ' midInk takes 2 RGB colors measures the difference in Red, Green, Blue and takes the fraction spec'd in frac## ' to make a color between the first color and the 2nd Next ' now we have a side image of color graient block from first color to 2nd color
_Dest 0 ' set all drawing and printing back to main screen AKA 0
Print "Here's the Color block we just drew off on the side, ...zzz press any to continue" _PutImage (400 - 50, 300 - 20), block, 0 ' this draws the block centered in middle of our screen Sleep ' ...zzz wait for keypress
r = 230: a = 0 ' a couple of variables r for Radius, a for Angle in rdian units here
Do ' find the next location on the circle to draw our side image of a colored block x = 410 + r * 1.5 * Cos(a) y = 300 + r * Sin(a)
_PutImage (x - 50, y - 20), block, 0 ' this draws the block there
a = a + .002 ' this increments the angle going around a circle _Limit 1000 ' this slows down the drawing a tiny bit Loop Until a >= _Pi(2.47) ' need a to go around slightly more than 2*pi = 1 circle
' midInk takes 2 RGB colors measures the difference in Red, Green, Blue and takes the fraction spec'd in frac## ' to make a color between the first color and the 2nd Function midInk~& (r1%, g1%, b1%, r2%, g2%, b2%, fr##) midInk~& = _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##) End Function Is it all the suffixes I am using for midInk~& and if so, how can I do that function as an _Unsigned Long? I am at Aurels forum again and want to share code results with folks not having QB64, the poor souls ;-)) For that matter it would be a real PLUS at the Friends of Basic forum too
|
|
dbox
Junior Member
Posts: 89
|
Post by dbox on May 12, 2023 11:09:08 GMT
Hey bplus , Looks like it's a similar issue that you see sometimes with some of the fcirc examples. QBJS doesn't like to draw blocks of 0 height or width. We might have to put in some special handling for this since QB64 is obviously ok with it. You can get your code to work by just commenting out the BF on line 16: _Title "Impossible Oval" 'b+ 2023-01-23 ' FYI start a file with a Title ' and when you go to save it the QB64 IDE will try that name first for yoy
Screen _NewImage(800, 600, 32) ' this sets up a screen width = 800 here, height = 600 here ' 32 gives us _RGB32 colors millions! including alpha = transparent blends
Dim As Long block, r, x, y ' I am setting up a handle for calling an image like a side worksheet for drawing Dim As Single a block = _NewImage(80, 40, 32) ' now I am setting up memory block for image and assigning the handle
_Dest block ' now I am telling QB64 to do all drawing or printing in my side image
For y = 0 To 40 ' here I am drawing a block that is color gradient Line (0, y)-(100, y), midInk~&(80, 0, 0, 255, 100, 100, 1 - y / 40)', BF ' midInk takes 2 RGB colors measures the difference in Red, Green, Blue and takes the fraction spec'd in frac## ' to make a color between the first color and the 2nd Next ' now we have a side image of color graient block from first color to 2nd color
_Dest 0 ' set all drawing and printing back to main screen AKA 0
Print "Here's the Color block we just drew off on the side, ...zzz press any to continue" _PutImage (400 - 50, 300 - 20), block, 0 ' this draws the block centered in middle of our screen Sleep ' ...zzz wait for keypress
r = 230: a = 0 ' a couple of variables r for Radius, a for Angle in rdian units here
Do ' find the next location on the circle to draw our side image of a colored block x = 410 + r * 1.5 * Cos(a) y = 300 + r * Sin(a)
_PutImage (x - 50, y - 20), block, 0 ' this draws the block there
a = a + .002 ' this increments the angle going around a circle _Limit 1000 ' this slows down the drawing a tiny bit Loop Until a >= _Pi(2.47) ' need a to go around slightly more than 2*pi = 1 circle
' midInk takes 2 RGB colors measures the difference in Red, Green, Blue and takes the fraction spec'd in frac## ' to make a color between the first color and the 2nd Function midInk~& (r1%, g1%, b1%, r2%, g2%, b2%, fr##) midInk~& = _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##) End Function
|
|
|
Post by bplus on May 12, 2023 15:14:11 GMT
Oh that again, man I get rusty fast, old dog and all that...
Thank you very much!
|
|
dbox
Junior Member
Posts: 89
|
Post by dbox on May 12, 2023 15:48:43 GMT
I actually just went ahead and made the change this morning so that will work the same as QB64. It will be in the next release!
|
|
|
Post by bplus on May 12, 2023 15:52:42 GMT
I actually just went ahead and made the change this morning so that will work the same as QB64. It will be in the next release! Great! the less detail I have to remember the better that might be universal.
|
|
|
Post by bplus on Aug 17, 2023 7:39:46 GMT
I am going to keep track of my notes for getting QB64 code working in QBJS. My notes at home are scattered. Maybe this will help others try out QBJS as well. For sure this is handy to run Filled Circles both in QB64 AND QBJS Sub FCirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long) $If WEB Then G2D.FillCircle CX, CY, R, C $Else Dim Radius As Long, RadiusError As Long Dim X As Long, Y As Long Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0 If Radius = 0 Then PSet (CX, CY), C: Exit Sub Line (CX - X, CY)-(CX + X, CY), C, 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), C, BF Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF End If X = X - 1 RadiusError = RadiusError - X * 2 End If Y = Y + 1 Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF Wend $End If End Sub There is probably a whole set of these we can do. I hope to update this as I develope more with QBJS It is really great to use same code for both so nothing needs be altered from something working in QB64. Some notes on that: 1. Dim all variables ie use Option _Explicit to get code up and running then comment it out (QBJS does not recognize but ignores). 2. No use of line labels ie for GoTo or GoSub 3. Flatten Type definitions eg Type MyType as Integer x, y, z ' <<< no multiple listings ' "flatten" x as integer y as integer z as integer Nor do this: Redim arr1(1 to 50), arr2(0) as string do: Redim arr1(1 to 50) Redim arr2(0) as String 4. For now anyway, be careful indexes to arrays are integer (or Long type) apparently JS attempts float type? I've mentioned this before QBJS might be good way to ease into JS which may be door to more modern ways of computing. Bring some QB64 along with you on your adventure! dbox if I am getting any of this wrong please correct Anyone, you are welcome to add to these notes as well, please do.
|
|
|
Post by bplus on Aug 17, 2023 17:15:05 GMT
I found a couple more items: Don't use Step option in _PutImage
Don't use STATIC in a procedure use (Re)Dim Shared in Main Module, top of program where declares usually go.
Don't use BF in line if there is no change in x or y ie you just want a line (not a box of box fill)
|
|
dbox
Junior Member
Posts: 89
|
Post by dbox on Aug 17, 2023 17:16:47 GMT
|
|
|
Post by bplus on Aug 17, 2023 17:19:04 GMT
Beautiful, a place with a link I will be able to find thanks!
Update:
Oh! Already I see one that can cause a problem hard to see, QBJS passes By Value to procedures whereas QB64 passes By Reference. A Sub was a handy way to pass multiple values back to main program because Functions are limited to only one value (in QB64, not QBJS).
The new functionality that QBJS offers might be fun to dabble with while learning JS but won't help much making a QB64 program work in QBJS.
|
|
dbox
Junior Member
Posts: 89
|
Post by dbox on Aug 17, 2023 19:10:06 GMT
The new functionality that QBJS offers might be fun to dabble with while learning JS but won't help much making a QB64 program work in QBJS.
Yes, I've debated over whether to at least provide some metadata command or other method to put QBJS in pass-by-ref compatibility mode. It wouldn't be a trivial change to make.
|
|
|
Post by bplus on Aug 18, 2023 18:09:19 GMT
'It wouldn't be a trivial change to make."
I understand huge undertakings like adding user defined subs and functions to one's esoteric interpreter just on the level of a tiny basic.
One is faced with very serious question: Are you just doing it for hobby ie for kicks or to accomplish something higher?
|
|
dbox
Junior Member
Posts: 89
|
Post by dbox on Aug 19, 2023 22:30:10 GMT
One is faced with very serious question: Are you just doing it for hobby ie for kicks or to accomplish something higher? That's a very interesting question bplus. I think the answer is both. It is a project I started for just for fun, to see how far I could take an idea. But I suppose I do now have somewhat higher goals for the project: Simply stated, I want to bring the fun and approachable nature of QBasic and make it available anywhere you can run a web browser. Back in the day the integrated QBasic IDE made it so easy to just start coding... no complicated setup, just make something fun. I want to replicate that experience online. I see QB64 as the natural successor to QBasic and was impressed its modern extensions for image graphics and cross platform nature. Ultimately, I'd like QBJS to support as many of the QBasic and QB64 keywords as is feasible. Then take it a bit further and allow developers to take advantage of the large number of powerful Javascript libraries that are available today, without having to learn Javascript. Finally, I want this to be a true open source project. Others have already submitted significant contributions to the project and it is open to whomever is interested to participate.
|
|
|
Post by bplus on Aug 27, 2023 15:45:04 GMT
bplus remember to comment out _ScreenMove to get QB64 working code to QBJS. One less distraction to adjusting the screen so that QBJS message that it is ignoring _ScreenMove is not posted.
Also use the Globe & page Icon for link of QBJS code and naming link to neat short blue line of text. Works in all ProBoards I think.
|
|
|
Post by bplus on Sept 1, 2023 17:56:03 GMT
No Shared key word in subs, best to Share on Global Level at start of main declarations section.
|
|
dbox
Junior Member
Posts: 89
|
Post by dbox on Sept 1, 2023 22:33:34 GMT
Both Static variables and Shared keyword in Subs will be supported in the next release. I've also implemented a "no-op" _ScreenMove so you can leave it in your code without an error message. That will also be in the next release.
|
|