Author Topic: Stuck on Indicies  (Read 2936 times)

0 Members and 1 Guest are viewing this topic.

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 319
  • Karma: 25
  • Hard players don't go home.
    • View Profile
Stuck on Indicies
« on: March 21, 2013 »
I haven't quite got the hang of them yet.

This program (long version) shows what I want.

Code: [Select]
open window 640,512
go=1
starz1=100
starz2=100
dim x1(starz1)
dim y1(starz1)
dim r1(starz1)
dim g1(starz1)
dim b1(starz1)
dim x2(starz2)
dim y2(starz2)
dim r2(starz2)
dim g2(starz2)
dim b2(starz2)
for a=1 to starz1
x1(a)=int(ran(64))*10
y1(a)=int(ran(51))*10
r1(a)=ran(256)
g1(a)=ran(256)
b1(a)=ran(256)
next a
for a=1 to starz2
x2(a)=int(ran(64))*10
y2(a)=int(ran(51))*10
r2(a)=ran(256)
g2(a)=ran(256)
b2(a)=ran(256)
next a
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
setrgb 1,20,20,20
fill rectangle 0,0 to 640,512
go=go+1
if go>50 go=1
if go>1 and go<25 then
for a=1 to starz1
y1(a)=y1(a)+1
if y1(a)>515 y1(a)=-3
setrgb 1,r1(a),g1(a),b1(a)
fill circle x1(a),y1(a),2
'dot x1(a),y1(a)
next a
endif
if go>25 and go<50 then
for a=1 to starz2
y2(a)=y2(a)+1
if y2(a)>515 y2(a)=-3
setrgb 1,r2(a),g2(a),b2(a)
fill circle x2(a),y2(a),2
'dot x2(a),y2(a)
next a
endif
until (1=0)

In the attempted short version, I'm not getting my random colours.

Can anyone see what I'm missing?

Code: [Select]
open window 640,512 rem >.
go=1
starz=3
stars=100
dim r(starz),g(starz),b(starz)
dim x(stars,starz),y(stars,starz)
for a=1 to starz
r(a)=ran(256)
g(a)=ran(256)
b(a)=ran(256)
for c=1 to stars
x(c,a)=int(ran(64))*10
y(c,a)=int(ran(51))*10
next c
next a
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
go=go+1
if go>75 go=1
setrgb 1,20,20,20
fill rectangle 0,0 to 640,512
for a=1 to starz
setrgb 1,r(a),g(a),b(a)
for c=1 to stars
y(c,a)=y(c,a)+1
if y(c,a)>515 y(c,a)=-3
if go>1 and go<25 fill circle x(c,1),y(c,1),2
if go>25 and go<50 fill circle x(c,2),y(c,2),2
if go>50 and go<75 fill circle x(c,3),y(c,3),2
next c
next a
until (1=0)

Help!
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Stuck on Indicies
« Reply #1 on: March 21, 2013 »
hey bikemadness i dont think its so much a problem with the way your using arrays rather than a dont think yabasic uses a true random rand() func and everytime your code gets launched the 3 r(),g(),b() index's were getting filled with very similar values you can test this out with.

Code: [Select]
for a=1 to starz
r(1)=0 rem ran(256)
g(1)=255 rem ran(256)
b(1)=0 rem ran(256)
  r(2)=255 rem ran(256)
g(2)=0 rem ran(256)
b(2)=0 rem ran(256)
r(3)=0 rem ran(256)
g(3)=0 rem ran(256)
b(3)=255 rem ran(256)

for c=1 to stars
x(c,a)=int(ran(64))*10
y(c,a)=int(ran(51))*10
next c
next a

you see that by specifically setting the rgb values your program works! pointing to the problem coming from rand()





i personally like it more setting r() , g() , b() to have 100 index's like so
Code: [Select]
open window 640,512 rem >.

go=1
starz=3
stars=100

dim r(stars),g(stars),b(stars)
dim x(stars,starz),y(stars,starz)


for a=1 to starz

for c=1 to stars
r(c)= ran(256)
g(c)= ran(256)
b(c)= ran(256)
x(c,a)=int(ran(64))*10
y(c,a)=int(ran(51))*10
next c
next a


