Author Topic: Problem to print values on the axis inside and outside WINDOW.  (Read 5119 times)

0 Members and 1 Guest are viewing this topic.

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Problem to print values on the axis inside and outside WINDOW.
« on: February 20, 2021, 05:56:41 am »
Hi,
I have a problem and I don't find a solution.
Launching the code, press 1 or 2, and then any key at time.
In the ordinate is drawn a notch every X mc/s.

Given this notch, the target is to print the corresponding value on the axis. The problem is just to print it in the right position.
In the code below, we have to see the subroutine "grafici": lines 302 to 385, but the core of the problem is in lines 365 (inside the command WINDOW) and 374 (outside).

I have thought to print the value with che command _PRINTSTRING. At the moment there is no value, but the string "-". _PRINTSTRING, unfortunately, doesn't use the local coordinates of WINDOW (line 333), but always the general coordinates in pixels of the screen in use (line 331). So, in order to use _PRINTSTRING, the idea was to transform (line 365 and 374) the general coordinates of _PRINTSTRING, into the local coordinates of WINDOW by using fx! and fy!: lines 323-328.

But, as we can see launching the code, there is no way in order to have the strings "-" to fit and match the notches, also introducing a parameter k! (line 362) to do so. In any way, the strings "-" are ot of phase with the notches. The solution is not to use double precision variables for the transformation between coordinates.

So how we can print the values on the axis? I never thought that the problem was this!

