Page 1 of 1

Is there a easyer/faster way to draw 64 point from an array

Posted: Tue Jun 16, 2015 10:10 pm
by rob.keij
Is there a faster or easyer way to draw a 64 point curve ?
This is working ok but I think there must be a better way.

Code: Select all

v.drawCurve p_ch2,[
[	10	,	@c[0 ]]	,
[	15	,	@c[1 ]]	,
[	20	,	@c[2 ]]	,
[	25	,	@c[3 ]]	,
[	30	,	@c[4 ]]	,
[	35	,	@c[5 ]]	,
[	40	,	@c[6 ]]	,
[	45	,	@c[7 ]]	,
[	50	,	@c[8 ]]	,
[	55	,	@c[9 ]]	,
[	60	,	@c[10]]	,
[	65	,	@c[11]]	,
[	70	,	@c[12]]	,
[	75	,	@c[13]]	,
[	80	,	@c[14]]	,
[	85	,	@c[15]]	,
[	90	,	@c[16]]	,
[	95	,	@c[17]]	,
[	100	,	@c[18]]	,
[	105	,	@c[19]]	,
[	110	,	@c[20]]	,
[	115	,	@c[21]]	,
[	120	,	@c[22]]	,
[	125	,	@c[23]]	,
[	130	,	@c[24]]	,
[	135	,	@c[25]]	,
[	140	,	@c[26]]	,
[	145	,	@c[27]]	,
[	150	,	@c[28]]	,
[	155	,	@c[29]]	,
[	160	,	@c[30]]	,
[	165	,	@c[31]]	,
[	170	,	@c[32]]	,
[	175	,	@c[33]]	,
[	180	,	@c[34]]	,
[	185	,	@c[35]]	,
[	190	,	@c[36]]	,
[	195	,	@c[37]]	,
[	200	,	@c[38]]	,
[	205	,	@c[39]]	,
[	210	,	@c[40]]	,
[	215	,	@c[41]]	,
[	220	,	@c[42]]	,
[	225	,	@c[43]]	,
[	230	,	@c[44]]	,
[	235	,	@c[45]]	,
[	240	,	@c[46]]	,
[	245	,	@c[47]]	,
[	250	,	@c[48]]	,
[	255	,	@c[49]]	,
[	260	,	@c[50]]	,
[	265	,	@c[51]]	,
[	270	,	@c[52]]	,
[	275	,	@c[53]]	,
[	280	,	@c[54]]	,
[	285	,	@c[55]]	,
[	290	,	@c[56]]	,
[	295	,	@c[57]]	,
[	300	,	@c[58]]	,
[	305	,	@c[59]]	,
[	310	,	@c[60]]	,
[	315	,	@c[61]]	,
[	320	,	@c[62]]	,
[	325	,	@c[63]]	,


This was one of my trials ( :lol: )

Code: Select all

count   = 0

pointer = 0

v.drawCurve p_ch3,[
while count < 64
 [ @pointer +=10  , @c[count +=1]],
 end
]

Re: Is there a easyer/faster way to draw 64 point from an ar

Posted: Tue Jun 16, 2015 10:25 pm
by MyCo
maybe something along this:

Code: Select all

v.drawCurve(p_ch2, @c.map.with_index { |x,i| [i*5+10, x] })
not tested... just guessed

Re: Is there a easyer/faster way to draw 64 point from an ar

Posted: Tue Jun 16, 2015 10:37 pm
by rob.keij
Myco,

It works :roll:

I do my best to know more about the ruby posibilities but you are very fast in answering....

When do I receive your invoice?

Re: Is there a easyer/faster way to draw 64 point from an ar

Posted: Tue Jun 16, 2015 10:44 pm
by MyCo
rob.keij wrote:When do I receive your invoice?
No invoice, but I accept PayPal donations :mrgreen:

Re: Is there a easyer/faster way to draw 64 point from an ar

Posted: Tue Jun 16, 2015 11:03 pm
by tulamide
x seems to be a fixed list of values. If that's right, you can also create that list elsewhere (for example in init-method) and for drawing just call

v.drawCurve(p_ch2, @x_list.zip(@c))

where @x_list is your array of x-positions. This is faster than mapping, because you don't need to calculate the x-values on each redraw.