It being so diminutive, it is pretty awesome for embedding into anything, and setting it up as "view-only": go to settings, click on a check box, and save.
I'm interested in knowing if there might be a different way to recalculate Scientific Notation into a decimal value. Here is the method I'm presently using which works ok with Single dimension arrays/variables but when the resultant value is zero I've been going back are Redim to Double or whatever can get me a decimal value other than zero.
Code: (Select All)
' Removing Scientific Notation from a Variable/Array of Single dimension
Dim Shared Number, x, y
'In the main module will be a calculation which generates a Scientifically Notated value
Number = 115 / 123456
Print Number
x = 115
y = 123456
Number = SNrid
Print Number
Function SNrid
ScNote$ = Str$(x / y)
If InStr(1, ScNote$, "E") Or InStr(1, ScNote$, "D") Then
SNA = x / y
a = SNA * 10000000
b = a \ 1
C = a - b
If C >= .5 Then
b = b + 1
SNB = b * .0000001
End If
If C < .5 Then
SNB = b * .0000001
End If
SNrid = SNB
Exit Function
End If
SNrid = x / y
The small screen resolution when using the font causes an error for me - the program has stopped working and will be terminated. I am attaching the font used to test if it will behave the same on your systems. I understand that the screen height is set small, but if you are debugging a large program, this type of error will definitely be very annoying to deal with.
NOTE: Later down there's an updated version that is more optimized and does away with colons.
I present to you the game Mastermind, in 25 lines of code. Technically a little more because of
colons, but all the colons here are fine I think. For tiny little one-statement DO and FOR loops,
I find it's more readable like this; likewise for concatenating a handful of simple results of an
IF statement, to avoid a block IF...END IF. For much larger programs, it makes understanding
program flow much less convoluted, since my eyes have less nesting hierarchy to navigate.
Also, this code works in QBasic!
Code: (Select All)
do: input "How many possible letters (2-26)? ", code_colors%: loop while code_colors% < 2 or code_colors% > 26
do: input "How many letters long? ", code_length%: loop while code_length% < 1
dim match%(code_length%)
randomize timer
for n = 1 to code_length%: solution$ = solution$ + chr$(int(rnd * code_colors%) + asc("a")): next n
do
do: input "> ", attempt$: loop until len(attempt$) = code_length%
black_pegs% = 0: white_pegs% = 0
for n = 1 to code_length%
if mid$(attempt$, n, 1) <> mid$(solution$, n, 1) then match%(n) = 0 else match%(n) = n: black_pegs% = black_pegs% + 1
next n
for n = 1 to code_length%
if match%(n) = 0 then
for n1 = 1 to code_length%
if n1 <> n and mid$(attempt$, n, 1) = mid$(solution$, n1, 1) then
for n2 = 1 to code_length%
if match%(n2) <> n1 then m = 0 else m = -1: exit for ' Check for pre-existing white peg
next n2
if m = 0 then match%(n) = n1: white_pegs% = white_pegs% + 1: exit for
end if
next n1
end if
next n
print black_pegs%; "black,"; white_pegs%; "white"
loop while black_pegs% < code_length%
This operates exactly like Mastermind as you know it, except with lowercase letters instead of
colored pegs. You specify how many letters are possible, and how long the solution is. So, if
you say 12 possible letters and 4 letters long, the game will use the letters a through l, and
produce solutions such as "glhf" and "dljk." If you say 2 possible letters and 15 letters long,
it will produce things like "baabbbabaababba."
Guesses must be of the specified length, and must be in all lowercase. The game will signal
a correct letter in correct position with a "black peg," just like a typical Mastermind set,
and will signal a correct letter that is in the wrong position with a "white peg." For example,
if the solution is "hall," and you guess "hola," you will get two black pegs for the first h and
the third l, and one white peg for the a, which is not in the second position. If the solution
is "other," and you guess "trout," you will get three white pegs, not four, since the solution
only has one t.
Posted by: Petr - 03-25-2023, 04:01 PM - Forum: Petr
- Replies (52)
I'll say straight away that I literally only passed very light OpenGL. Still, I have a few absolutely basic things to post here.
The first program is completely primitive. Draws a triangle and a square in 2D, without texture.
Code: (Select All)
$Resize:On
Screen _NewImage(800, 600, 32)
Do While InKey$ <> Chr$(27)
_Limit 20
Loop
Sub _GL
_glViewport 0, 0, 800, 600
_glMatrixMode _GL_PROJECTION '// set projection matrix
_glLoadIdentity ' // Reset matrix
_gluPerspective 45.0F, 800 / 600, 0.1F, 100.0F ' claculate perspective
_glMatrixMode _GL_MODELVIEW ' set matrix _GL_MODELVIEW
_glLoadIdentity
_glShadeModel _GL_SMOOTH ' allow smooth shading
_glClearColor 0.0F, 0.0F, 0.0F, 0.5F
_glClearDepth 1.0F ' set depth buffer
_glEnable _GL_DEPTH_TEST ' allow depth testing
_glDepthFunc _GL_LEQUAL ' depth testing type
_glHint _GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ' set the best projection correction
_glClear _GL_COLOR_BUFFER_BIT: _glClear _GL_DEPTH_BUFFER_BIT 'clear screen and depth buffer
_glLoadIdentity ' matrix reset
' Sem kresli primitivy
_glTranslatef -1.5F, 0.0F, -6.0F 'Shift to the left and to the depth - be careful, every other shift on the screen moves from the place where we moved before!
_glBegin _GL_TRIANGLES ' Begin draw triangle
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point
_glVertex3f -1.0F, -1.0F, 0.0F ' left bottom point
_glVertex3f 1.0F, -1.0F, 0.0F ' right bottom point
_glEnd ' End draw triangle
_glTranslatef 3.0F, 0.0F, 0.0F ' we will move in the x-axis by 1.5 to the center and 1.5 to the right, where we will paint a square
_glBegin _GL_QUADS ' Square draw begin
_glVertex3f -1.0F, 1.0F, 0.0F ' left upper point
_glVertex3f 1.0F, 1.0F, 0.0F ' right upper point
_glVertex3f 1.0F, -1.0F, 0.0F ' right bottom point
_glVertex3f -1.0F, -1.0F, 0.0F ' left bottom point
_glEnd ' end draw square
End Sub
[size=1]182 / 5 000
[/size]
This source code shows how to draw a pyramid in color with blending colors on the walls, as well as how to draw a cube with walls of one color and how to rotate these objects.
Code: (Select All)
$Resize:On
Screen _NewImage(800, 600, 32) '
Dim Shared rquad As _Float: rquad = 7
Dim Shared rtri As _Float: rtri = 7
_glTranslatef -1.5F, 0.0F, -6.0F ' Shift to the left and to the depth - be careful, every other shift on the screen moves from the place where we moved before!
_glRotatef rtri, 0.0F, 1.0F, 0.0F ' Rotate the triangle around the y-axis
_glBegin _GL_TRIANGLES ' The beginning of drawing the PYRAMID
_glColor3f 1.0F, 0.0F, 0.0F ' Red color (it is as _glColor3f Red, Green, Blue and values can be calculated as 1 / 255)
_glVertex3f 0.0F, 1.0F, 0.0F ' Upper point
_glColor3f 0.0F, 1.0F, 0.0F ' Green color
_glVertex3f -1.0F, -1.0F, 1.0F ' left bottom point
_glColor3f 0.0F, 0.0F, 1.0F ' blue color
_glVertex3f 1.0F, -1.0F, 1.0F ' right bottom point
_glColor3f 1.0F, 0.0F, 0.0F ' red color
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (right wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue color
_glVertex3f 1.0F, -1.0F, 1.0F 'left point (right wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f 1.0F, -1.0F, -1.0F ' right point (right wall) '
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (rear wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f 1.0F, -1.0F, -1.0F ' left point (rear wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, -1.0F, -1.0F 'right point (rear wall)
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (back wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, -1.0F, -1.0F 'left point (left wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f -1.0F, -1.0F, 1.0F ' right point (left wall)
_glEnd 'triangle draw end
_glTranslatef 3.0F, 0.0F, 0.0F 'we will move in the x-axis by 1.5 to the center and 1.5 to the right, where we will paint a quad
'FOR THE ENTIRE OBJECT IN ONE COLOR:
_glLoadIdentity ' we call it to align the X Y Z axes to the original direction, without it it would default to the previous rotated state
_glTranslatef 1.5F, 0.0F, -7.0F ' The displacement of the origin is higher than in a quad
_glRotatef rquad, 1.0F, 1.0F, 1.0F 'Rotate the quad around the x-axis
_glBegin _GL_QUADS ' begin draw quad
_glColor3f 0.0F, 1.0F, 0.0F ' green color
_glVertex3f 1.0F, 1.0F, -1.0F ' left upper point
_glVertex3f -1.0F, 1.0F, -1.0F ' right upper point
_glVertex3f -1.0F, 1.0F, 1.0F ' right bottom point
_glVertex3f 1.0F, 1.0F, 1.0F ' left bottom point
_glColor3f 1.0F, 0.5F, 0.0F ' orange color
_glVertex3f 1.0F, -1.0F, 1.0F ' right upper point (bottom wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' left upper point (bottom wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left bottom point (bottom wall)
_glVertex3f 1.0F, -1.0F, -1.0F ' right bottm point (bottom wall)
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 1.0F, 1.0F, 1.0F ' right upper point (front wall)
_glVertex3f -1.0F, 1.0F, 1.0F ' Left upper point (front wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' left bottom point (front wall)
_glVertex3f 1.0F, -1.0F, 1.0F ' right bottom point (front wall)
_glColor3f 1.0F, 1.0F, 0.0F ' yellow
_glVertex3f 1.0F, -1.0F, -1.0F ' right upper point (rear wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left upper point (rear wall)
_glVertex3f -1.0F, 1.0F, -1.0F ' left bottom point (rear wall)
_glVertex3f 1.0F, 1.0F, -1.0F ' right bottom point (rear wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, 1.0F, 1.0F ' right upper point (left wall)
_glVertex3f -1.0F, 1.0F, -1.0F ' left upper point (left wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left bottom point (left wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' right bottom point (left wall)
_glColor3f 1.0F, 0.0F, 1.0F ' purple
_glVertex3f 1.0F, 1.0F, -1.0F ' right upper point (right wall)
_glVertex3f 1.0F, 1.0F, 1.0F ' left upper point (right wall)
_glVertex3f 1.0F, -1.0F, 1.0F 'Left bottom point (right wall)
_glVertex3f 1.0F, -1.0F, -1.0F 'Right bottom point (right wall)
_glEnd 'quad draw end
rtri = rtri + 0.52F 'Incrementing the angle of rotation of the triangle
rquad = rquad - 0.515F 'Incrementing the angle of rotation of the quad
'it is important to RESET THE AXES so that they are rotated to the basic setting (otherwise the X axis can move to the Y axis) using _glLoadIdentity,
'and it is EXTREMELY IMPORTANT to always move in the scene to the beginning of the scene using _glTranslateF
'moving the object in openGL is not done by recalculating _glVertex, but by moving the start of rendering using _glTranslatef
End Sub
Posted by: Petr - 03-25-2023, 02:21 PM - Forum: Petr
- No Replies
This is what happens when you have small children at home, they draw something and you show them that the drawing can be used in some way.
Program need H00H.gif file
Code: (Select All)
$NoPrefix
Title "Kids clock"
Dim Shared nrs(14) As Long
'DataCreate "hrsml.txt", "h00h.gif" - not used, is here for you - you can test it, it is way how find numbers to DATA lines in this program
LoadSubImages
Screen NewImage(1024, 768, 32)
CX = 500: CY = 350: A = -_Pi / 2 + _Pi(2) / 12
Circle (535, 419), 340, _RGB32(200)
Paint (535, 419), _RGB32(250), _RGB32(200)
For t = 0 To 11
Xv = CX + Cos(A) * 250
Yv = CY + Sin(A) * 250
A = A + _Pi(2) / 12
PutImage (Xv, Yv), nrs(t)
Next
PCopy Display, 1
Do Until k&
k& = KeyDown(27)
PCopy 1, Display
Mode = 1
Select Case Mode ' mode: 0 for standard STEPs mode, 1 for smooth steps.
Case 0
Hrs = Int(Timer / 3600)
If Hrs > 12 Then Hrs = Hrs - 12
Min = Int((Timer / 3600 - Hrs) * 60)
Secs = Int(Timer - (Hrs * 3600 + Min * 60))
Case 1
Hrs = Timer / 3600
Min = (Hrs - (Int(Timer / 3600))) * 60
Secs = Timer - (Int(Hrs) * 3600 + Int(Min) * 60)
End Select
For HrsSel = 1 To 3
Select Case HrsSel
Case 1 'hours
Asecs = _Pi(2) / 12 * Hrs - _Pi / 2
iW = 45: iH = 144: Handle = 13: L1 = 170
Case 2 'minutes
Asecs = _Pi(2) / 60 * Min - _Pi / 2
iW = 54: iH = 145: Handle = 14: L1 = 222
Case 3 'seconds
Asecs = _Pi(2) / 60 * Secs - _Pi / 2
iW = 61: iH = 143: Handle = 12: L1 = 200
End Select
Sub DataCreate (OutputFile As String, InputFile As String) 'this sub is not need for run, but is used between developing this program. This sub create DATA values for us.
img = LoadImage(InputFile$, 32)
img2 = CopyImage(img, 32)
ff = FreeFile
Open OutputFile$ For Output As #ff
Screen img
Do Until k&
k& = KeyDown(27)
While _MouseInput: Wend
MX = MouseX: MY = MouseY
MB1 = MouseButton(1)
MB2 = MouseButton(2)
If MB1 Then
Do Until MB1 = 0
PutImage , img2
Line (MX, MY)-(MouseX, MouseY), &HFF000000, B
While MouseInput: Wend
MB1 = MouseButton(1)
Limit 15
Loop
wMX = MX: wMY = MY: wMx2 = _MouseX: wMy2 = _MouseY
End If
If MB2 Then
If wMx2 Then
r$ = Str$(wMX) + ", " + Str$(wMY) + ", " + Str$(wMx2) + ", " + Str$(wMy2)
Print #ff, r$
wMx2 = 0
End If
End If
Loop
End Sub
Sub LoadSubImages
img = LoadImage("H00H.gif", 32)
For lsi = 0 To 14
Read x1, y1, x2, y2, i
wdth = x2 - x1: hght = y2 - y1
nrs(i) = _NewImage(wdth, hght, 32)
PutImage , img, nrs(i), (x1, y1)-(x2, y2)
SetAlpha 0, _RGB32(255) To _RGB32(200), nrs(i)
Next
FreeImage img
Data 0,4,62,148,12
Data 69,5,115,150,13
Data 118,7,172,153,14
Data 182,9,226,140,8
Data 226,10,310,134,9
Data 320,10,430,144,10
Data 435,11,522,132,11
Data 1,177,59,270,0
Data 64,171,130,260,1
Data 143,170,204,267,2
Data 211,168,280,269,3
Data 282,168,330,265,4
Data 332,167,401,272,5
Data 402,156,469,274,6
Data 474,157,518,265,7
End Sub
I tried using Inform 1.3 with QB64pe as I thought it should work. Well, sometimes it says include files are missing even though the editor says to click on it to open tht file! I change one of the include files to paste it. Well, that fixed that one. Then it points to a DECLARE LIIBRARY 'falcon' so I copy tie file falcon.h over. Still does not see it. So I comment out the DECLARE statement. That causes the complaint that a later declaratiion is illegal without a correspondind DELARE LIBRARY statement.
Sometimes I think this proram should be named Catch-22 instead.
Posted by: CharlieJV - 03-24-2023, 03:55 AM - Forum: Utilities
- No Replies
As part of some work I'm doing for a client, I'm setting up the client's applications with context-sensitive help using TiddlyWiki as the context-sensitive help engine.
A small wiki for creating and maintaining documentation is pretty fantastic in and of itself, but the bonus of having that single file doing a stellar job as context-sensitive help engine? It rocks something silly.
The one TiddlyWiki I've setup is to provide help for five applications, each application having a different set of users. Depending on the application that brings up the TiddlyWiki instance in a web browser, parameters are included in the URL to alter the appearance of the wiki so that it looks as if it is dedicated to the application that brought it up.
So if you ever want some context-sensitive help for your QB64pe, I highly recommend TiddlyWiki.
Just as an example, here's one TiddlyWiki instance that I've just setup with the ability to generate a link to a specific subject and topic for copying and pasting for sharing: https://basicanywheremachine.neocities.o...chine#Home
That link is much more complicated than normal when sharing a link to a specific wiki page, but that's because I've completely overridden the TiddlyWiki interface with a custom interface. So that it doesn't look like a wiki anymore.