Code: QB64: [Select]
  1.  
  2. mockus: 'dati dell'idrogramma unitario di Mockus
  3. DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  4. DATA 0.030,0.100,0.190,0.310,0.470,0.660,0.820,0.930,0.990,1.000,0.990,0.930,0.860,0.780,0.680,0.560,0.460,0.390,0.330,0.280,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.040,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0.000: ' t/tp
  5.  
  6. coefficienti:
  7. DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32: 'N volte tc!.
  8. DATA 0.1,0.1,0.1,0.2,0.3,0.2,0.3,0.3,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,1,1,1,1,1,1,1: 'discretizzazione dei coeff. di Mockus.
  9.  
  10. TYPE mockus
  11.     MOCKUStSUta AS SINGLE
  12.     MOCKUSqSUqp AS SINGLE
  13.  
  14. TYPE matrice1
  15.     m AS INTEGER '[numero naturale] conta il numero di interazioni fino al raggiungimento di "d".
  16.     mdt AS SINGLE '[ore] conta la progessione delle ore fino al raggiungimento di "d".
  17.     tminuti AS SINGLE '[minuti] trasforma mdt in minuti.
  18.     h1 AS SINGLE '[mm] valore h della curva di possibilità climatica.
  19.     i1 AS SINGLE '[mm/ora] intensità di pioggia.
  20.     i2 AS SINGLE '[mm/ora] intensità di pioggia secondo lo ietogramma Chicago o costante.
  21.     DH AS SINGLE '[mm] pioggia in ogni istante temporale dt.
  22.     H2 AS SINGLE '[mm] pioggia cumulata ad ogni istante temporale.
  23.     he AS SINGLE '[mm] piggia efficace cumulata ad ogni istante temporale.
  24.     Dhe AS SINGLE '[mm] pioggia efficace ad ogni istante temporale.
  25.     MOCKUStSUta AS SINGLE
  26.     MOCKUSqSUqp AS SINGLE
  27.     tmSUta AS SINGLE '[-].
  28.     qmSUqp AS SINGLE '[-] il valore di qm/qp corrispondente a tm/ta e' = al valore di q/qp che corrisponde a t/ta=tm/ta.
  29.     qm AS SINGLE '[mc/s].
  30.  
  31. TYPE coefficienti
  32.     d AS SINGLE
  33.     tSUta AS SINGLE
  34.  
  35. TYPE idrogramma
  36.     ore AS SINGLE
  37.     minuti AS SINGLE
  38.     portata AS SINGLE
  39.  
  40. CONST limit = 200 '50
  41.  
  42. DIM schermo&
  43.  
  44. DIM SHARED mockus(50) AS mockus
  45. DIM SHARED dt!(2, 24)
  46. DIM SHARED matrice1(2, 24, 50, 1) AS matrice1
  47. DIM SHARED coefficienti(24) AS coefficienti
  48. DIM SHARED matrice2!(2, 24, 50, 50)
  49. DIM SHARED idrogramma(2, 24, 50, 1) AS idrogramma
  50. DIM SHARED massimi1(2, 24, 1) AS idrogramma
  51. DIM SHARED massimi2(2) AS idrogramma
  52. DIM SHARED i%, n%, z%, ieto%
  53. DIM SHARED m%(2, 24)
  54. DIM SHARED S2! '[mm] contenuto idrico massimo del terreno.
  55. DIM SHARED Ia! '[mm] perdite iniziali.
  56. DIM SHARED tc! '[ore] tempo di corrivazione
  57. DIM SHARED ta! '[ore] tempo di picco.
  58. DIM SHARED qp! '[mc/s] portata al colmo dell'idrogramma unitario.
  59. DIM SHARED k! '[-] coeff. della curva di possibilità climatica tado dal sito della Regione.
  60. DIM SHARED a2! '[mm/d^n] coeff. della curva di possibilità climatica.
  61. DIM SHARED n1! '[-] coeff. della curva di possibilità climatica.
  62. DIM SHARED visualizzaieto%
  63. DIM A1! '[mq] superficie bacino idrografico.
  64. DIM L! '[m] lunghezza asta principale.
  65. DIM HmaxL! '[m] punto più alto dell'astra principale.
  66. DIM HminL! '[m] punto più basso dell'asta principale.
  67. DIM s1! '[-] pendenza media del bacino non espressa in percentuale ma come 0,x.
  68. DIM CNII! '[-] tabellato.
  69. DIM CNIII '[-] discende da CNII.
  70. DIM tl! '[ore] tempo di ritardo.
  71. DIM keypress$
  72.  
  73. SCREEN schermo&
  74.  
  75. A1! = 2641902
  76. k! = 2.34
  77. a2! = 14.6653
  78. n1! = 0.45596
  79. L! = 3300
  80. HmaxL! = 1981
  81. HminL! = 1062
  82. s1! = 0.415
  83. CNII! = 70
  84.  
  85. 'INPUT A1!
  86. 'INPUT k!
  87. 'INPUT a2!
  88. 'INPUT n1!
  89. 'INPUT L!
  90. 'INPUT HmaxL!
  91. 'INPUT HminL!
  92. 'INPUT s1!
  93. 'INPUT CNII!
  94. 'INPUT d1!
  95.  
  96. CNIII! = (23 * CNII!) / (10 + 0.13 * CNII!)
  97. tl! = 0.342 * ((L! / 1000) ^ 0.8 / (100 * s1!) ^ 0.5) * (1000 / CNIII! - 9) ^ 0.7 'formula di Mockus.
  98. S2! = 25.4 * (1000 / CNIII! - 10)
  99. Ia! = 0.1 * S2! 'coeff.=0.03-0.2.
  100. tc! = tl! / 0.6
  101. ta! = tl! / 0.9
  102. qp! = 0.208 * ((A1! / 1000000) / ta!)
  103.  
  104. RESTORE mockus
  105. FOR i% = 1 TO 100
  106.     IF i% <= 50 THEN READ mockus(i%).MOCKUStSUta
  107.     IF i% > 50 THEN READ mockus(i% - 50).MOCKUSqSUqp
  108. NEXT i%
  109.  
  110. RESTORE coefficienti
  111. FOR i% = 1 TO 48
  112.     IF i% <= 24 THEN READ coefficienti(i%).d: coefficienti(i%).d = coefficienti(i%).d * tc!
  113.     IF i% > 24 THEN READ coefficienti(i% - 24).tSUta
  114. NEXT i%
  115.  
  116. PRINT "Ietogramma Chicago/costante: 1/2> "
  117.     _LIMIT 60 'limit
  118.     keypress$ = INKEY$
  119. LOOP UNTIL keypress$ = "1" OR keypress$ = "2"
  120. visualizzaieto% = VAL(keypress$)
  121.  
  122. FOR ieto% = 1 TO 2
  123.     CALL creamatrici
  124. NEXT ieto%
  125.  
  126. CALL grafici(massimi1(visualizzaieto%, 24, 1).ore, massimi2(visualizzaieto%).ore, massimi2(visualizzaieto%).portata) 'valori passati per disegnare il grafico.
  127.  
  128. 'CALL risultati
  129.  
  130. '-----------------------------------------matrice1---------------------------------------------------------------------------------------------------------------------------------
  131. SUB creamatrici ()
  132.     z% = 0
  133.     DO
  134.         z% = z% + 1
  135.         dt!(ieto%, z%) = coefficienti(z%).tSUta * ta!
  136.         m%(ieto%, z%) = coefficienti(z%).d / (coefficienti(z%).tSUta * ta!) 'determina il numero di passi temporali necessari ad arrivare allla durata d considerata con il paso temporale dt!.
  137.         FOR i% = 1 TO 50
  138.             matrice1(ieto%, z%, i%, 1).MOCKUStSUta = mockus(i%).MOCKUStSUta
  139.             matrice1(ieto%, z%, i%, 1).MOCKUSqSUqp = mockus(i%).MOCKUSqSUqp
  140.             matrice1(ieto%, z%, i%, 1).m = i%
  141.             matrice1(ieto%, z%, i%, 1).mdt = matrice1(ieto%, z%, i%, 1).m * dt!(ieto%, z%)
  142.             matrice1(ieto%, z%, i%, 1).tminuti = matrice1(ieto%, z%, i%, 1).mdt * 60
  143.             SELECT CASE (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 'crea il vettore dell'idrogramma unitario di Mockus con i multipli del coeff. z% considerato (0.1,0.2,0.3,0.5,1).
  144.                 CASE IS <= 5 'valore massimo di t/ta di Mockus
  145.                     matrice1(ieto%, z%, i%, 1).tmSUta = (_ROUND(10 * (i% * coefficienti(z%).tSUta))) / 10 '=matrice1(i%).m *  matrice1(i%).mdt / ta!
  146.                 CASE ELSE
  147.                     matrice1(ieto%, z%, i%, 1).tmSUta = 0
  148.             END SELECT
  149.         NEXT i%
  150.         FOR i% = 1 TO 50
  151.             n% = 1
  152.             DO 'crea il vettore dell'idrogramma unitario Mockus prendendo i valori corrispondenti di ai coefficienti.
  153.                 IF matrice1(ieto%, z%, i%, 1).tmSUta = matrice1(ieto%, z%, n%, 1).MOCKUStSUta THEN
  154.                     matrice1(ieto%, z%, i%, 1).qmSUqp = matrice1(ieto%, z%, n%, 1).MOCKUSqSUqp
  155.                     EXIT DO
  156.                 ELSE
  157.                     n% = n% + 1
  158.                 END IF
  159.             LOOP UNTIL n% = 50
  160.             matrice1(ieto%, z%, i%, 1).qm = matrice1(ieto%, z%, i%, 1).qmSUqp * qp!
  161.         NEXT i%
  162.         FOR i% = 1 TO m%(ieto%, z%)
  163.             matrice1(ieto%, z%, i%, 1).h1 = k! * a2! * matrice1(ieto%, z%, i%, 1).mdt ^ n1!
  164.             IF i% = 1 THEN
  165.                 matrice1(ieto%, z%, i%, 1).i1 = matrice1(ieto%, z%, i%, 1).h1 / dt!(ieto%, z%)
  166.             ELSE
  167.                 matrice1(ieto%, z%, i%, 1).i1 = (matrice1(ieto%, z%, i%, 1).h1 - matrice1(ieto%, z%, i% - 1, 1).h1) / dt!(ieto%, z%)
  168.             END IF
  169.         NEXT i%
  170.         SELECT CASE ieto%
  171.             CASE 1 'Chicago.
  172.                 CALL chicago
  173.             CASE 2 'costante
  174.                 FOR i% = 1 TO m%(ieto%, z%)
  175.                     matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z%, m%(ieto%, z%), 1).h1 / matrice1(ieto%, z%, m%(ieto%, z%), 1).mdt
  176.                 NEXT i%
  177.         END SELECT
  178.         FOR i% = 1 TO m%(ieto%, z%)
  179.             matrice1(ieto%, z%, i%, 1).DH = matrice1(ieto%, z%, i%, 1).i2 * dt!(ieto%, z%)
  180.             IF i% = 1 THEN
  181.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH
  182.             ELSE
  183.                 matrice1(ieto%, z%, i%, 1).H2 = matrice1(ieto%, z%, i%, 1).DH + matrice1(ieto%, z%, i% - 1, 1).H2
  184.             END IF
  185.             SELECT CASE matrice1(ieto%, z%, i%, 1).H2 - Ia!
  186.                 CASE IS < 0
  187.                     matrice1(ieto%, z%, i%, 1).he = 0
  188.                 CASE IS >= 0
  189.                     matrice1(ieto%, z%, i%, 1).he = (matrice1(ieto%, z%, i%, 1).H2 - Ia!) ^ 2 / (matrice1(ieto%, z%, i%, 1).H2 - Ia! + S2!)
  190.             END SELECT
  191.             IF i% = 1 THEN
  192.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he
  193.             ELSE
  194.                 matrice1(ieto%, z%, i%, 1).Dhe = matrice1(ieto%, z%, i%, 1).he - matrice1(ieto%, z%, i% - 1, 1).he
  195.             END IF
  196.         NEXT i%
  197.  
  198.         '-------------------------------matrice2-------------------------------------------------------------------------------------------------------------------------
  199.  
  200.         FOR n% = 1 TO 50 'colonna
  201.             FOR i% = n% TO 50 ' riga
  202.                 matrice2!(ieto%, z%, i%, n%) = matrice1(ieto%, z%, i% - n% + 1, 1).Dhe * matrice1(ieto%, z%, n%, 1).qm
  203.             NEXT i%
  204.         NEXT n%
  205.         '-------------------------------idrogramma------------------------------------------------------------------------------------------------------------------
  206.         FOR i% = 1 TO 50 'riga
  207.             FOR n% = 1 TO 50 'colonna
  208.                 idrogramma(ieto%, z%, i%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata + matrice2!(ieto%, z%, i%, n%)
  209.  
  210.             NEXT n%
  211.             idrogramma(ieto%, z%, i%, 1).ore = matrice1(ieto%, z%, i%, 1).mdt
  212.             idrogramma(ieto%, z%, i%, 1).minuti = matrice1(ieto%, z%, i%, 1).tminuti
  213.         NEXT i%
  214.         '-------------------------------Massimi-----------------------------------------------------
  215.         i% = 1
  216.         'massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, 1, 1).portata
  217.         DO
  218.             IF massimi1(ieto%, z%, 1).portata < idrogramma(ieto%, z%, i%, 1).portata THEN
  219.                 massimi1(ieto%, z%, 1).portata = idrogramma(ieto%, z%, i%, 1).portata
  220.                 massimi1(ieto%, z%, 1).ore = idrogramma(ieto%, z%, i%, 1).ore
  221.                 massimi1(ieto%, z%, 1).minuti = idrogramma(ieto%, z%, i%, 1).minuti
  222.             END IF
  223.             i% = i% + 1
  224.         LOOP UNTIL i% = 50
  225.         ' IF massimi2(ieto%).ore < massimi1(visualizzaieto%, z%, 1).ore THEN massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  226.         IF massimi2(ieto%).portata < massimi1(visualizzaieto%, z%, 1).portata THEN
  227.             massimi2(ieto%).portata = massimi1(visualizzaieto%, z%, 1).portata
  228.             massimi2(ieto%).ore = massimi1(visualizzaieto%, z%, 1).ore
  229.         END IF
  230.     LOOP UNTIL z% = UBOUND(coefficienti)
  231. '---------------------------------------------------------------------------------------------------------------------------------------------------
  232. 'Questa subroutine crea gli ietogrammi chicago per ogni iterazione z%.
  233. 'Ad ogni nuovo dt! pone l'ultimo valore di pioggia come ultimo, il penultimo come primo, il terzultimo come penultimo, il quartultimo come secondo e così via.
  234. 'Quando vi è un valore di z% che ha un dt! non nuovo, cerca la precedente iterazione z% con lo stesso dt! e copia i suoi valori dello ietogramma chicago in quello dell'iterazione z% in corso. I valori rimanenti sono riempiti
  235. 'procedendo come prima.
  236. 'Quindi per esempio l'iterazione z%=1 corrisponde a d=1tc con passo temporale dt!. L'iterazione z%=2 corrisponde a d=2tc con il medesimo passo temporale. Per cui lo ietogramma chicago per d=2tc e' dato dallo stesso ietogramma
  237. 'chicago che si ha per d=1tc, con l'aggiunta, ai suoi estremi, dei nuovi valori. Il meccanismo si ripete per z%=3, che corrisponde a d=3tc, con il medesimo dt!. Per z%=4, corrispondente a d=4tc, invece, il passo temporale dt!
  238. 'cambia.
  239. 'Quanto detto e' necessario per evitare piccole discrepanze che potrebbero comportare il fatto che alcuni massimi risultino localmente poco piu' bassi del precedente, anche quando il trend generale e' chiaramente di aumento dei
  240. 'massimi all'aumentare della durata della pioggia. In questo modo si fa l'ipotesi che all'aumentare della durata della pioggia, discretizzata con uno stesso passo temporale dt!, ogni ietogramma contenga a sua volta il precedente.
  241. 'In tal modo, se si condiera per esempio d=2tc, si assume che l'altezza di pioggia corrispondente a 1tc, segua lo ietogramma relativo a d=1tc, cosi' che l'altezza di pioggia rimamente sia eclusivamente dovuta ai nuovi valori.
  242. SUB chicago ()
  243.     DIM test%
  244.     DIM k%
  245.     n% = 1
  246.     DO
  247.         IF z% = 1 THEN test% = 0: EXIT DO 'permette il calcolo dello ietogramma chicago della prima iterazione. test%=0
  248.         IF dt!(ieto%, z%) = dt!(ieto%, z% - n%) THEN ' se trova un'iterazione z% precedente con lo stesso dt! di quella in corso, esegue i comandi successivi
  249.             test% = 1
  250.             k% = m%(ieto%, z%)
  251.             i% = 0
  252.             DO 'inserisce i nuovi valori dello ietogramma chicago dell'iterazione z% in corso.
  253.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  254.                 k% = k% - 1
  255.                 IF k% = m%(ieto%, z% - n%) THEN EXIT DO 'se ha completato l'inserimento dei nuovi valori, passa oltre.
  256.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  257.                 k% = k% - 1
  258.                 i% = i% + 1
  259.             LOOP UNTIL k% = m%(ieto%, z% - n%)
  260.             IF matrice1(ieto%, z%, i%, 1).i2 = 0 THEN i% = i% - 1
  261.             k% = 1
  262.             DO 'inserisce lo ietogramma chicago dell'iterazione z% precedente con lo stesso dt!, nello ietogramma dell'iterazione z% in corso.
  263.                 i% = i% + 1
  264.                 matrice1(ieto%, z%, i%, 1).i2 = matrice1(ieto%, z% - n%, k%, 1).i2
  265.                 k% = k% + 1
  266.             LOOP UNTIL k% > m%(ieto%, z% - n%)
  267.             EXIT DO 'siccome ha completato lo ietogramma dell'iterazione z% in corso, non serve incrementare n%, quindi passa oltre. test%=1.
  268.         ELSE ' se non trova l'iterazione z% precedente con lo stesso dt! di quella in corso, incrementa n% e ripete la ricerca.
  269.             test% = 0
  270.             n% = n% + 1
  271.         END IF
  272.     LOOP UNTIL n% = z% - 1 'se non ha trovato iterazioni z% precedenti con lo stesso dt!, allora passa oltre e test%=0.
  273.     SELECT CASE test%
  274.         CASE IS = 1 'esce dalla subroutine, in quanto lo ietogramma e' definito.
  275.             EXIT SUB
  276.         CASE IS = 0 'calcola ex-novo lo ietogramma relativo all'iterazione z% in corso in quanto non vi e' un'iterazioni z% precedente con lo stesso dt! dell'iterazione z% in corso.
  277.             k% = m%(ieto%, z%)
  278.             i% = 0
  279.             DO
  280.                 matrice1(ieto%, z%, m%(ieto%, z%) - i%, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  281.                 k% = k% - 1
  282.                 IF k% = 0 THEN EXIT DO
  283.                 matrice1(ieto%, z%, i% + 1, 1).i2 = matrice1(ieto%, z%, k%, 1).i1
  284.                 k% = k% - 1
  285.                 i% = i% + 1
  286.             LOOP UNTIL k% = 0
  287.     END SELECT
  288. '-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  289. SUB grafici (ore!, oreM!, QM!)
  290.     'ore!: ore massime di analisi.
  291.     'oreM!: ore corrispondenti alla portata massima.
  292.     'QM!: portata massima.
  293.  
  294.     CONST dxy% = 30
  295.     CONST L% = 800
  296.     CONST H% = 600
  297.  
  298.     ' CONST LH! = L% / H% 'costante che, all'interno del comando WINDOW, di portare la scala delle ordinate uguale a quella delle ascisse.
  299.     CONST rosso = _RGB32(255, 0, 0)
  300.     CONST bianco = _RGB32(255, 255, 255)
  301.     CONST giallo = _RGB32(255, 255, 0)
  302.  
  303.     DIM grafico&
  304.     DIM fx! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse x e nelle circonferenze.
  305.     DIM fy! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse y.
  306.     DIM dx!, dy!
  307.     DIM tacca%
  308.     DIM k%
  309.  
  310.     grafico& = _NEWIMAGE(L%, H%, 32)
  311.     fx! = L% / (ore! * 1.1) '=168.3349 'pixel/ora
  312.     fy! = H% / (QM! * 1.1) '=23.3657 'pixel/mc
  313.     dx! = dxy% / fx! '=0.1782162:dx! e' la lunghezza dentro WINDOWS per avere un numero di pixel=dxy%.
  314.     dy! = dxy% / fy! '=1.283933
  315.     tacca% = QM! \ 5
  316.  
  317.     _DEST grafico&
  318.     SCREEN grafico&
  319.     LINE (0, 0)-(L% - 1, H% - 1), rosso, B
  320.     WINDOW (0, 0)-(ore! * 1.1 + dx!, QM! * 1.1 + dy!) 'scala ascisse e ordinate in base alle ore e alla portata, estendendole del 10%.
  321.     LINE (dx!, QM! * 1.1)-(dx!, dy!): LINE -(ore! * 1.1, dy!), bianco
  322.     PSET (dx!, QM! * 1.1!), bianco: DRAW "F20": PSET (dx!, QM! * 1.1), bianco: DRAW "G20" ': LOCATE 7, 65: PRINT "y"
  323.     PSET (ore! * 1.1, dy!), bianco: DRAW "G20": PSET (ore! * 1.1, dy!), bianco: DRAW "H20" ': LOCATE 25, 112: PRINT "x"
  324.     FOR z% = 1 TO 24
  325.         CIRCLE (dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), 3 / fx!, rosso
  326.         PAINT (dx! + massimi1(visualizzaieto%, z%, 1).ore + 0.5 / fx!, dy! + massimi1(visualizzaieto%, z%, 1).portata + 0.5 / fx!), rosso
  327.         IF z% = 1 THEN
  328.             LINE (dx!, dy!)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), rosso
  329.         ELSE
  330.             LINE (dx! + massimi1(visualizzaieto%, z% - 1, 1).ore, dy! + massimi1(visualizzaieto%, z% - 1, 1).portata)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata), rosso
  331.         END IF
  332.         IF z% = 24 THEN
  333.             SELECT CASE visualizzaieto%
  334.                 CASE IS = 1
  335.                     LINE -(dx!, dy! + massimi1(visualizzaieto%, z%, 1).portata), bianco, , 61440
  336.                     LINE (dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy!), bianco, , 61440
  337.                 CASE IS = 2
  338.                     LINE (dx! + massimi1(visualizzaieto%, z%, 1).ore, dy! + massimi1(visualizzaieto%, z%, 1).portata)-(dx! + massimi1(visualizzaieto%, z%, 1).ore, dy!), bianco, , 61440
  339.             END SELECT
  340.         END IF
  341.     NEXT z%
  342.     IF visualizzaieto% = 2 THEN
  343.         LINE (dx!, dy! + QM!)-(dx! + oreM!, dy! + QM!), bianco, , 61440
  344.         LINE -(dx! + oreM!, dy!), bianco, , 61440
  345.     END IF
  346.     ' _PRINTSTRING (L% \ 2, H% \ 2), "O" '_PRINTSTRING non usa le coordinate locali di VIEW, ma sempre quello dello SCREEN in uso. Per tal ragione e' stato necessario creare grafico&.
  347.     SLEEP
  348.     i% = 1
  349.     k! = 0.98
  350.     WHILE i% * tacca% <= QM!
  351.         LINE (dx! - 5 / fx!, dy! + i% * tacca%)-(dx! + 5 / fx!, dy! + i% * tacca%): SLEEP
  352.         _PRINTSTRING (dx! * fx! - 20, H% - 1 - (dy! + i% * tacca%) * fy! * k!), "-": SLEEP
  353.         i% = i% + 1
  354.     WEND
  355.     WINDOW
  356.     i% = 1
  357.     '  k! = 1
  358.     WHILE i% * tacca% <= QM!
  359.         '   LINE (dxy% - 1 - 5, H% - 1 - (dy! + i% * tacca%) * fy! * k!)-(dxy% - 1 + 1000, H% - 1 - (dy! + i% * tacca%) * fy! * k!), giallo: SLEEP
  360.         '   PRINT (dy! + i% * tacca%) * fy!: SLEEP
  361.         _PRINTSTRING (dx! * fx! - 20, H% - 1 - (dy! + i% * tacca%) * fy! * k!), "--": SLEEP
  362.         i% = i% + 1
  363.     WEND
  364.     ' k% = i% * tacca%
  365.     'i% = 1
  366.     'WHILE i% <= ore!
  367.     '    _PRINTSTRING (dxy%, H% - 1 - (dxy% + i% * k%)), "-"
  368.     'i% = i% + 1
  369.     'WEND
  370.     '  _PUTIMAGE ((_DESKTOPWIDTH - L%) \ 2, (_DESKTOPHEIGHT - H%) \ 2), grafico&, schermo&
  371.     '   _FREEIMAGE grafico&
  372. '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  373. SUB risultati ()
  374.     FOR z% = 1 TO 24
  375.         CLS
  376.         PRINT "z%="; z%
  377.         PRINT "dt="; dt!(visualizzaieto%, z%); ";"; dt!(visualizzaieto%, z%) * 60
  378.         PRINT "visualizzaieto%="; visualizzaieto%
  379.         PRINT "m%="; m%(visualizzaieto%, z%)
  380.         PRINT "N="; coefficienti(z%).d / tc!
  381.         PRINT "n="; coefficienti(z%).tSUta
  382.         FOR i% = 1 TO 50
  383.             '  _LIMIT limit
  384.     PRINT _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).m)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).mdt)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tminuti)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).h1)),_
  385.      _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i1)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).i2)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).DH)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).H2)),_
  386.       _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).he)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).Dhe)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUStSUta)),_
  387.        _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).MOCKUSqSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).tmSUta)), _TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qmSUqp)),_TRIM$(STR$(matrice1(visualizzaieto%,z%,i%, 1).qm))
  388.         NEXT i%
  389.         SLEEP
  390.         CLS
  391.         FOR n% = 1 TO 50
  392.             '  _LIMIT limit
  393.             LOCATE 1,
  394.             FOR i% = 1 TO 50
  395.                 LOCATE , n% * 4 - 3
  396.                 PRINT matrice2!(visualizzaieto%, z%, i%, n%)
  397.             NEXT i%
  398.         NEXT n%
  399.         SLEEP
  400.     NEXT z%
  401.     CLS
  402.     FOR n% = 1 TO 24
  403.         ' _LIMIT limit
  404.         SELECT CASE n%
  405.             CASE IS <= 16
  406.                 FOR i% = 1 TO 50
  407.                     LOCATE i%, n% * 15 - 14
  408.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  409.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  410.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  411.  
  412.                 NEXT i%
  413.                 IF n% = 16 THEN SLEEP: CLS
  414.             CASE IS > 16
  415.                 FOR i% = 1 TO 50
  416.                     LOCATE i%, (n% - 16) * 15 - 14
  417.                     PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).portata))
  418.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).ore))
  419.                     'PRINT _TRIM$(STR$(idrogramma(visualizzaieto%, n%, i%, 1).minuti))
  420.                 NEXT i%
  421.         END SELECT
  422.     NEXT n%
  423.     SLEEP
  424.     CLS
  425.     FOR z% = 1 TO 24
  426.         ' _LIMIT limit
  427.         PRINT massimi1(visualizzaieto%, z%, 1).ore, massimi1(visualizzaieto%, z%, 1).minuti, massimi1(visualizzaieto%, z%, 1).portata
  428.     NEXT z%
  429.     SLEEP
  430.     PRINT
  431.     PRINT massimi2(visualizzaieto%).ore; massimi2(visualizzaieto%).portata
  432.  