repeat

setdrawbuf vm
vm=1-vm
setdispbuf vm

clear window

go=go+1

if go>75 go=1

setrgb 1,20,20,20

fill rectangle 0,0 to 640,512

for a=1 to starz
for c=1 to stars
setrgb 1,r(c),g(c),b(c)
y(c,a)=y(c,a)+1
if y(c,a)>515 y(c,a)=-3
if go>1 and go<25 fill circle x(c,1),y(c,1),2
if go>25 and go<50 fill circle x(c,2),y(c,2),2
if go>50 and go<75 fill circle x(c,3),y(c,3),2
next c

next a

until (1=0)

because when you do this ran() has a better chance to start generating random numbers and you get nice variations in the colors.

now i seem to remember jim posting a small peice of code years ago over at ps2yabasic that either made ran() a lot more random or was a new ran() type function ill see if i can find it somewhere.
« Last Edit: March 21, 2013 by ninogenio »
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Stuck on Indicies
« Reply #2 on: March 21, 2013 »
found it :)
it was someone named parabelum who wrote this function, jim credited him in the original post so i thought i better too...

i have integrated it, too show you they do change color now i don't think its still the way you would like it too be yet but at least getting this small issue out the way should make it possible for you to craft it now.


Code: [Select]
open window 640,512 rem >.

randomize()

go=1
starz=3
stars=100
dim r(starz),g(starz),b(starz)
dim x(stars,starz),y(stars,starz)
for a=1 to starz
r(a)=ran(256)
g(a)=ran(256)
b(a)=ran(256)
for c=1 to stars
x(c,a)=int(ran(64))*10
y(c,a)=int(ran(51))*10
next c
next a
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
go=go+1
if go>75 go=1
setrgb 1,20,20,20
fill rectangle 0,0 to 640,512
for a=1 to starz
setrgb 1,r(a),g(a),b(a)
for c=1 to stars
y(c,a)=y(c,a)+1
if y(c,a)>515 y(c,a)=-3
if go>1 and go<25 fill circle x(c,1),y(c,1),2
if go>25 and go<50 fill circle x(c,2),y(c,2),2
if go>50 and go<75 fill circle x(c,3),y(c,3),2
next c
next a
until (1=0)


sub randomize()
d=1
rnd$=left$(date$,13)+left$(time$,8) 
for i=len(rnd$) to 1 step -1 
for j=d*i*asc(mid$(rnd$,i,1))/3.75 to 0 step -1       
k = ran(100)   
next   
d = 1+k/100 
next
end sub
Challenge Trophies Won:

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 319
  • Karma: 25
  • Hard players don't go home.
    • View Profile
Re: Stuck on Indicies
« Reply #3 on: March 22, 2013 »
Thanks. Small as it was, it wasn't an issue, because it didn't work.

Yes. I know about about the true random that the PS2 console demo disk gave.
In this case, having a set random helps me.

What also helps me is to have my lines of code in the order that they happen.

I've managed to solve my original problem.

Code: [Select]
open window 640,512 rem >.
go=1
starz=3
stars=100
dim r(stars,starz),g(stars,starz),b(stars,starz)
dim x(stars,starz),y(stars,starz)
for a=1 to starz
for c=1 to stars
r(c,a)=ran(256)
g(c,a)=ran(256)
b(c,a)=ran(256)
x(c,a)=int(ran(64))*10
y(c,a)=int(ran(51))*10
next c
next a
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
go=go+1
if go>75 go=1
setrgb 1,20,20,20
fill rectangle 0,0 to 640,512
for a=1 to starz
for c=1 to stars
y(c,a)=y(c,a)+1
if y(c,a)>515 y(c,a)=-3
setrgb 1,r(c,a),g(c,a),b(c,a)
if go>1 and go<25 fill circle x(c,1),y(c,1),2
if go>25 and go<50 fill circle x(c,2),y(c,2),2
if go>50 and go<75 fill circle x(c,3),y(c,3),2
next c
next a
until (1=0)
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.