Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first matrix
#1
Hi everyone

Showcase of first my matrix in NaaLaa.
Trying to simulate random grass. I hope it's not too bad. LOL.[Image: smile.png]


Code:
'my first matrix

constant:
  SCREENWIDTH 800
  SCREENHEIGHT 600


hidden:

set window 0, 0, SCREENWIDTH, SCREENHEIGHT, false
set redraw off
set color 0,0,0
cls

'matrix indexes begin at 0
m[SCREENWIDTH][SCREENHEIGHT][3]

'put rgb colors in matrix (size of screen)
for y=0 to SCREENHEIGHT-1
  for x=0 to SCREENWIDTH-1
    m[x][y][0]=rnd(100)
    m[x][y][1]=rnd(255)
    m[x][y][2]=rnd(100)
  next
next

'draw matrix to screen
for y=0 to SCREENHEIGHT-1
  for x=0 to SCREENWIDTH-1
    r=m[x][y][0]
    g=m[x][y][1]
    b=m[x][y][2]
    set color r,g,b
    draw pixel x,y
  next
next

set color 255,255,255
wln "Press space key to exit ..."

redraw

wait keydown
Reply
#2
Nice Grass, it looks cool, thanks for sharing.
Reply
#3
Hi everyone

Modified my original code. Now you can test the grass it in different resolutions. Just change values of SCREENWIDTH and SCREENHEIGHT constants. See code on top.[Image: wink.png]
Reply
#4
Looking very good Smile

I know you're playing with multidimensional arrays and that my tips may ruin the point of your program, but if you're interested in faster plotting you can use a single integer to store each RGB value.

Code:
'my first matrix
set window 0, 0, 320, 200, false,2
set redraw off
set color 0,0,0
cls

'matrix indexes begin at 0
m[320][200]
  for cnt = 1 to 200
        'put rgb colors in matrix (size of screen)   
      for y=0 to 199
        for x=0 to 319
          m[x][y] = (rnd(100) SHL 16) + (rnd(255) SHL 8) + rnd(100)
        next
      next

         'draw matrix to screen
      for y = 0 to 199
        for x= 0 to 319
          set colori m[x][y]
          draw pixel x,y
        next
      next
    redraw
   next
set color 255,255,255
wln "Press space key to exit ..."

redraw

wait keydown

 end

SHL is used to shift the bytes into the correct bit positions of the integers.

And if you want to speed it up even more, you can skip the matrix step altogether:

Code:
'my first matrix
set window 0, 0, 320, 200, false,2
set redraw off
set color 0,0,0
cls

  for cnt = 1 to 200
     'draw matrix to screen
      for y = 0 to 199
        for x= 0 to 319
          set colori (rnd(100) SHL 16) + (rnd(255) SHL 8) + rnd(100)
          set pixel x,y
        next
      next
    redraw
   next
set color 255,255,255
wln "Press space key to exit ..."

redraw

wait keydown

 end

Also, 'set pixel' is a little bit faster than 'draw pixel'.
Reply
#5
(06-15-2018, 08:58 PM)Rick3137 Wrote: Nice
 
 I'm still learning new tricks.

 That line of font / screen info didn't work on my Windows10. I suspect that it was for Linux.

Nah, that was just something that got messed up with the post Smile  I'll correct it
Reply
#6
(06-15-2018, 08:24 PM)Marcus Wrote: Looking very good Smile

I know you're playing with multidimensional arrays and that my tips may ruin the point of your program, but if you're interested in faster plotting you can use a single integer to store each RGB value.

Code:
'my first matrix
set window 0, 0, 320, 200, false,2
set redraw off
set color 0,0,0
cls

'matrix indexes begin at 0
m[320][200]
  for cnt = 1 to 200
        'put rgb colors in matrix (size of screen)   
      for y=0 to 199
        for x=0 to 319
          m[x][y] = (rnd(100) SHL 16) + (rnd(255) SHL 8) + rnd(100)
        next
      next

         'draw matrix to screen
      for y = 0 to 199
        for x= 0 to 319
          set colori m[x][y]
          draw pixel x,y
        next
      next
    redraw
   next
set color 255,255,255
wln "Press space key to exit ..."

redraw

wait keydown

 end

SHL is used to shift the bytes into the correct bit positions of the integers.

And if you want to speed it up even more, you can skip the matrix step altogether:

Code:
'my first matrix
set window 0, 0, 320, 200, false,2
set redraw off
set color 0,0,0
cls

  for cnt = 1 to 200
     'draw matrix to screen
      for y = 0 to 199
        for x= 0 to 319
          set colori (rnd(100) SHL 16) + (rnd(255) SHL 8) + rnd(100)
          set pixel x,y
        next
      next
    redraw
   next
set color 255,255,255
wln "Press space key to exit ..."

redraw

wait keydown

 end

Also, 'set pixel' is a little bit faster than 'draw pixel'.

Thanks Marcus. It's superfast plotting. I am getting news ideas for this. [Image: smile.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)