« Last Edit: February 20, 2021, 11:40:28 am by bartok »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #1 on: February 20, 2021, 08:07:07 am »
I don't know if I understand this correctly, but if you have a positioning problem between screen absolute coordinates and WINDOW defined coordinates, I've used the map! function to good effect. If you have a value that needs translation from an old  range {minRange!/maxRange!}, it will translate that value to the new range {newMinRange!/newMaxRange!}. The order depends upon which way one is going, from WINDOW to screen or from screen to WINDOW. Hope this helps

Code: QB64: [Select]
  1. Function map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  2.  
  3.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  4.  
  5.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #2 on: February 20, 2021, 10:52:47 am »
Aren't _PrintString coordinates automatically translated to Window coordinates like the graphics pset, line, circle..., if not, try same trick for translating Mouse Coordinates in a Window use PMap see Wiki.

Use Moses idea if printing outside the Window or returning screen back to normal.

BTW is your graph reversed? Both look flipped: up/down and left/right? Your screen bigger than my laptop, didn't see the axis arrows they were over in the storage shelf left of my laptop on my desk. :)

Ah TempodiBasic and or Kiara are recruiting ;-))
« Last Edit: February 20, 2021, 01:26:32 pm by bplus »

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #3 on: February 20, 2021, 11:36:36 am »
I don't know if I understand this correctly, but if you have a positioning problem between screen absolute coordinates and WINDOW defined coordinates, I've used the map! function to good effect. If you have a value that needs translation from an old  range {minRange!/maxRange!}, it will translate that value to the new range {newMinRange!/newMaxRange!}. The order depends upon which way one is going, from WINDOW to screen or from screen to WINDOW. Hope this helps

