| Welcome, Guest |
You have to register before you can post on our site.
|
| Forum Statistics |
» Members: 714
» Latest member: HenryG
» Forum threads: 3,569
» Forum posts: 31,909
Full Statistics
|
| Latest Threads |
QB64PE v 4.4.0
Forum: Announcements
Last Post: madscijr
4 hours ago
» Replies: 8
» Views: 680
|
4x4 Square Elimination Pu...
Forum: bplus
Last Post: bplus
8 hours ago
» Replies: 12
» Views: 413
|
Container Data Structure
Forum: Utilities
Last Post: bplus
8 hours ago
» Replies: 3
» Views: 131
|
Accretion Disk
Forum: Programs
Last Post: bplus
8 hours ago
» Replies: 11
» Views: 295
|
QBJS v0.10.0 - Release
Forum: QBJS, BAM, and Other BASICs
Last Post: Unseen Machine
Today, 04:14 AM
» Replies: 13
» Views: 1,300
|
Arrays inside Types?
Forum: General Discussion
Last Post: hsiangch_ong
Today, 03:24 AM
» Replies: 47
» Views: 1,444
|
Has anybody experience wi...
Forum: Help Me!
Last Post: Rudy M
Yesterday, 08:47 AM
» Replies: 31
» Views: 1,937
|
Sorting numbers - FiliSor...
Forum: Utilities
Last Post: PhilOfPerth
03-11-2026, 12:48 AM
» Replies: 11
» Views: 376
|
Quick Sort for variable l...
Forum: Utilities
Last Post: SMcNeill
03-10-2026, 03:14 PM
» Replies: 3
» Views: 107
|
Ready for Easter!
Forum: Holiday Code
Last Post: bplus
03-10-2026, 12:15 PM
» Replies: 0
» Views: 61
|
|
|
| Mouse Button Status (MBS) |
|
Posted by: SMcNeill - 04-23-2022, 05:05 PM - Forum: SMcNeill
- Replies (3)
|
 |
Code: (Select All) _Title "MBS (Mouse Button Status) by Steve" ' 12-17-2020 // updated 4/23/2022
Do
Cls
held$ = ""
result = MBS
left = left - (result And 8) \ 8
right = right - (result And 16) \ 16
middle = middle - (result And 32) \ 32
If result And 64 Then held$ = "Left held"
If result And 128 Then held$ = "Right held"
If result And 256 Then held$ = "Middle held"
If result And 512 Then scroll = scroll + 1
If result And 1024 Then scroll = scroll - 1
Print "MouseX: "; _MouseX
Print "MouseY: "; _MouseY
Print "Left down : "; result And 1
Print "Right down : "; result And 2
Print "Middle down : "; result And 4
Print "Left pressed : "; left
Print "Right pressed : "; right
Print "Middle pressed: "; middle
Print "Mouse Wheel Scrolled: "; scroll
Print
Print "Last held event started at X/Y :"; Mouse_StartX, Mouse_StartY
Print "Last held event ended at X/Y :"; Mouse_EndX, Mouse_EndY
Print held$
_Limit 60
Loop
Function MBS% 'Mouse Button Status
Static StartTimer As _Float
Static ButtonDown As Integer
Static ClickCount As Integer
Const ClickLimit## = 0.2 'Less than 1/4th of a second to down, up a key to count as a CLICK.
' Down longer counts as a HOLD event.
Shared Mouse_StartX, Mouse_StartY, Mouse_EndX, Mouse_EndY
While _MouseInput 'Remark out this block, if mouse main input/clear is going to be handled manually in main program.
Select Case Sgn(_MouseWheel)
Case 1: tempMBS = tempMBS Or 512
Case -1: tempMBS = tempMBS Or 1024
End Select
Wend
If _MouseButton(1) Then tempMBS = tempMBS Or 1
If _MouseButton(2) Then tempMBS = tempMBS Or 2
If _MouseButton(3) Then tempMBS = tempMBS Or 4
If StartTimer = 0 Then
If _MouseButton(1) Then 'If a button is pressed, start the timer to see what it does (click or hold)
ButtonDown = 1: StartTimer = Timer(0.01)
Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
ElseIf _MouseButton(2) Then
ButtonDown = 2: StartTimer = Timer(0.01)
Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
ElseIf _MouseButton(3) Then
ButtonDown = 3: StartTimer = Timer(0.01)
Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
End If
Else
BD = ButtonDown Mod 3
If BD = 0 Then BD = 3
If Timer(0.01) - StartTimer <= ClickLimit Then 'Button was down, then up, within time limit. It's a click
If _MouseButton(BD) = 0 Then tempMBS = 4 * 2 ^ ButtonDown: ButtonDown = 0: StartTimer = 0
Else
If _MouseButton(BD) = 0 Then 'hold event has now ended
tempMBS = 0: ButtonDown = 0: StartTimer = 0
Mouse_EndX = _MouseX: Mouse_EndY = _MouseY
Else 'We've now started the hold event
tempMBS = tempMBS Or 32 * 2 ^ ButtonDown
End If
End If
End If
MBS = tempMBS
End Function
I had one of these somewhere before, but I'll be danged if I can find it, so I rolled another one...
A simple routine to check the mouse buttons and to give us information on up/down, click, and hold statuses, as well as hold start/stop positions. Results are all stored in a single binary integer, and basically break down to:
1 -- left down
2 -- right down
4 -- middle down
8 -- left clicked
16 -- right clicked
32 -- middle clicked
64 -- left held
128 -- right held
256 -- middle held
512 -- scroll down
1024 -- scroll up
Starting X/Y and Ending X/Y positions are available in the shared Mouse_ variables.
Note, HOLD and CLICK events are independent of each other. We don't register a free click with each hold event. Windows tends to count first down events as clicks, so all hold events start with a click event and then transition into a hold event. I didn't need that for my purposes, so this will either give you a hold event OR a click event; not both.
|
|
|
| Tutorial - Turn a QB64 interpreter into a compiler |
|
Posted by: Dav - 04-23-2022, 03:55 PM - Forum: Dav
- Replies (3)
|
 |
