Author Topic: How create a scrolling down graphic ?  (Read 1682 times)

0 Members and 1 Guest are viewing this topic.

Offline acjacques

  • Newbie
  • Posts: 33
How create a scrolling down graphic ?
« on: October 09, 2019, 03:45:41 pm »
Hello people
I'm a newbie to QB64 and would like some help from the experts

I want to create a continuously scrolling top-down graphical window
I thought of the following algorithm:

do
10 draw a variable color line according to a value read from a sensor in the first row
20 copy entire screen
30 paste the captured image from second row to botton less one row
loop
 

each new reading sensor is always plotted on the first row
always copying the entire screen
always pasting from the  second row to bellow and discarding the last row


What are the best functions and commands to perform this?

I want to work with 1200 x 800 screen  x RGB  256 bits depth  each color

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: How create a scrolling down graphic ?
« Reply #1 on: October 09, 2019, 04:38:42 pm »
Hi. Use _PUTIMAGE. Better (or easyest) is using two pictures below each other:

Code: QB64: [Select]
  1. image = _NEWIMAGE(320, 480, 32)
  2. _PUTIMAGE (0, 0)-(319, 239), _SCREENIMAGE, image
  3. _PUTIMAGE (0, 240)-(319, 479), _SCREENIMAGE, image
  4. SCREEN _NEWIMAGE(800, 600, 32)
  5.  
  6.  
  7. S = 240
  8.     'area for viewing: 200, 200 to 520, 440
  9.  
  10.     LINE (200, 200)-(520, 440), &HFF000000, BF
  11.     S = S + 1: IF S > 480 THEN S = 240
  12.     _PUTIMAGE (200, 200)-(520, 440), image, 0, (0, S - 240)-(319, S)
  13.     _DISPLAY
  14.     _LIMIT 50
  15.  


or second direction:


Code: QB64: [Select]
  1. image = _NEWIMAGE(320, 480, 32)
  2. _PUTIMAGE (0, 0)-(319, 239), _SCREENIMAGE, image
  3. _PUTIMAGE (0, 240)-(319, 479), _SCREENIMAGE, image
  4. SCREEN _NEWIMAGE(800, 600, 32)
  5.  
  6.  
  7. S = 480
  8.     'area for viewing graphic: 200, 200 to 520, 440
  9.  
  10.     LINE (200, 200)-(520, 440), &HFF000000, BF
  11.     S = S - 1: IF S < 240 THEN S = 480
  12.     _PUTIMAGE (200, 200)-(520, 440), image, 0, (0, S - 240)-(319, S)
  13.     _DISPLAY
  14.     _LIMIT 50
  15.  

Welcome to forum!
« Last Edit: October 09, 2019, 04:42:37 pm by Petr »

Offline acjacques

  • Newbie
  • Posts: 33
Re: How create a scrolling down graphic ?
« Reply #2 on: October 09, 2019, 08:15:48 pm »
Hi Petr;

Thanks for your sample. But I could not understand well.

It seems to first copy a part of computer screen , not my window.

What I need is  draw a line with random  colors in the first line,
then go adding new lines at the top and the image rolling down.
At each image capture the last line drawn at first line will be added at the top of rolling image.
the code I was trying
 

SCREEN _NEWIMAGE(1200, 800, 32)   'this is my screen

DO
    cor1 = INT(RND * 255) 'randomize colors
    cor2 = INT(RND * 255)
    cor3 = INT(RND * 255)

    LINE (0, 0)-(1200, 0), _RGB(cor1, cor2, cor3)       'creates a random color line in the first row

  * i need put here a command to copy the entire screen (1200x800) with the above line ploted
  * i need put here a command to paste the  captured image just one row bellow (2nd line) to the botton (botton line of the image will be discarded) (1200x799)
 
LOOP

A help will be very appreciated.
Thanks

 


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: How create a scrolling down graphic ?
« Reply #3 on: October 09, 2019, 09:43:49 pm »
Nothing fancy needed but an array to store colors:
Code: QB64: [Select]
  1. _TITLE "Scrolling Plasma Lines, press spacebar for new colors" 'B+ 2019-10-09
  2. CONST xmax = 800, ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5. DIM ln(0 TO ymax) AS _UNSIGNED LONG
  6. r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  7.     IF INKEY$ = " " THEN r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  8.     FOR i = UBOUND(ln) - 1 TO 0 STEP -1
  9.         ln(i + 1) = ln(i)
  10.         LINE (0, i)-STEP(xmax, 1), ln(i + 1), BF
  11.     NEXT
  12.     ln(0) = _RGB32(127 + 127 * SIN(r * c), 127 + 127 * SIN(g * c), 127 + 127 * SIN(b * c))
  13.     c = c + 1
  14.     _DISPLAY
  15.     _LIMIT 60
  16.  
« Last Edit: October 09, 2019, 09:45:26 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: How create a scrolling down graphic ?
« Reply #4 on: October 10, 2019, 05:59:02 am »
Is something like this what you're talking about doing?

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1200, 800, 256) 'size and color palette described in post
  2.  
  3. 'draw some stuff on the screen
  4. LINE (100, 100)-(700, 700), 40, BF
  5. CIRCLE (600, 600), 400, 25
  6. PAINT (600, 600), 25
  7. LINE (1000, 200)-(1200, 800), 123, BF
  8.  
  9. SLEEP 'so we can see the sceen
  10. temp = _COPYIMAGE(0) 'copy the current screen to preserve it
  11.     y = y + 1 'implement a counter to scroll the screen
  12.     IF y > _HEIGHT THEN y = 0
  13.     'put part of the preserved screen back
  14.     _PUTIMAGE (0, y)-(1199, 799), temp, 0, (0, 0)-(1199, 800 - y) 'one half of the screen
  15.     _PUTIMAGE (0, 0)-(1199, y), temp, 0, (0, 800 - y)-(1199, 799) 'the other half
  16.     _LIMIT 240
  17.     _DISPLAY
  18.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: How create a scrolling down graphic ?