Code: QB64: [Select]
  1. Function map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  2.  
  3.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  4.  
  5.  

Hi and thanks for the tip, but it doesn't work with the damned _PRINTSTRING!

As you can see in the semplified code above (press any key to go ahead), outside WINDOW, your function works, because lines drawn in the WHILE cicle of lines 55 to 59, perfetly mach the notches drawn inside WINDOW in the WHILE circle of lines 40 to 44.

But, in the WHILE cicle of lines 62 to 66, no matches! I have also tried to add something like this:

_PRINTSTRING (55, H% - 1 - test!+K)

where K is an empirical and inexplicable value brutally added in order to have the match: no way.

Code: QB64: [Select]
  1. CONST ore! = 6.723612
  2. CONST oreM! = 6.723612
  3. CONST QM! = 29.88063
  4.  
  5. CONST dxy% = 30
  6. CONST L% = 800
  7. CONST H% = 600
  8.  
  9. CONST rosso = _RGB32(255, 0, 0)
  10. CONST bianco = _RGB32(255, 255, 255)
  11. CONST giallo = _RGB32(255, 255, 0)
  12.  
  13. DIM grafico&
  14. DIM fx! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse x e nelle circonferenze.
  15. DIM fy! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse y.
  16. DIM dx!, dy!
  17. DIM test%
  18. DIM tacca%
  19. DIM i%
  20.  
  21. grafico& = _NEWIMAGE(L%, H%, 32)
  22. fx! = L% / (ore! * 1.1) '=168.3349 'pixel/ora
  23. fy! = H% / (QM! * 1.1) '=23.3657 'pixel/mc
  24. dx! = dxy% / fx! '=0.1782162:dx! e' la lunghezza dentro WINDOWS per avere un numero di pixel=dxy%.
  25. dy! = dxy% / fy! '=1.283933
  26. tacca% = QM! \ 5
  27.  
  28.  
  29.  
  30. _DEST grafico&
  31. SCREEN grafico&
  32. LINE (0, 0)-(L% - 1, H% - 1), rosso, B
  33. WINDOW (0, 0)-(ore! * 1.1 + dx!, QM! * 1.1 + dy!) 'scala ascisse e ordinate in base alle ore e alla portata, estendendole del 10%.
  34. 'test! = map!(QM! \ 5 + dy!, 0, dy! + QM! * 1.1, 0, H% - 1)
  35. LINE (dx!, QM! * 1.1)-(dx!, dy!): LINE -(ore! * 1.1, dy!), bianco
  36. PSET (dx!, QM! * 1.1!), bianco: DRAW "F20": PSET (dx!, QM! * 1.1), bianco: DRAW "G20" ': LOCATE 7, 65: PRINT "y"
  37. PSET (ore! * 1.1, dy!), bianco: DRAW "G20": PSET (ore! * 1.1, dy!), bianco: DRAW "H20" ': LOCATE 25, 112: PRINT "x"
  38. i% = 1
  39. WHILE i% * tacca% <= QM!
  40.     LINE (dx! - 5 / fx!, dy! + i% * tacca%)-(dx! + 5 / fx!, dy! + i% * tacca%): SLEEP
  41.     '  _PRINTSTRING (dx! * fx! - 20, H% - 1 - (dy! + i% * tacca%) * fy! * k!), "-": SLEEP
  42.     i% = i% + 1
  43.  
  44.  
  45. 'i% = 1
  46. 'WHILE i% * tacca% <= QM!
  47. '_PRINTSTRING (dx! * fx! - 20, H% - 1 - (dy! + i% * tacca%) * fy!), "--": SLEEP
  48. 'i% = i% + 1
  49. 'WEND
  50.  
  51. i% = 1
  52. WHILE i% * tacca% <= QM!
  53.     test! = map!(i% * QM! \ 5 + dy!, 0, dy! + QM! * 1.1, 0, H% - 1)
  54.     LINE (35, H% - 1 - test!)-(50, H% - 1 - test!): PRINT test!: SLEEP '------|
  55.     i% = i% + 1 '                                                             |
  56. WEND '                                                                        |
  57. '                                                                             |
  58. i% = 1 '                                                                      |---Same (H%-1-test!), different output!
  59. WHILE i% * tacca% <= QM! '                                                    |
  60.     test! = map!(i% * QM! \ 5 + dy!, 0, dy! + QM! * 1.1, 0, H% - 1) '         |
  61.     _PRINTSTRING (55, H% - 1 - test!), "--": PRINT test!: SLEEP '-------------|
  62.     i% = i% + 1
  63. '---------------------------------------------------------------------------------------
  64. FUNCTION map! (value!, minWINDOW!, maxWINDOW!, minPIXEL%, maxPIXEL%)
  65.     map! = ((value! - minWINDOW!) / (maxWINDOW! - minWINDOW!)) * (maxPIXEL% - minPIXEL%) + minPIXEL%
  66.  
