Posts: 36
Threads: 18
Joined: Jun 2018
Reputation:
0
06-15-2018, 11:44 AM
(This post was last modified: 06-15-2018, 04:48 PM by pedromartins.)
Hi everyone
Showcase of first my matrix in NaaLaa.
Trying to simulate random grass. I hope it's not too bad. LOL.
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
Posts: 85
Threads: 6
Joined: Jan 2018
Reputation:
1
Nice Grass, it looks cool, thanks for sharing.
Posts: 36
Threads: 18
Joined: Jun 2018
Reputation:
0
06-15-2018, 04:51 PM
(This post was last modified: 06-15-2018, 05:13 PM by pedromartins.)
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.
Posts: 579
Threads: 76
Joined: Jan 2018
Reputation:
16
06-15-2018, 08:24 PM
(This post was last modified: 06-15-2018, 09:30 PM by Marcus.)
Looking very good
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'.
Posts: 579
Threads: 76
Joined: Jan 2018
Reputation:
16
(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  I'll correct it
Posts: 36
Threads: 18
Joined: Jun 2018
Reputation:
0
(06-15-2018, 08:24 PM)Marcus Wrote: Looking very good 
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.
|