Tutorial: How to turn a QB64 interpreter into a compiler.
(WINDOWS ONLY!)
Several of our members have made excellent interpreters in QB64 that run BAS code. I ported one of mine to QB64, and wanted to take it further and make it an compiler that turn BAS code in standalone EXE's. Here's a tutorial on how I did it. With this method you can make your own EXE producing compiler in QB64.
It's easier to explain the method by just going through the steps of making one, so in this tutorial we will turn a small interpreter into a EXE producing compiler. Please note - this is not a 'true' compiler, but more like a 'bytecode' one. The EXE's produced are merely a special interpreter with source coded binded to it - Like RapidQ and other basic compilers out there do. The EXE's will read itself and run the attached code. I've attached all the needed source files to this post at the bottom for easier saving. So...Download all the attached BAS files before we begin.
STEP #1) Compile the MarkExeSize.bas tool to an EXE first. The interpreter and compiler EXE's we make here will need to be marked by that tool. You can read what MarkExeSize does in its source code.
(MarkExeBas.bas)
Code: (Select All) '===============
'MarkExeSize.bas
'===============
'Marks QB64 compiled EXE's with its EXE data size.
'Coded by Dav, JAN/2021
'WINDOWS ONLY!
'This helps facilitate using appended data on the EXE.
'It saves the compiled EXE size to the EXE file, so
'the program can read that info and jump to its data.
'It does this by borrowing some space near the top of
'the EXE file. It shortens 'This program cannot be run
'in DOS mode.' to 'This program can't run in DOS mode.' and
'uses those 4 gained spaces to save EXE file size instead.
'=======================================================
'Example...after you mark your EXE file, it can do this:
'=======
'OPEN COMMAND$(0) FOR BINARY AS 1 'Open itself up...
'test$ = INPUT$(200, 1) 'grab a little info
'place = INSTR(1, test$, "This program can't") 'look for words
'IF place = 0 THEN PRINT "No data found.": CLOSE: END
'grab exesize info...
'SEEK 1, place + 35: ExeSize& = CVL(INPUT$(4, 1))
'Go there....
'SEEK 1, ExeSize& + 1 'where appended data begins
'=======================================================
'NOTE: Always mark the EXE before appending data to it.
' If you use EXE compressors, like UPX, mark the EXE
' AFTER using UPX, not before, otherwise the info won't
' be read correctly by your program.
SCREEN Pete
PRINT
PRINT "================"
PRINT "MarkExeSize v1.0 - by Dav"
PRINT "================"
PRINT
IF COMMAND$ = "" THEN
INPUT "EXE to Mark -->", exe$
PRINT
ELSE
exe$ = COMMAND$
END IF
IF exe$ = "" THEN END
IF NOT _FILEEXISTS(exe$) THEN
PRINT "File not found.": END
END IF
OPEN exe$ FOR BINARY AS 1
'find location of place to mark
test$ = INPUT$(200, 1)
place = INSTR(1, test$, "This program can")
IF place = 0 THEN
PRINT "This file is not markable."
CLOSE: END
END IF
'jump to location
SEEK 1, place
look$ = INPUT$(19, 1) 'grab a little info
SELECT CASE look$
CASE IS = "This program cannot"
'mark/overwrite exe file info file with new info
PRINT "Marking file "; exe$
PRINT
PRINT "EXE files size:"; LOF(1)
PRINT "Data start loc:"; LOF(1) + 1
new$ = "This program can't run in DOS mode." + MKL$(LOF(1))
PUT 1, place, new$
PRINT: PRINT "Done."
CASE IS = "This program can't "
PRINT "EXE already appears to be marked."
PRINT
SEEK 1, place + 35: datastart& = CVL(INPUT$(4, 1))
PRINT "EXE files size:"; LOF(1)
PRINT "Data start loc:"; datastart& + 1
PRINT "Size of data :"; LOF(1) - datastart&
CASE ELSE
PRINT "EXE is not markable."
END SELECT
CLOSE
STEP #2) Compile the sample interpreter.bas to EXE. This is just an example interpreter. The main thing is that this interpreter is made to open itself up when run, and load source code attached to itself, instead of loading an external BAS file. Think of it as the runtime file. But don't attach any BAS code to it yet, just compile it for now. (When using your own interpreter you will need to adapt it to load code this way too).
(interpreter.bas)
Code: (Select All) 'Mini Interpreter runtime.
'A compiled EXE of this runs BAS code attached to it.
DIM Code$(100) 'space for 100 lines
'==========================================================
OPEN COMMAND$(0) FOR BINARY AS 1
place = INSTR(1, INPUT$(200, 1), "This program can't")
IF place = 0 THEN
CLOSE: END
ELSE
SEEK 1, place + 35: ExeSize& = CVL(INPUT$(4, 1))
END IF
'==========================================================
'Make sure something is attached to exe...
IF ExeSize& + 1 > LOF(1) THEN END
SEEK 1, ExeSize& + 1
Lines = 1
WHILE NOT EOF(1)
LINE INPUT #1, c$
Code$(Lines) = c$
Lines = Lines + 1
WEND
CLOSE 1
FOR t = 1 TO Lines
ExecuteLine Code$(t)
NEXT
SUB ExecuteLine (cmd$)
cmd$ = LTRIM$(RTRIM$(cmd$))
IF LEFT$(cmd$, 1) = "'" THEN EXIT SUB
IF UCASE$(LEFT$(cmd$, 3)) = "REM" THEN EXIT SUB
IF UCASE$(LEFT$(cmd$, 5)) = "SLEEP" THEN SLEEP
IF UCASE$(cmd$) = "BEEP" THEN BEEP
IF UCASE$(LEFT$(cmd$, 6)) = "COLOR " THEN
COLOR VAL(RIGHT$(cmd$, LEN(cmd$) - 6))
END IF
IF UCASE$(cmd$) = "PRINT" THEN PRINT
IF UCASE$(LEFT$(cmd$, 7)) = "PRINT " + CHR$(34) THEN
PRINT MID$(cmd$, 8, LEN(cmd$) - 8)
END IF
IF UCASE$(LEFT$(cmd$, 3)) = "CLS" THEN CLS
IF UCASE$(LEFT$(cmd$, 3)) = "END" THEN END
END SUB
STEP #3) Compile the compiler.bas to EXE. This little programs whole job is to combine the interpreter+source code together. But - It will have the interpreter runtime attached to it eventually, like the interpreter has code attached to it. We will attach that later. For now just compile it...
(compiler.bas)
Code: (Select All) 'Mini Compiler example
PRINT
PRINT "A Mini .BAS Compiler"
PRINT "Compile .BAS to .EXE"
PRINT
INPUT "BAS to open ->", in$: IF in$ = "" THEN END
INPUT "EXE to make ->", out$: IF out$ = "" THEN END
'First see if this EXE is marked...
OPEN COMMAND$(0) FOR BINARY AS 1
place = INSTR(1, INPUT$(200, 1), "This program can't")
IF place = 0 THEN CLOSE: END
'Grab EXE size info
SEEK 1, place + 35: ExeSize& = CVL(INPUT$(4, 1))
'Make sure data attached...
IF ExeSize& + 1 > LOF(1) THEN END
'Jump to data
SEEK 1, ExeSize& + 1
'Extract data, make EXE file...
OPEN out$ FOR OUTPUT AS 2
outdata$ = INPUT$(LOF(1) - ExeSize&, 1)
PRINT #2, outdata$;: outdata$ = ""
'Add/attach BAS code to EXE
OPEN in$ FOR BINARY AS 3
outdata$ = INPUT$(LOF(3), 3)
PRINT #2, outdata$;
CLOSE
PRINT "Made "; out$
END
OPTIONAL STEP: At this point you could run UPX on those EXE's to reduce their size down to about 500k. You will have to download UPX from off the internet. I use it a lot. Works well on QB64 generated EXE's. Make sure if you do this step, that you do it right here - BEFORE using MarkExeSize on them.
STEP #4) Now use the MarkExeSize.exe tool on both the interpreter.exe and compiler.exe programs. It saves their EXE size in the EXE's. IMPORTANT: This is a needed step. Without it, the EXE's won't know how to open a file attached to them.
STEP #5) Now it's time to make the mini.exe compiler program. Drop to a command prompt, into the folder where the new EXE's are, and combine both the compiler.exe+interpreter.exe files like this, making a new file called mini.exe:
copy /b compiler.exe+interpreter.exe mini.exe
If all went well, You just made a new EXE file called mini.exe. It's the whole compiler that contains the interpreter runtime too. Run mini.exe, and you can now compile the demo.bas below. It will generate a demo.exe out of it. The interpreter.exe & compiler.exe are no longer needed - mini.exe is the only thing needed to make the EXE files from BAS code.
(demo.bas)
Code: (Select All) REM Sample program
COLOR 3
PRINT "Hit any key to clear..."
SLEEP
BEEP
CLS
COLOR 15
PRINT "Cleared!"
END
Final comments: The example here is just a simple interpreter, just to show you how to do yours. Be aware that unless you encode/decode your source code on the interpreter, people will be able to open up your EXE and see the source code, so I would put in an encoding/decoding method in your interpreter.
Try building this sample first, and you will see how easy it is to turn your interpreter into a byte-code compiler using QB64. Start your own programming language!
Have fun!
- Dav
markexesize.bas (Size: 2.64 KB / Downloads: 282)
interpreter.bas (Size: 1.3 KB / Downloads: 257)
compiler.bas (Size: 829 bytes / Downloads: 260)
demo.bas (Size: 113 bytes / Downloads: 251)
|
|
|
| TextToImage and DisplayImage |
|
Posted by: SMcNeill - 04-23-2022, 02:02 PM - Forum: SMcNeill
- Replies (9)
|
 |