« Last Edit: February 20, 2021, 11:53:39 am by bartok »

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #4 on: February 20, 2021, 11:42:07 am »
Your screen bigger than my laptop, didn't see the axis arrows they were over in the storage shelf left of my laptop on my desk. :)

Ah TempodiBasic and or Kiara are recruiting ;-))

I have changed both of the 2 codes with 800x600.

In the second post, I have semplified the code, because the core of my problem is in the "graphs" subroutine of the first code I have posted. However, the program is finalized to calculate the maximum flow of a given drainage basin for a given return period, depending on the duration of the rain.

Quote
Aren't _PrintString coordinates automatically translated to Window coordinates like the graphics pset, line, circle.

no, unfortunately they aren't...
« Last Edit: February 20, 2021, 11:56:14 am by bartok »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #5 on: February 20, 2021, 12:04:58 pm »
You’re in SCREEN 0, where _PRINTSTRING is nothing more than a shortcut for LOCATE x, y: PRINT.

Here’s the relevant c-snippet for you:

Code: C++: [Select]
  1.        void sub__printstring(float x,float y,qbs* text,int32 i,int32 passed){
  2.             .... STUFF
  3.             if (im->text){
  4.                 int oldx = func_pos(0), oldy = func_csrlin();
  5.                 qbg_sub_locate(y, x, 0, 0, 0, 3);
  6.                 qbs_print(text, 0);
  7.                 qbg_sub_locate(oldy, oldx, 0, 0, 0, 3);
  8.                 goto printstring_exit;
  9.             }
  10.             ..... STUFF

If you’re in a text screen, simply use _PRINTSTRING as a LOCATE, PRINT, then restore the previous LOCATE position.

If _PRINTSTRING doesn’t work, just go back to LOCATE: PRINT

Edit: Nevermind...  I see your SCREEN statement down on line 70something...  You’re not trying anything in a text screen after all. 
« Last Edit: February 20, 2021, 12:08:59 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #6 on: February 20, 2021, 01:06:24 pm »
SMcNeill,
yes, in fact I am in graphic mode.

It is not possible it is so complicated to put a text in a graph!:D

(I try to avoid the use of GOTO).
« Last Edit: February 20, 2021, 01:11:59 pm by bartok »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #7 on: February 20, 2021, 01:23:25 pm »
Found my old test code.

YES you MUST use PMAP for x, y conversion for both MOUSE and for _PRINTSTRING

demo
Code: QB64: [Select]
  1. _TITLE "Test Using Window for Cartesian Coordinate System x = -100 to 100, y = -100 to 100"
  2. 'It seems all graphics commands convert x, y to window system BUT...
  3. 'Mouse and _PrintString do not convert! BUT...
  4. 'Somebody setup a PMAP system that will do these conversions both to grapghics coordinate system and back
  5. ' convert mouse qbx, qby to graphics x, y use
  6. ' PMAP(qbx, 2), PMAP(qby, 3)
  7. ' And to print something at the graphics location use
  8. ' PMAP(graphicsX, 0), PMAP(graphicsY, 1) to _PRINTSTRING to a graphics location
  9.  
  10. CONST xmax = 700, ymax = 700, red = &HFFFF0000, grn = &HFF009900, blu = &HFF0000AA
  11. CONST tlx = -100, tly = 100, brx = 100, bry = -100 ' Cartesian Coordinate System corners for WINDOW command
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. _SCREENMOVE 300, 40
  14.  
  15. DIM mx, my, a, r, s$
  16.  
  17. WINDOW (tlx, tly)-(brx, bry) ' converts QB csreen to Cartesian Coodianate System
  18. WHILE _KEYDOWN(27) = 0
  19.     CLS
  20.     mx = INT(PMAP(_MOUSEX, 2)): my = INT(PMAP(_MOUSEY, 3)) 'covert mouse to Cart Cood using PMAP
  21.     a = atan360(my, mx) 'mouse angle to origin
  22.     r = INT((mx * mx + my * my) ^ .5)
  23.     LINE (0, 0)-(mx, my), grn 'hypotenuse = radius
  24.     LINE (0, 0)-(mx, 0), blu ' r*cos
  25.     LINE (mx, 0)-(mx, my), red ' r*sin
  26.     arc 0, 0, 10, 0, _R2D(a), &HFFFFFF00 'yellow arc
  27.     s$ = "Mouse (" + _TRIM$(STR$(mx)) + ", " + _TRIM$(STR$(my)) + "), Radius: "
  28.     s$ = s$ + _TRIM$(STR$(r)) + ", Degrees: " + _TRIM$(STR$(_R2D(a) \ 1))
  29.     _PRINTSTRING (PMAP(0, 0), PMAP(-1, 1)), s$
  30.     _PRINTSTRING (PMAP(-95, 0), PMAP(95, 1)), "COS = x/r = " + _TRIM$(STR$(mx / r))
  31.     _PRINTSTRING (PMAP(-95, 0), PMAP(89, 1)), "SIN = y/r = " + _TRIM$(STR$(my / r))
  32.     IF mx <> 0 THEN _PRINTSTRING (PMAP(-95, 0), PMAP(83, 1)), "TAN = y/x = " + _TRIM$(STR$(my / mx)) 'EDIT
  33.     _DISPLAY
  34.     _LIMIT 60
  35.  
  36. ' A regular graphic draw still works correctly in a Cartesian Window System!
  37. 'note: degrees start due East = 0 and go clockwise: South = 90, West = 180, North = 270
  38. SUB arc (x, y, r, degStart, degStop, c~&)
  39.  
  40.     DIM rs, re, a, ax, ay, lastx, lasty
  41.     'x, y origin, r = radius, c = color
  42.  
  43.     'degStart is first angle clockwise from due East = 0 degrees
  44.     ' arc will start drawing there and clockwise until degStop angle reached, unless in Cartesain Window
  45.  
  46.     IF degStop < degStart THEN
  47.         arc x, y, r, degStart, 360, c~&
  48.         arc x, y, r, 0, degStop, c~&
  49.     ELSE
  50.         rs = _D2R(degStart): re = _D2R(degStop)
  51.         FOR a = rs TO re STEP 1 / (7 * r)
  52.             ax = x + r * COS(a)
  53.             ay = y + r * SIN(a)
  54.             IF a <> rs THEN LINE (lastx, lasty)-(ax, ay), c~&
  55.             lastx = ax: lasty = ay
  56.         NEXT
  57.     END IF
  58.  
  59. 'need to match degrees going around clockwise up to full circle
  60. FUNCTION atan360 (y, x)
  61.     DIM test
  62.     test = _ATAN2(y, x)
  63.     IF test < 0 THEN atan360 = _PI(2) + test ELSE atan360 = test
  64.  
  65.  

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #8 on: February 20, 2021, 01:46:08 pm »
bplus,
thank you very much! I did not have time yet to try PMAP after your message, but it was already my purpose to try it. I didn't know the command PMAP before today.

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #9 on: February 21, 2021, 04:01:32 am »
Thank's you bplus, with PMAP it works better!

But, as you can see in the code above on line 43, I have to add "-7" in order to have the strings "--" fitting. I don't know why! In line 41 PMAP gets the y screen coordinates of WINDOW y coordinates of the line drawn in line 39. So the string "--" printed with _PRINTSTRING in line 43 should match using y calculated by PMAP without this "-7"...

Code: QB64: [Select]
  1. CONST ore! = 6.723612
  2. CONST oreM! = 6.723612
  3. CONST QM! = 29.88063
  4.  
  5. CONST dxy% = 30
  6. CONST rosso = _RGB32(255, 0, 0)
  7. CONST bianco = _RGB32(255, 255, 255)
  8. CONST giallo = _RGB32(255, 255, 0)
  9.  
  10. DIM L%, H%
  11. DIM grafico&
  12. DIM fx! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse x e nelle circonferenze.
  13. DIM fy! 'all'interno del comando WINDOW e VIEW permette di disegnare in pixel sull'asse y.
  14. DIM dx!, dy!
  15. DIM tacca%
  16. DIM x%, y%
  17.  
  18. H% = _DESKTOPHEIGHT * 2 / 3
  19. L% = H% * 1.62
  20.  
  21. grafico& = _NEWIMAGE(L%, H%, 32)
  22. fx! = L% / (ore! * 1.1) '=168.3349 'pixel/ora
  23. fy! = H% / (QM! * 1.1) '=23.3657 'pixel/mc
  24. dx! = dxy% / fx! '=0.1782162:dx! e' la lunghezza dentro WINDOWS per avere un numero di pixel=dxy%.
  25. dy! = dxy% / fy! '=1.283933
  26. tacca% = QM! \ 5
  27.  
  28. _DEST grafico&
  29. SCREEN grafico&
  30. LINE (0, 0)-(L% - 1, H% - 1), rosso, B
  31. WINDOW (0, 0)-(ore! * 1.1 + dx!, QM! * 1.1 + dy!) 'scala ascisse e ordinate in base alle ore e alla portata, estendendole del 10%.
  32. LINE (dx!, QM! * 1.1)-(dx!, dy!): LINE -(ore! * 1.1, dy!), bianco
  33. PSET (dx!, QM! * 1.1!), bianco: DRAW "F20": PSET (dx!, QM! * 1.1), bianco: DRAW "G20" ': LOCATE 7, 65: PRINT "y"
  34. PSET (ore! * 1.1, dy!), bianco: DRAW "G20": PSET (ore! * 1.1, dy!), bianco: DRAW "H20" ': LOCATE 25, 112: PRINT "x"
  35. i% = 1
  36. i% = 1
  37. WHILE i% * tacca% <= QM!
  38.     LINE (dx! - 5 / fx!, dy! + i% * tacca%)-(dx! + 5 / fx!, dy! + i% * tacca%): SLEEP
  39.     x% = PMAP(dx! - 5 / fx!, 0)
  40.     y% = PMAP(dy! + i% * tacca%, 1)
  41.     PRINT x%, y%: SLEEP
  42.     _PRINTSTRING (x% + 10, y% - 7), "--": SLEEP '----------------------------------------------------> WHY 7??
  43.     i% = i% + 1
  44.  
« Last Edit: February 21, 2021, 04:02:45 am by bartok »

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #10 on: February 21, 2021, 05:38:33 am »
Ok, solved!

PMAP works perfectly with _PRINTSTRING. In this case "--" didn't match the line because the line is drawn at the top and "--" in the middle (_--)-->up side down.
But this is not the solution without using PMAP, because in the preview tries the "--"  changed the distance with the line. So PMAP is necessary.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #11 on: February 21, 2021, 09:20:12 am »
I find this interesting as I have not, thus far, investigated PMAP.

It would seem that it is essentially FUNCTION map! that I posted earlier, only optimized for screen ops, and much less typing.

You couldn't use it, like you can map!, for general computations, but it's much easier for graphics. You don't have to do that much range figuring.

Having learned about a new trick, I'll have to do some experiments now...;)



Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #12 on: February 21, 2021, 01:23:56 pm »
Yeah WINDOW is the way to go especially for math apps that you want standard 4 quads upper right #1 and going Counter-clockwise 2, 3, 4 with angle increases.

Anyway with that command (set correctly of course) angles Increase going counter-clockwise and y up is up and x up is right! The way you learned it in school before Basic ruined your mind by flipping it upside down and making angles increase clockwise ;-))