« Reply #5 on: October 10, 2019, 09:02:26 am »
Quote
Hi Petr;

Thanks for your sample. But I could not understand well.

It seems to first copy a part of computer screen , not my window.

What I need is  draw a line with random  colors in the first line,
then go adding new lines at the top and the image rolling down.
At each image capture the last line drawn at first line will be added at the top of rolling image.
the code I was trying
 

SCREEN _NEWIMAGE(1200, 800, 32)   'this is my screen

DO
    cor1 = INT(RND * 255) 'randomize colors
    cor2 = INT(RND * 255)
    cor3 = INT(RND * 255)

    LINE (0, 0)-(1200, 0), _RGB(cor1, cor2, cor3)       'creates a random color line in the first row

  * i need put here a command to copy the entire screen (1200x800) with the above line ploted
  * i need put here a command to paste the  captured image just one row bellow (2nd line) to the botton (botton line of the image will be discarded) (1200x799)
 
LOOP

A help will be very appreciated.
Thanks




Hi. For best outputs in graphic use arrays.

Code: QB64: [Select]
  1.  
  2. SCREEN _NEWIMAGE(1200, 800, 32) '                       this is my screen
  3. '                           your screen height is 800. So, let say, one colored quad height is 10. So you need draw 80 colored quads:
  4. DIM Quads(1 TO 80) AS _UNSIGNED LONG '                  80 values (Quads(0) is also value nd is not used now)
  5. DIM Y(1 TO 80) AS INTEGER '                             Y coordinate for quads
  6.  
  7. 'why DIM: if is needed many variables, you can write: A1 = 10, A2 = 20... A1000 = 70. OR A(number for A) = value
  8. 'why _UNSIGNED LONG: 32 bit colors used on 32 bit screens use this _UNSIGNED LONG type values.
  9.  
  10. 'set random colors:
  11.  
  12. FOR set = 1 TO 80
  13.     Quads(set) = _RGBA32(255, RND * 255, RND * 255, RND * 255) ' _RGBA32 (Alha transparency 0 to 255, 255 is full visible, red 0 to 255, green 0 to 255, blue 0 to 255)
  14.     Y(set) = (set - 1) * 10 'set start Y coordinate
  15. NEXT set
  16.  
  17. 'your choice is starting with full screen. So first step - placing quads to screen:
  18. DO UNTIL _KEYHIT = 27 'ESC for end
  19.     CLS
  20.     FOR P = 1 TO 80
  21.         LINE (0, Y(P))-(1199, Y(P) + 10), Quads(P), BF ' LINE (startX, startY) - (endX, endY (quad size is 10 pixels)), Unsigned Long color value, BF = filled quad
  22.         Y(P) = Y(P) + 10 'increase Y position for quad
  23.         IF Y(P) > 800 THEN Y(P) = 0 'if is Y on bottom, return it to above
  24.     NEXT
  25.  
  26.     'SLEEP
  27.     'if you place here SLEEP, you can see program start
  28.  
  29.     _DISPLAY 'kill flickering
  30.     _LIMIT 30 'save CPU time
  31.  
  32.  


If you are interrested, goto qb64 wikipedia and read about _PUTIMAGE and _MAPTRIANGLE.

Offline acjacques

  • Newbie
  • Posts: 33
Re: How create a scrolling down graphic ?
« Reply #6 on: October 10, 2019, 10:15:00 am »
Dear Friends
Thanks . Was not exactly but helps a lot.

Now is my simple working code:

SCREEN _NEWIMAGE(1200, 800, 32)

COL = 0
LIN = 0 'line

DO
    cor1 = INT(RND * 255) 'randomize color   'in future is here were my sensor values will be 
    cor2 = INT(RND * 255)
    cor3 = INT(RND * 255)

    LINE (COL, LIN)-(1200, LIN), _RGB(cor1, cor2, cor3) 'creates a random color line in the first row 

    temp = _COPYIMAGE(0) 'copy the current screen

    _PUTIMAGE (0, 1), temp 'place the image 1 row below

    _LIMIT 60 'timing
    _DISPLAY ' to avoid flicker
    _FREEIMAGE temp 'release memory

LOOP

Offline acjacques

  • Newbie
  • Posts: 33
Re: How create a scrolling down graphic ?
« Reply #7 on: October 16, 2019, 05:59:18 am »
Code: QB64: [Select]
  1. ['SCROLLING DOWN SCREEN WITH RANDOM COLORS
  2. 'ACJacques  acj@infolink.com.br
  3.  
  4. SCREEN _NEWIMAGE(1200, 800, 32)
  5.  
  6. COL = 0
  7. LIN = 0 'line
  8.  
  9.     cor1 = INT(RND * 255) 'randomize color   'in future my sensor values will be here
  10.     cor2 = INT(RND * 255)
  11.     cor3 = INT(RND * 255)
  12.  
  13.     LINE (COL, LIN)-(1200, LIN), _RGB(cor1, cor2, cor3) 'creates a random color line in the first row
  14.  
  15.     temp = _COPYIMAGE(0) 'copy the current screen
  16.  
  17.     _PUTIMAGE (0, 1), temp 'place the image 1 row below
  18.  
  19.     _LIMIT 60 'timing
  20.     _DISPLAY ' to avoid flicker
  21.     _FREEIMAGE temp 'release memory
  22.  
  23. END/code]
« Last Edit: October 16, 2019, 06:06:01 am by acjacques »