Code: (Select All) SCREEN _NEWIMAGE(800, 700, 32)
_SCREENMOVE 250, 0
FOR i = 1 TO 4
HW(i) = TextToImage("Hello World", 16, &HFFFFFF00, 0, i)
NEXT
CLS
PRINT "The first thing to showcase with these two routines is just how simple it is to turn"
PRINT "text into an image with TextToImage."
SLEEP
PRINT
PRINT "First, let's print it forwards:"
_PUTIMAGE (250, 48), HW(1)
SLEEP
PRINT
PRINT "Then, let's print it backwards:"
_PUTIMAGE (250, 80), HW(2)
SLEEP
PRINT
PRINT "Then, let's print it up to down:"
_PUTIMAGE (270, 112), HW(3)
SLEEP
LOCATE 8, 40: PRINT "And let's finish with down to up:"
_PUTIMAGE (580, 112), HW(4)
SLEEP
LOCATE 20, 1
PRINT
PRINT
PRINT "TextToImage simply transforms text into an image for us, with a few built in options"
PRINT "to it for the direction we want we text to print."
PRINT "It's as simple as a call with:"
PRINT " Handle = TextToImage(text$, fonthandle, fontcolor, backgroundcolor, mode"
PRINT
PRINT " text$ is the string which we want to print. (In this case 'Hello World'"
PRINT " fonthandle is the handle of the font which we _LOADFONT for use."
PRINT " (In this case, I choose the default _FONT 16.)"
PRINT " fontcolor is the color which we want our text in. (Here, it's YELLOW.)"
PRINT " backgroundcolor is the background which we want for the text time. (Clear this time.)"
PRINT " mode is how we decide to print forwards, backwards, up to down, or down to up."
PRINT
PRINT "Once we have an image handle, we can use that image just the same as we can with any other."
PRINT "For those who don't need to do anything more than display the text as an image,"
PRINT "feel free to use it as I have in the first part of this program with _PUTIMAGE."
PRINT
PRINT "Trust me -- TextToImage works just fine with _PUTIMAGE."
PRINT
PRINT "But.... If you need more..."
SLEEP
CLS , 0
PRINT "There's always DisplayImage to help you out!"
DisplayImage HW(1), 300, 30, 1, 1, 0, 1
PRINT
PRINT "Display your image at a scale!"
SLEEP
PRINT
PRINT "Twice as wide! ";
DisplayImage HW(1), 300, 60, 2, 1, 0, 1
SLEEP
PRINT "Twice as tall! "
DisplayImage HW(1), 500, 60, 1, 2, 0, 1
SLEEP
PRINT
PRINT "At an angle!"
DisplayImage HW(1), 280, 90, 1, 1, -45, 1
SLEEP
PRINT: PRINT: PRINT: PRINT: PRINT
PRINT "Make it rotate!"
_DELAY .2
_KEYCLEAR
DO
LINE (355, 155)-STEP(100, 100), &HFF000000, BF
DisplayImage HW(1), 400, 200, 1, 1, angle, 0
angle = (angle + 1) MOD 360
_LIMIT 30
_DISPLAY
LOOP UNTIL _KEYHIT
_AUTODISPLAY
PRINT
PRINT
PRINT
PRINT
PRINT "You can basically use DisplayImage just as you'd normally use RotoZoom, EXCEPT..."
SLEEP
PRINT "You can choose which CORNER of the image you want to display at your coordinates."
PRINT
LINE (350, 350)-STEP(100, 100), -1, B
CIRCLE (400, 400), 10, -1
SLEEP
PRINT "Top Left corner! ";
DisplayImage HW(1), 400, 400, 2, 2, 0, 1
SLEEP
PRINT "Bottom Left corner! ";
DisplayImage HW(1), 400, 400, 2, 2, 0, 2
SLEEP
PRINT "Top Right corner! ";
DisplayImage HW(1), 400, 400, 2, 2, 0, 3
SLEEP
PRINT "Bottom Right corner! "
DisplayImage HW(1), 400, 400, 2, 2, 0, 4
SLEEP
_FREEIMAGE HW(1)
HW(1) = TextToImage("Hello World", 16, &HFFFF0000, &HFF0000FF, 1)
PRINT "Or Centered!"
DisplayImage HW(1), 400, 400, 2, 2, 0, 0
CIRCLE (400, 400), 10, -1
SLEEP
CLS
PRINT "With TextToImage, you can turn text into an image... It's that simple!"
PRINT
PRINT "With DisplayImage, you have a ton of options for how to display ANY image"
PRINT " (NOT just for use with text images!!)"
PRINT
PRINT "Scale them, stretch them, rotate them, position them by various corners..."
PRINT
PRINT "Between these two routines, I generally don't need anything else when working"
PRINT " with images in my programs. ;)"
PRINT
PRINT
PRINT "And that's THE END of this demo. Post any questions you have on the forums for me!"
' (Image As Long, x As Integer, y As Integer, xscale As Single, yscale As Single,
' angle As Single, mode As _Byte)
FUNCTION TextToImage& (text$, font&, fc&, bfc&, mode AS _BYTE)
'text$ is the text that we wish to transform into an image.
'font& is the handle of the font we want to use.
'fc& is the color of the font we want to use.
'bfc& is the background color of the font.
'Mode 1 is print forwards
'Mode 2 is print backwards
'Mode 3 is print from top to bottom
'Mode 4 is print from bottom up
'Mode 0 got lost somewhere, but it's OK. We check to see if our mode is < 1 or > 4 and compensate automatically if it is to make it one (default).
IF mode < 1 OR mode > 4 THEN mode = 1
dc& = _DEFAULTCOLOR: bgc& = _BACKGROUNDCOLOR
D = _DEST
F = _FONT
T2Idown = CSRLIN: T2Iright = POS(0)
IF font& <> 0 THEN _FONT font&
IF mode < 3 THEN
'print the text lengthwise
w& = _PRINTWIDTH(text$): h& = _FONTHEIGHT
ELSE
'print the text vertically
FOR i = 1 TO LEN(text$)
IF w& < _PRINTWIDTH(MID$(text$, i, 1)) THEN w& = _PRINTWIDTH(MID$(text$, i, 1))
NEXT
h& = _FONTHEIGHT * (LEN(text$))
END IF
TextToImage_temp& = _NEWIMAGE(w&, h&, 32)
TextToImage = TextToImage_temp&
_DEST TextToImage_temp&
IF font& <> 0 THEN _FONT font&
COLOR fc&, bfc&
SELECT CASE mode
CASE 1
'Print text forward
_PRINTSTRING (0, 0), text$
CASE 2
'Print text backwards
temp$ = ""
FOR i = 0 TO LEN(text$) - 1
temp$ = temp$ + MID$(text$, LEN(text$) - i, 1)
NEXT
_PRINTSTRING (0, 0), temp$
CASE 3
'Print text upwards
'first lets reverse the text, so it's easy to place
temp$ = ""
FOR i = 0 TO LEN(text$) - 1
temp$ = temp$ + MID$(text$, LEN(text$) - i, 1)
NEXT
'then put it where it belongs
FOR i = 1 TO LEN(text$)
fx = (w& - _PRINTWIDTH(MID$(temp$, i, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better
_PRINTSTRING (fx, _FONTHEIGHT * (i - 1)), MID$(temp$, i, 1)
NEXT
CASE 4
'Print text downwards
FOR i = 1 TO LEN(text$)
fx = (w& - _PRINTWIDTH(MID$(text$, i, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better
_PRINTSTRING (fx, _FONTHEIGHT * (i - 1)), MID$(text$, i, 1)
NEXT
END SELECT
_DEST D
COLOR dc&, bgc&
_FONT F
LOCATE T2Idown, T2Iright
END FUNCTION
SUB DisplayImage (Image AS LONG, x AS INTEGER, y AS INTEGER, xscale AS SINGLE, yscale AS SINGLE, angle AS SINGLE, mode AS _BYTE)
'Image is the image handle which we use to reference our image.
'x,y is the X/Y coordinates where we want the image to be at on the screen.
'angle is the angle which we wish to rotate the image.
'mode determines HOW we place the image at point X,Y.
'Mode 0 we center the image at point X,Y
'Mode 1 we place the Top Left corner of oour image at point X,Y
'Mode 2 is Bottom Left
'Mode 3 is Top Right
'Mode 4 is Bottom Right
DIM AS INTEGER px(3), py(3), w, h, w1, h1
DIM sinr AS SINGLE, cosr AS SINGLE, i AS _BYTE
w = _WIDTH(Image): h = _HEIGHT(Image)
w1 = w * xscale: h1 = h * yscale
SELECT CASE mode
CASE 0 'center
px(0) = -w1 / 2: py(0) = -h1 / 2: px(3) = w1 / 2: py(3) = -h1 / 2
px(1) = -w1 / 2: py(1) = h1 / 2: px(2) = w1 / 2: py(2) = h1 / 2
CASE 1 'top left
px(0) = 0: py(0) = 0: px(3) = w1: py(3) = 0
px(1) = 0: py(1) = h1: px(2) = w1: py(2) = h1
CASE 2 'bottom left
px(0) = 0: py(0) = -h1: px(3) = w1: py(3) = -h1
px(1) = 0: py(1) = 0: px(2) = w1: py(2) = 0
CASE 3 'top right
px(0) = -w1: py(0) = 0: px(3) = 0: py(3) = 0
px(1) = -w1: py(1) = h1: px(2) = 0: py(2) = h1
CASE 4 'bottom right
px(0) = -w1: py(0) = -h1: px(3) = 0: py(3) = -h1
px(1) = -w1: py(1) = 0: px(2) = 0: py(2) = 0
END SELECT
sinr = SIN(angle / 57.2957795131): cosr = COS(angle / 57.2957795131)
FOR i = 0 TO 3
x2 = (px(i) * cosr + sinr * py(i)) + x: y2 = (py(i) * cosr - px(i) * sinr) + y
px(i) = x2: py(i) = y2
NEXT
_MAPTRIANGLE (0, 0)-(0, h - 1)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
_MAPTRIANGLE (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB
|
|
|
| Powershell Text To Speech |
|
Posted by: SMcNeill - 04-23-2022, 01:55 PM - Forum: SMcNeill
- Replies (3)
|
 |
Code: (Select All) _Title "Steve's Powershell Speech Script"
SaP "Hello World. This is a normal speed demo of David's voice", "David", 0
_Delay 2
SaP "Hello again. This is a normal speed demo of Ziva's voice.", "Ziva", 0
_Delay 2
SaP "And now I'm speaking as David, but I'm speaking veeery slow.", "David", -10
_Delay 2
SaP "And now I'm a very hyper Ziva!", "Ziva", 5
_Delay 2
SaP "And now I'm done with my demo!", "", 0
Sub SaP (text$, who$, speed)
Print text$
If UCase$(who$) = "ZIVA" Then Speaker = 1
speak text$, Speaker, speed
End Sub
Sub speak (text As String, Speaker As Integer, Speed)
Dim message As String
message = text
'some symbols and such can't be used with Powershell like this, as they're command symbols
'we need to strip them out of our text. (Like apostrophes!)
remove$ = "'" + Chr$(34) 'add to remove$ here, if more symbols need to be removed as future testing showcases problems
For j = 1 To Len(remove$)
Do
i = InStr(message, Mid$(remove$, j, 1))
If i Then message = Left$(message, i - 1) + Mid$(message, i + 1)
Loop Until i = 0
Next
out$ = "Powershell -Command " + Chr$(34)
out$ = out$ + "Add-Type -AssemblyName System.Speech; "
out$ = out$ + "$Speech = New-Object System.Speech.Synthesis.SpeechSynthesizer; "
If Speaker = 0 Then out$ = out$ + "$Speech.SelectVoice('Microsoft David Desktop'); "
If Speaker = 1 Then out$ = out$ + "$Speech.SelectVoice('Microsoft Zira Desktop'); "
If Speed Then out$ = out$ + "$Speech.Rate =" + Str$(Speed) + "; "
out$ = out$ + "$Speech.Speak('" + message + "');" + Chr$(34)
Shell _Hide out$
End Sub
|
|
|
| qb64.org forum archive |
|
Posted by: luke - 04-23-2022, 01:20 PM - Forum: General Discussion
- Replies (16)
|
 |
Since the qb64.org forum has ceased to exist I have deployed a copy of it at https://qb64forum.alephc.xyz from the data I have locally from January when the site moved servers. I expect to keep it there mostly indefinitely, but I make no promises. Feel free to clone it with httrack or similar, but please be gentle to the machine.
This is intended to be an archival copy, so registration and login is disabled.
|
|
|
| CONTENTS (Categories with links) |
|
Posted by: Dav - 04-23-2022, 02:44 AM - Forum: Dav
- No Replies
|
 |
Welcome to...
Dav's QB64 Corner
Click on links below to easily find my QB64 programs.
FUNCTIONS & SUBS
FileSelect - Simple to use file selector popup box
PPRINT - SUB to easily print larger text on screen.
CP437FONT - Easily provide re-sizable CP437 font to use.
GAMES & PUZZLES
10x10 - Addictive line puzzle game (woody clone)
FindTheBall - Classic cup/shell game where you find the ball.
GridWars - Strategy Board game with AI Play.
Make5 - Board clearing puzzle game.
MazeBall - A 'tilt' like maze puzzle game.
RoCoLoco - Row & Column math puzzle game.
Tents - QB64 version of popular 'Tents & Trees' puzzle game.
TriPegs - Classic wooden triangle peg jumping puzzle.
JackStack - Stacking jack-o-lanterns Halloween game.
GRAPHICS, DEMOS & SCREEN SAVERS
Coming soon...
SOUND & MUSIC
KEYS48 - 48 note piano to play and record songs with
MemWave - Play WAV from string memory, not external file (WINDOWS ONLY)
TANKDRUM - Virtual tankdrum instrument to play and record
TUTORIALS
UTILITIES & TOOLS
BASFILE - Converts small files into BAS code
BASIMAGE - Put image files in you BAS code to use with _PUTIMAGE
BASFONT - Turns a FONT into BAS code SUB for using in your programs.
DavsIDE - An Alternative IDE for the QB64 compiler
XE - Simple file viewer & editor
|
|
|
|