Trouble is I don't know if anyone uses it enough to report bugs when working with all the new extensions installed with QB64 ie how z axis might work with GL 3D?




Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #13 on: February 21, 2021, 05:21:58 pm »
Trouble is I don't know if anyone uses it enough to report bugs when working with all the new extensions installed with QB64 ie how z axis might work with GL 3D?

I am a beginner, so I think that my level is not enough hight to report bugs, but maybe it wouldn't be bad if _PRINTSTRING worked also inside WINDOW. But perhaps there is a reason if it doesn't. For the 3D, maybe some games programmer. I don't think my graphics needs will go beyond 2D.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem to print values on the axis inside and outside WINDOW.
« Reply #14 on: February 21, 2021, 06:45:55 pm »
Code: QB64: [Select]
  1. _TITLE "But _PrintString Works Fine in a Winodow!"
  2. CONST xmax = 512, ymax = 400
  3. CONST Top_Left_X = -100, Top_Left_Y = 100, Bottom_Right_X = 100, Bottom_Right_Y = -100 ' Cartesian Coordinate System corners for WINDOW command
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. _SCREENMOVE 300, 40
  6. WINDOW (Top_Left_X, Top_Left_Y)-(Bottom_Right_X, Bottom_Right_Y) ' converts QB csreen to Cartesian Coodianate System
  7. _PRINTSTRING (PMAP(-95, 0), PMAP(60, 1)), "I am a beginner, so I think that my level is not enough high"
  8. _PRINTSTRING (PMAP(-95, 0), PMAP(30, 1)), "to report bugs, but maybe it wouldn't be bad if _PRINTSTRING"
  9. _PRINTSTRING (PMAP(-95, 0), PMAP(0, 1)), "worked also inside WINDOW. But perhaps there is a reason if "
  10. _PRINTSTRING (PMAP(-95, 0), PMAP(-30, 1)), "it doesn't. For the 3D, maybe some games programmer. I don't"
  11. _PRINTSTRING (PMAP(-95, 0), PMAP(-60, 1)), " think my graphics needs will go beyond 2D."
  12.  
  13.  
  14.  
« Last Edit: February 21, 2021, 07:01:29 pm by bplus »