Hi,
Analyzing the Pete's code for scrolling the screen, I came across PCOPY statement. I have already meet it in BitMaze example of the tutorial by Terry and in the QB64 help, and I thought to have understood it:
BITMAZE:
'*
'* Bitwise math demonstration
'*
'* Draws a simple map and allows player to move circle within map
'*
'--------------------------------
'- Variable Declaration Section -
'--------------------------------
DIM MAP%
(3, 5, 5) ' create threedimentional array DIM cx%
' current x cell coordinate of player DIM cy%
' current y cell coordinate of player DIM KeyPress$
' player key presses
'----------------------------
'- Main Program Begins Here -
'----------------------------
_TITLE "Simple Map" ' give window a title DRAWMAP ' draw the map
cx% = 1
cy% = 1
DO ' MAIN LOOP begins here PCOPY 1, 0 ' copy page 1 to current screen CIRCLE (MAP%
(2, cx%
, cy%
) + 24, MAP%
(3, cx%
, cy%
) + 24), 20, _RGB32(255, 0, 0) ' draw player PAINT (MAP%
(2, cx%
, cy%
) + 24, MAP%
(3, cx%
, cy%
) + 24), _RGB32(128, 0, 0), _RGB32(255, 0, 0) _DISPLAY ' update the screen without flicker DO ' KEY INPUT LOOP begins here KeyPress$
= INKEY$ ' get a key (if any) that player pressed _LIMIT 120 ' limit loop to 120 times per second LOOP UNTIL KeyPress$
<> "" ' KEY INPUT LOOP back if no key IF NOT MAP%
(1, cx%
, cy%
) AND 1 THEN cy%
= cy%
- 1 ' move player up if no wall present IF NOT MAP%
(1, cx%
, cy%
) AND 2 THEN cx%
= cx%
+ 1 ' move player right if no wall present IF NOT MAP%
(1, cx%
, cy%
) AND 4 THEN cy%
= cy%
+ 1 ' move player down if no wall present IF NOT MAP%
(1, cx%
, cy%
) AND 8 THEN cx%
= cx%
- 1 ' move player left if no wall present
'-----------------------------------
'- Function and Subroutine section -
'-----------------------------------
'*
'* draws a map based on the value of each map cell
'*
SHARED MAP%
() ' AS MAP ' need access to map array
DIM x%
, y%
' x,y map coordinates MAP%(2, x%, y%) = (x% - 1) * 50
MAP%(3, x%, y%) = (y% - 1) * 50
IF MAP%
(1, x%
, y%
) AND 1 THEN ' is NORTH wall present? LINE (MAP%
(2, x%
, y%
), MAP%
(3, x%
, y%
))-(MAP%
(2, x%
, y%
) + 49, MAP%
(3, x%
, y%
)), _RGB32(255, 255, 255) ' yes, draw it IF MAP%
(1, x%
, y%
) AND 2 THEN ' is EAST wall present? LINE (MAP%
(2, x%
, y%
) + 49, MAP%
(3, x%
, y%
))-(MAP%
(2, x%
, y%
) + 49, MAP%
(3, x%
, y%
) + 49), _RGB32(255, 255, 255) 'yes, draw it IF MAP%
(1, x%
, y%
) AND 4 THEN ' is SOUTH wall present? LINE (MAP%
(2, x%
, y%
), MAP%
(3, x%
, y%
) + 49)-(MAP%
(2, x%
, y%
) + 49, MAP%
(3, x%
, y%
) + 49), _RGB32(255, 255, 255) 'yes, draw it IF MAP%
(1, x%
, y%
) AND 8 THEN ' is WEST wall present? LINE (MAP%
(2, x%
, y%
), MAP%
(3, x%
, y%
))-(MAP%
(2, x%
, y%
), MAP%
(3, x%
, y%
) + 49), _RGB32(255, 255, 255) ' yes, draw it PCOPY 0, 1 ' save a copy of the map
'------------------------
'- Program DATA section -
'------------------------
'*
'* Map cell values
'*
DATA 11,15,15,11,15,12,5,5,4,3,15,15,15,15,10,11,15,9,5,6,12,5,6,15,15
QB64 help:
DIM x
(10), y
(10), dx
(10), dy
(10) PCOPY 1, 0 'place image on the visible page 0 _LIMIT 100 'regulates speed of balls in QB64 CIRCLE(x
(a
), y
(a
)), 5, 15 'all erasing and drawing is done on page 1 x(a) = x(a) + dx(a)
y(a) = y(a) + dy(a)
IF x
(a
) > 320 THEN dx
(a
) = -dx
(a
): x
(a
) = x
(a
) - 1 IF x
(a
) < 0 THEN dx
(a
) = -dx
(a
): x
(a
) = x
(a
) + 1 IF y
(a
) > 200 THEN dy
(a
) = -dy
(a
): y
(a
) = y
(a
) - 1 IF y
(a
) < 0 THEN dy
(a
) = -dy
(a
): y
(a
) = y
(a
) + 1
I thought to have worked PCOPY out.
Speaking about BITMAZE.
on line 21, the SCREEN _NEWIMAGE is set by default on 0, as a working and visualized page. Then the subroutine DRAWMAP draws the map in page 0 and line 82 copies the map, drawned in page 0, to page 1, while the working page is alway the visualized page 0. The DO loop in line 27 draws the circle in the visualized page 0, and the line 28 copies the map drawned in page 1, in page 0, deleting the preview circle of the preview loop, while the following lines drawn the new circle.
Speaking about the QB64 help.
on line 1, the working page is set to 1, while the visualized page is 0. the DO loop at line 10 draws the circles in background on page 1, and the PCOPY command in line 10 copies the circles in the visualized page 0 one time at loop, avoiding the flickering. Same result with _DISPLAY:
DIM x
(10), y
(10), dx
(10), dy
(10) ' PCOPY 1, 0 'place image on the visible page 0
_LIMIT 100 'regulates speed of balls in QB64 CIRCLE (x
(a
), y
(a
)), 5, 15 'all erasing and drawing is done on page 1 x(a) = x(a) + dx(a)
y(a) = y(a) + dy(a)
IF x
(a
) > 320 THEN dx
(a
) = -dx
(a
): x
(a
) = x
(a
) - 1 IF x
(a
) < 0 THEN dx
(a
) = -dx
(a
): x
(a
) = x
(a
) + 1 IF y
(a
) > 200 THEN dy
(a
) = -dy
(a
): y
(a
) = y
(a
) - 1 IF y
(a
) < 0 THEN dy
(a
) = -dy
(a
): y
(a
) = y
(a
) + 1
As I was saying, I was studying the Pete code to scroll the screen. In this code, PCOPY is used in a much complicated way, so I tried to work it out by implementig PCOPY on my y=kx^m code first. So, I have concluded that I don't have understood PCOPY statement.
Thi is my code, and it doesn't work this time:
disegno
disegno
CONST A%
= 1 'per prendere un punto ogni A% pixel. CONST k!
= 1 ' coefficiente della x. CONST m%
= 2 'esponente della x. CONST s!
= 5 * k!
'amplificazione di scala delle ascisse. DIM titolo1$
, titolo2$
, punti$
, istruzioni$
DIM punti%
, i%
, n%
'valori di x considerati da -punti% a +punti%, i% e n% sono contatori. i% = 1
DO 'disegna cartiglio, assi, scrive istruzioni e chiede il n. di punti. non accetta come valore "0". SCREEN schermo&
, , 1, 0 'imposta schermo& come pagina di lavoro e visualizzata. titolo1$
= "RAPPRESENTAZIONE DELLA FUNZIONE y = kx^m (k =" + STR$(k!
) + " ; m =" + STR$(m%
) + ")" titolo2$
= "(Fattore di amplificazione delle ascisse: s = " + STR$(s!
) + ")" LINE (0, 0)-(799, 599), rosso
, B
_PUTIMAGE ((L%
- 800) \
2, (H%
- 600) \
2), grafico1&
, schermo&
SCREEN schermo&
, , 1, 0 'le iscruzioni che seguono agiscono su schermo&, che e' visualizzato. punti$ = "Inserire il n. di punti in ascissa: "
SCREEN grafico2&
, , 3, 0 'le istruzioni che seguono agiscono in background su grafico2&. n% = -punti%
DO UNTIL n%
= punti%
+ 1 ' crea il vettore con i valori di x e y i cui elementi vanno da -punti% a +punti%. disegna un cerchio colorato per ogni punto, traslando il grafico in modo che l'orgine non sia in alto a sinistra, ma su "0". funzione(i%).x = n%
funzione(i%).y = k! * (funzione(i%).x) ^ m
CIRCLE (s!
* A%
* funzione
(i%
).x
+ 399, A%
* funzione
(i%
).y
+ 299), 2, rosso
PAINT (s!
* A%
* funzione
(i%
).x
+ 399 + 1, A%
* funzione
(i%
).y
+ 299 + 1), rosso
i% = i% + 1
n% = n% + 1
FOR i%
= 1 TO UBOUND(funzione
) - 1 ' congiunge i punti. LINE (s!
* A%
* funzione
(i%
).x
+ 399, A%
* funzione
(i%
).y
+ 299)-(s!
* A%
* funzione
(i%
+ 1).x
+ 399, A%
* funzione
(i%
+ 1).y
+ 299), rosso
_PUTIMAGE (0, 599)-(799, 0), grafico2&
, grafico1&
, (0, 0)-(799, 599) 'mette grafico2& su grafico1&, invertendo le x, in modo che le y postive siano verso l'alto e non verso il basso. _PUTIMAGE ((L%
- 800) \
2, (H%
- 600) \
2), grafico1&
, schermo&
'mette grafico1& su schermo&, il quale, essendo visualizzato, permette di vedere il grafico definitivo. SCREEN schermo&
, , 1, 0 'le iscruzioni che seguono agiscono su schermo&, che e' visualizzato. istruzioni$ = "Premere INVIO per un nuovo calcolo, ESC per terminare."
the idea is the following:
on line 39 schermo& is set as the working page 1, while the visualized page is 0.
in line 46, page 1 is copied on page 0.
on line 47 grafico1& is set as the working page 2, while the visualized page is 0.
in line 56, page 2 is copied on page 0.
on line 57 schermo& is again set as the working page 1, while the visualized page is 0.
in line 62, page 1 is copied on page 0.
on line 64 grafico2& is set as the working page 3, while the visualized page is 0.
in line 80, page 3 is copied on page 0.
on line 81 schermo& is again set as the working page 1, while the visualized page is 0.
in line 96, page 1 is copied on page 0.
But It doesn't work.
I have done many attempts, for example:
on line 39 schermo& is set as the working page 1, while the visualized page is 0.
in line 46, page 1 is copied on page 0.
on line 47 grafico1& is set as the working page 2, while the visualized page is 0.
in line 56, page 2 is copied on page 0.
on line 57 schermo& is set as the working page 3, while the visualized page is 0.
in line 62, page 3 is copied on page 0.
on line 64 grafico2& is set as the working page 4, while the visualized page is 0.
in line 80, page 4 is copied on page 0.
on line 81 schermo& is again set as the working page 5, while the visualized page is 0.
in line 96, page 5 is copied on page 0.
I have also tried solutions with things like this:
PCOPY 3,2
PCOPY 2,1
PCOPY 1,0
Nothig.
Why?