Author Topic: Some info regarding $IF precompiler directives  (Read 2062 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Some info regarding $IF precompiler directives
« Reply #15 on: March 13, 2022, 02:32:58 pm »
OK thanks!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Some info regarding $IF precompiler directives
« Reply #16 on: March 13, 2022, 03:37:01 pm »
Ah Dav's number works better than Steve's but Steve pointed to right place. You guys tied :)

Works well now! (Windows only sorry PI guys)
Code: QB64: [Select]
  1. _Title " MessageBox test - look behind the QB64 app on tool bar if not seen on top. Lean on esc to quit... "
  2.  
  3. ' Thank you FellippeHeitor!
  4. $If WIN Then
  5.         Function MessageBox (ByVal ignore&, message$, title$, Byval type&)
  6.     End Declare
  7.     DECLARE LIBRARY ""
  8.     FUNCTION MessageBox (BYVAL ignore&, message$, title$, BYVAL type&)
  9.     END DECLARE
  10.  
  11. Const xmax = 800, ymax = 600, PI = 3.141592653589793
  12. Screen _NewImage(xmax, ymax, 32)
  13. _ScreenMove 300, 40
  14.  
  15.     Cls
  16.     drawLandscape
  17.     Color &HFFFFFFFF, &HFF000000
  18.     kind = 1 + 4096 ' 0 is just OK, 1 is OK & Cancel
  19.     Print "Warning a Modal Message Box may come up off screen, you program is waiting for that!."
  20.     answer = MessageBox(0, "You might have to look for me off screen. Lean on escape button to quit. Now you should quit seeing me with Cancel.", "Test MessageBox", kind)
  21.     Print answer
  22.  
  23.     'cant mess with first parameter?
  24.     _Delay 2
  25.     If answer = 2 Then End
  26.     k$ = InKey$ ' curious if key press in messageBox will interfere with inkey$
  27.     If k$ = "q" Then End
  28.     _Limit 1
  29.  
  30. Sub drawLandscape
  31.     'needs midInk, irnd
  32.  
  33.     Dim i As Long, startH As Single, rr As Long, gg As Long, bb As Long
  34.     Dim mountain As Long, Xright As Single, y As Single, upDown As Single, range As Single
  35.     Dim lastx As Single, X As Long
  36.     'the sky
  37.     For i = 0 To ymax
  38.         midInk 0, 0, 128, 128, 128, 200, i / ymax
  39.         Line (0, i)-(xmax, i)
  40.     Next
  41.     'the land
  42.     startH = ymax - 200
  43.     rr = 70: gg = 70: bb = 90
  44.     For mountain = 1 To 6
  45.         Xright = 0
  46.         y = startH
  47.         While Xright < xmax
  48.             ' upDown = local up / down over range, change along Y
  49.             ' range = how far up / down, along X
  50.             upDown = (Rnd * .8 - .35) * (mountain * .5)
  51.             range = Xright + irnd&(15, 25) * 2.5 / mountain
  52.             lastx = Xright - 1
  53.             For X = Xright To range
  54.                 y = y + upDown
  55.                 Color _RGB(rr, gg, bb)
  56.                 Line (lastx, y)-(X, ymax), , BF 'just lines weren't filling right
  57.                 lastx = X
  58.             Next
  59.             Xright = range
  60.         Wend
  61.         rr = irnd&(rr - 15, rr): gg = irnd&(gg - 15, gg): bb = irnd&(bb - 25, bb)
  62.         If rr < 0 Then rr = 0
  63.         If gg < 0 Then gg = 0
  64.         If bb < 0 Then bb = 0
  65.         startH = startH + irnd&(5, 20)
  66.     Next
  67.  
  68. Sub midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  69.     Color _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  70.  
  71. Function irnd& (n1, n2) 'return an integer between 2 numbers
  72.     Dim l%, h%
  73.     If n1 > n2 Then l% = n2: h% = n1 Else l% = n1: h% = n2
  74.     irnd& = Int(Rnd * (h% - l% + 1)) + l%
  75.  
  76.  
  77.