Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #33005 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2017-04-14 11:49 -0700 |
| Last post | 2017-04-24 13:27 -0700 |
| Articles | 8 on this page of 68 — 11 participants |
Back to article view | Back to comp.lang.javascript
Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-14 11:49 -0700
Re: Javascripts and highlevel computer language programming of graphics John G Harris <niam@jghnorth.org.uk.invalid> - 2017-04-15 11:07 +0100
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-15 11:52 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-15 12:04 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-15 14:52 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-15 15:04 -0700
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-16 00:09 +0200
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-15 15:18 -0700
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-16 11:27 +0200
Re: Javascripts and highlevel computer language programming of graphics <cyber@2trom.com> - 2017-04-16 15:08 +0000
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-16 20:47 +0200
Re: Javascripts and highlevel computer language programming of graphics Gene Wirchenko <genew@telus.net> - 2017-04-17 10:02 -0700
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-17 23:46 +0200
Re: Javascripts and highlevel computer language programming of graphics Gene Wirchenko <genew@telus.net> - 2017-04-18 17:39 -0700
Re: Javascripts and highlevel computer language programming of graphics Andrew Poulos <ap_prog@hotmail.com> - 2017-04-19 11:25 +1000
Re: Javascripts and highlevel computer language programming of graphics Bob Martin <bob.martin@excite.com> - 2017-04-19 07:30 +0100
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-19 12:13 +0200
Re: Javascripts and highlevel computer language programming of graphics Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-04-19 13:58 +0200
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-19 17:20 +0200
Re: Javascripts and highlevel computer language programming of graphics Gene Wirchenko <genew@telus.net> - 2017-04-19 10:00 -0700
Re: Javascripts and highlevel computer language programming of graphics <cyber@2trom.com> - 2017-04-20 12:33 +0000
Re: Javascripts and highlevel computer language programming of graphics Gene Wirchenko <genew@telus.net> - 2017-04-20 11:39 -0700
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-20 21:24 +0200
Re: Javascripts and highlevel computer language programming of graphics Gene Wirchenko <genew@telus.net> - 2017-04-21 11:57 -0700
Re: Javascripts and highlevel computer language programming of graphics Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-04-21 18:37 +0200
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-19 12:00 +0200
Re: Javascripts and highlevel computer language programming of graphics Gene Wirchenko <genew@telus.net> - 2017-04-19 10:03 -0700
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-20 00:07 +0200
Re: Javascripts and highlevel computer language programming of graphics Gene Wirchenko <genew@telus.net> - 2017-04-19 17:21 -0700
Re: Javascripts and highlevel computer language programming of graphics Andrew Poulos <ap_prog@hotmail.com> - 2017-04-20 15:54 +1000
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-20 08:46 +0200
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-20 08:43 +0200
Re: Javascripts and highlevel computer language programming of graphics Gene Wirchenko <genew@telus.net> - 2017-04-20 11:42 -0700
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-20 21:37 +0200
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-21 03:23 -0700
Re: Javascripts and highlevel computer language programming of graphics Andrew Poulos <ap_prog@hotmail.com> - 2017-04-22 16:21 +1000
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-22 12:15 +0200
Re: Javascripts and highlevel computer language programming of graphics Gene Wirchenko <genew@telus.net> - 2017-04-21 11:58 -0700
Re: Javascripts and highlevel computer language programming of graphics <cyber@2trom.com> - 2017-04-17 13:01 +0000
Re: Javascripts and highlevel computer language programming of graphics Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-04-17 20:28 +0200
Re: Javascripts and highlevel computer language programming of graphics bit-naughty@hotmail.com - 2017-04-19 23:50 -0700
Re: Javascripts and highlevel computer language programming of graphics Andrew Poulos <ap_prog@hotmail.com> - 2017-04-20 19:02 +1000
Re: Javascripts and highlevel computer language programming of graphics "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-04-20 11:24 +0200
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-15 15:14 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-15 15:24 -0700
Re: Javascripts and highlevel computer language programming of graphics John G Harris <niam@jghnorth.org.uk.invalid> - 2017-04-17 10:49 +0100
Re: Javascripts and highlevel computer language programming of graphics RobG <rgqld@iinet.net.au> - 2017-04-23 08:39 +1000
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-22 15:46 -0700
Re: Javascripts and highlevel computer language programming of graphics John G Harris <niam@jghnorth.org.uk.invalid> - 2017-04-23 15:29 +0100
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-23 09:47 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-23 09:57 -0700
Re: Javascripts and highlevel computer language programming of graphics John G Harris <niam@jghnorth.org.uk.invalid> - 2017-04-24 11:09 +0100
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 05:26 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 05:32 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 05:36 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 05:44 -0700
Re: Javascripts and highlevel computer language programming of graphics John G Harris <niam@jghnorth.org.uk.invalid> - 2017-04-24 15:12 +0100
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 10:12 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-23 09:49 -0700
Re: Javascripts and highlevel computer language programming of graphics John G Harris <niam@jghnorth.org.uk.invalid> - 2017-04-24 11:10 +0100
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 12:07 -0700
Re: Javascripts and highlevel computer language programming of graphics Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-24 21:24 +0100
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 13:32 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 13:41 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 13:56 -0700
Re: Javascripts and highlevel computer language programming of graphics John G Harris <niam@jghnorth.org.uk.invalid> - 2017-04-25 10:41 +0100
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-26 12:15 -0700
Re: Javascripts and highlevel computer language programming of graphics jonas.thornvall@gmail.com - 2017-04-24 13:27 -0700
Page 4 of 4 — ← Prev page 1 2 3 [4]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 12:07 -0700 |
| Message-ID | <48cfe37e-e2b5-4d29-b5a7-0bc6c0f5a34c@googlegroups.com> |
| In reply to | #33095 |
Den söndag 23 april 2017 kl. 16:29:26 UTC+2 skrev John G Harris:
> On Sat, 22 Apr 2017 15:46:53 -0700 (PDT), jonas.thornvall@gmail.com
> wrote:
>
> >Den söndag 23 april 2017 kl. 00:39:50 UTC+2 skrev RobG:
> >> On 17/04/2017 19:49, John G Harris wrote:
> >> [...]
> >> > For the paint_graph function it looks as though only one of the
> >> > markers can be true at a time. You could use a code instead and use it
> >> > to address an array of functions.
> >> >
> >> > var fd = [markDraw, moveDraw, boundariesDraw, reshapeDraw];
> >> >
> >> > // if m is the code, call the required function by :
> >> > fd.m();
> >>
> >> Or if "m is the code" means m is a variable to which the code is
> >> assigned, then perhaps:
> >>
> >> var m = /* expression to generate required code */
> >>
> >> fd[m]();
> <snip>
>
> Sorry Jonas, I must have written it in a hurry. The dot notation can't
> be used for this purpose.
>
> Here are two examples that work.
> First, using an array.
>
> /***************/
> function al(){return "alpha"};
> function be(){return "beta"};
> function ga(){return "gamma"};
>
> var fd = [al, be, ga];
> var m;
>
> m = 1;
> alert( fd[m]() );
>
> m = 2;
> alert( fd[m]() );
> /***************/
>
>
> Second, using an object.
>
> /***************/
> function fal(){return "alpha"};
> function fbe(){return "beta"};
> function fga(){return "gamma"};
>
> var fd = {al: fal, be: fbe, ga: fga};
> var m;
>
> m = "be";
> alert( fd[m]() );
>
> m = "ga";
> alert( fd[m]() );
> /***************/
>
> John
I have tried your approach i get a type error
TypeError: callfunctions[m] is not a function
at redraw (6PAINTCANVAS.4
// Paint logic *here i call redraw
function redraw() {
// Redraw graph every x-th millisec
for (var m=0;m<callfunctions.length;m++) {callfunctions[m]()} //TYPEERROR
}
//This is in init *global*
callfunctions = new Array();
//HERE I BUILD UP CANVAS *HARDCODED* probably should use push...
function build_canvas(arr) {
callfunctions[0]=back_ground;
if (grid==true) { callfunctions[1]=graphBackground; }
if (markarea == true) {
callfunctions[2]=markDraw;
} else if (moveit == true) {
callfunctions[2]=moveDraw;
} else if (reshape == true) {
callfunctions[2]=boundariesDraw;
} else if (doreshape == true) {
callfunctions[2]=reshapeDraw;
} else if (holdbezier1==true){
callfunctions[2]=moveBezierDraw1;
} else if (holdbezier2==true){
callfunctions[2]=moveBezierDraw2;
}
callfunctions[3]=graphDraw;
if (handles==true){
callfunctions[4]=nodeDraw;
}
callfunctions[4]=paint_message;
}
And i am sure i call build array before i start to draw.
// Start animation "form"
function startanime() {
//Start animation
message2 = "";
build_canvas(arr);
refresh = setInterval(redraw, 33);
}
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-04-24 21:24 +0100 |
| Message-ID | <87k269zh7z.fsf@bsb.me.uk> |
| In reply to | #33108 |
jonas.thornvall@gmail.com writes:
<snip>
> I have tried your approach i get a type error
>
> TypeError: callfunctions[m] is not a function
> at redraw (6PAINTCANVAS.4
>
> // Paint logic *here i call redraw
> function redraw() {
> // Redraw graph every x-th millisec
> for (var m=0;m<callfunctions.length;m++) {callfunctions[m]()} //TYPEERROR
This tries to call all the elements of the array...
> }
>
> //This is in init *global*
> callfunctions = new Array();
>
> //HERE I BUILD UP CANVAS *HARDCODED* probably should use push...
> function build_canvas(arr) {
> callfunctions[0]=back_ground;
>
> if (grid==true) { callfunctions[1]=graphBackground; }
but if grid is false, callfunctions[1] will not be a function.
> if (markarea == true) {
> callfunctions[2]=markDraw;
> } else if (moveit == true) {
> callfunctions[2]=moveDraw;
> } else if (reshape == true) {
> callfunctions[2]=boundariesDraw;
> } else if (doreshape == true) {
> callfunctions[2]=reshapeDraw;
> } else if (holdbezier1==true){
> callfunctions[2]=moveBezierDraw1;
> } else if (holdbezier2==true){
> callfunctions[2]=moveBezierDraw2;
> }
The same could also happen with callfunctions[2] depending on the
outcome of all these tests.
> callfunctions[3]=graphDraw;
>
> if (handles==true){
> callfunctions[4]=nodeDraw;
> }
>
> callfunctions[4]=paint_message;
This is odd. There's no point in setting callfunctions[4]=nodeDraw of
you are going to assign a different value immediately afterwards.
> }
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 13:32 -0700 |
| Message-ID | <28918937-7d79-4cc5-8337-7e835944da26@googlegroups.com> |
| In reply to | #33109 |
Den måndag 24 april 2017 kl. 22:25:01 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> <snip>
> > I have tried your approach i get a type error
> >
> > TypeError: callfunctions[m] is not a function
> > at redraw (6PAINTCANVAS.4
> >
> > // Paint logic *here i call redraw
> > function redraw() {
> > // Redraw graph every x-th millisec
> > for (var m=0;m<callfunctions.length;m++) {callfunctions[m]()} //TYPEERROR
>
> This tries to call all the elements of the array...
>
> > }
> >
> > //This is in init *global*
> > callfunctions = new Array();
> >
> > //HERE I BUILD UP CANVAS *HARDCODED* probably should use push...
> > function build_canvas(arr) {
> > callfunctions[0]=back_ground;
> >
> > if (grid==true) { callfunctions[1]=graphBackground; }
>
> but if grid is false, callfunctions[1] will not be a function.
>
> > if (markarea == true) {
> > callfunctions[2]=markDraw;
> > } else if (moveit == true) {
> > callfunctions[2]=moveDraw;
> > } else if (reshape == true) {
> > callfunctions[2]=boundariesDraw;
> > } else if (doreshape == true) {
> > callfunctions[2]=reshapeDraw;
> > } else if (holdbezier1==true){
> > callfunctions[2]=moveBezierDraw1;
> > } else if (holdbezier2==true){
> > callfunctions[2]=moveBezierDraw2;
> > }
>
> The same could also happen with callfunctions[2] depending on the
> outcome of all these tests.
>
> > callfunctions[3]=graphDraw;
> >
> > if (handles==true){
> > callfunctions[4]=nodeDraw;
> > }
> >
> > callfunctions[4]=paint_message;
>
> This is odd. There's no point in setting callfunctions[4]=nodeDraw of
> you are going to assign a different value immediately afterwards.
>
> > }
>
> <snip>
> --
> Ben.
You are correct Ben that would be 5, i must find a way to see if the approach is faster. Some of the logic seem changed with it so not everything works, but first i would like to make some sort of speed comparisson, to see if it really worth the effort.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 13:41 -0700 |
| Message-ID | <49f74d70-2688-4730-95c1-64fd3e55be2e@googlegroups.com> |
| In reply to | #33111 |
Den måndag 24 april 2017 kl. 22:32:14 UTC+2 skrev jonas.t...@gmail.com:
> Den måndag 24 april 2017 kl. 22:25:01 UTC+2 skrev Ben Bacarisse:
> > jonas.thornvall@gmail.com writes:
> > <snip>
> > > I have tried your approach i get a type error
> > >
> > > TypeError: callfunctions[m] is not a function
> > > at redraw (6PAINTCANVAS.4
> > >
> > > // Paint logic *here i call redraw
> > > function redraw() {
> > > // Redraw graph every x-th millisec
> > > for (var m=0;m<callfunctions.length;m++) {callfunctions[m]()} //TYPEERROR
> >
> > This tries to call all the elements of the array...
> >
> > > }
> > >
> > > //This is in init *global*
> > > callfunctions = new Array();
> > >
> > > //HERE I BUILD UP CANVAS *HARDCODED* probably should use push...
> > > function build_canvas(arr) {
> > > callfunctions[0]=back_ground;
> > >
> > > if (grid==true) { callfunctions[1]=graphBackground; }
> >
> > but if grid is false, callfunctions[1] will not be a function.
> >
> > > if (markarea == true) {
> > > callfunctions[2]=markDraw;
> > > } else if (moveit == true) {
> > > callfunctions[2]=moveDraw;
> > > } else if (reshape == true) {
> > > callfunctions[2]=boundariesDraw;
> > > } else if (doreshape == true) {
> > > callfunctions[2]=reshapeDraw;
> > > } else if (holdbezier1==true){
> > > callfunctions[2]=moveBezierDraw1;
> > > } else if (holdbezier2==true){
> > > callfunctions[2]=moveBezierDraw2;
> > > }
> >
> > The same could also happen with callfunctions[2] depending on the
> > outcome of all these tests.
> >
> > > callfunctions[3]=graphDraw;
> > >
> > > if (handles==true){
> > > callfunctions[4]=nodeDraw;
> > > }
> > >
> > > callfunctions[4]=paint_message;
> >
> > This is odd. There's no point in setting callfunctions[4]=nodeDraw of
> > you are going to assign a different value immediately afterwards.
> >
> > > }
> >
> > <snip>
> > --
> > Ben.
>
> You are correct Ben that would be 5, i must find a way to see if the approach is faster. Some of the logic seem changed with it so not everything works, but first i would like to make some sort of speed comparisson, to see if it really worth the effort.
Well most of the errors seem to be with the fact that my list of called functions never changed because startanimate that hold canvas rebuild only called 1 time. Instead i will use mouse down/up to start and stop animation i think it will work. And that terrible noise of rendering in earphones will stop ;), well unless i do mousedown.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 13:56 -0700 |
| Message-ID | <c3cfa2c1-ae00-4ed2-9122-db51b9c8d5ad@googlegroups.com> |
| In reply to | #33112 |
Den måndag 24 april 2017 kl. 22:41:09 UTC+2 skrev jonas.t...@gmail.com:
> Den måndag 24 april 2017 kl. 22:32:14 UTC+2 skrev jonas.t...@gmail.com:
> > Den måndag 24 april 2017 kl. 22:25:01 UTC+2 skrev Ben Bacarisse:
> > > jonas.thornvall@gmail.com writes:
> > > <snip>
> > > > I have tried your approach i get a type error
> > > >
> > > > TypeError: callfunctions[m] is not a function
> > > > at redraw (6PAINTCANVAS.4
> > > >
> > > > // Paint logic *here i call redraw
> > > > function redraw() {
> > > > // Redraw graph every x-th millisec
> > > > for (var m=0;m<callfunctions.length;m++) {callfunctions[m]()} //TYPEERROR
> > >
> > > This tries to call all the elements of the array...
> > >
> > > > }
> > > >
> > > > //This is in init *global*
> > > > callfunctions = new Array();
> > > >
> > > > //HERE I BUILD UP CANVAS *HARDCODED* probably should use push...
> > > > function build_canvas(arr) {
> > > > callfunctions[0]=back_ground;
> > > >
> > > > if (grid==true) { callfunctions[1]=graphBackground; }
> > >
> > > but if grid is false, callfunctions[1] will not be a function.
> > >
> > > > if (markarea == true) {
> > > > callfunctions[2]=markDraw;
> > > > } else if (moveit == true) {
> > > > callfunctions[2]=moveDraw;
> > > > } else if (reshape == true) {
> > > > callfunctions[2]=boundariesDraw;
> > > > } else if (doreshape == true) {
> > > > callfunctions[2]=reshapeDraw;
> > > > } else if (holdbezier1==true){
> > > > callfunctions[2]=moveBezierDraw1;
> > > > } else if (holdbezier2==true){
> > > > callfunctions[2]=moveBezierDraw2;
> > > > }
> > >
> > > The same could also happen with callfunctions[2] depending on the
> > > outcome of all these tests.
> > >
> > > > callfunctions[3]=graphDraw;
> > > >
> > > > if (handles==true){
> > > > callfunctions[4]=nodeDraw;
> > > > }
> > > >
> > > > callfunctions[4]=paint_message;
> > >
> > > This is odd. There's no point in setting callfunctions[4]=nodeDraw of
> > > you are going to assign a different value immediately afterwards.
> > >
> > > > }
> > >
> > > <snip>
> > > --
> > > Ben.
> >
> > You are correct Ben that would be 5, i must find a way to see if the approach is faster. Some of the logic seem changed with it so not everything works, but first i would like to make some sort of speed comparisson, to see if it really worth the effort.
>
> Well most of the errors seem to be with the fact that my list of called functions never changed because startanimate that hold canvas rebuild only called 1 time. Instead i will use mouse down/up to start and stop animation i think it will work. And that terrible noise of rendering in earphones will stop ;), well unless i do mousedown.
An annoyance is that since the function calls can make the array length differ i would have to push and pop elements. But i think i cheat that to start with using function empty(){}
Or is there another way to tell interpretator that sometimes an element have no function AKA callfunctions[m]==undefined? when using callfunctions[m]()
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2017-04-25 10:41 +0100 |
| Message-ID | <o46ufc59f0dbl2nhevo0hv2i5g5stcof55@4ax.com> |
| In reply to | #33113 |
On Mon, 24 Apr 2017 13:56:20 -0700 (PDT), jonas.thornvall@gmail.com
wrote:
<snip>
>An annoyance is that since the function calls can make the array length differ i would have to push and pop elements. But i think i cheat that to start with using function empty(){}
Writing to the array's length property changes the arrray's size,
deleting elements if necessary.
>Or is there another way to tell interpretator that sometimes an element have no function AKA callfunctions[m]==undefined? when using callfunctions[m]()
Or you could define a no_op function that does nothing.
John
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-26 12:15 -0700 |
| Message-ID | <331fd048-df5c-42cf-976b-85766c8042f0@googlegroups.com> |
| In reply to | #33113 |
Den måndag 24 april 2017 kl. 22:56:25 UTC+2 skrev jonas.t...@gmail.com:
> Den måndag 24 april 2017 kl. 22:41:09 UTC+2 skrev jonas.t...@gmail.com:
> > Den måndag 24 april 2017 kl. 22:32:14 UTC+2 skrev jonas.t...@gmail.com:
> > > Den måndag 24 april 2017 kl. 22:25:01 UTC+2 skrev Ben Bacarisse:
> > > > jonas.thornvall@gmail.com writes:
> > > > <snip>
> > > > > I have tried your approach i get a type error
> > > > >
> > > > > TypeError: callfunctions[m] is not a function
> > > > > at redraw (6PAINTCANVAS.4
> > > > >
> > > > > // Paint logic *here i call redraw
> > > > > function redraw() {
> > > > > // Redraw graph every x-th millisec
> > > > > for (var m=0;m<callfunctions.length;m++) {callfunctions[m]()} //TYPEERROR
> > > >
> > > > This tries to call all the elements of the array...
> > > >
> > > > > }
> > > > >
> > > > > //This is in init *global*
> > > > > callfunctions = new Array();
> > > > >
> > > > > //HERE I BUILD UP CANVAS *HARDCODED* probably should use push...
> > > > > function build_canvas(arr) {
> > > > > callfunctions[0]=back_ground;
> > > > >
> > > > > if (grid==true) { callfunctions[1]=graphBackground; }
> > > >
> > > > but if grid is false, callfunctions[1] will not be a function.
> > > >
> > > > > if (markarea == true) {
> > > > > callfunctions[2]=markDraw;
> > > > > } else if (moveit == true) {
> > > > > callfunctions[2]=moveDraw;
> > > > > } else if (reshape == true) {
> > > > > callfunctions[2]=boundariesDraw;
> > > > > } else if (doreshape == true) {
> > > > > callfunctions[2]=reshapeDraw;
> > > > > } else if (holdbezier1==true){
> > > > > callfunctions[2]=moveBezierDraw1;
> > > > > } else if (holdbezier2==true){
> > > > > callfunctions[2]=moveBezierDraw2;
> > > > > }
> > > >
> > > > The same could also happen with callfunctions[2] depending on the
> > > > outcome of all these tests.
> > > >
> > > > > callfunctions[3]=graphDraw;
> > > > >
> > > > > if (handles==true){
> > > > > callfunctions[4]=nodeDraw;
> > > > > }
> > > > >
> > > > > callfunctions[4]=paint_message;
> > > >
> > > > This is odd. There's no point in setting callfunctions[4]=nodeDraw of
> > > > you are going to assign a different value immediately afterwards.
> > > >
> > > > > }
> > > >
> > > > <snip>
> > > > --
> > > > Ben.
> > >
> > > You are correct Ben that would be 5, i must find a way to see if the approach is faster. Some of the logic seem changed with it so not everything works, but first i would like to make some sort of speed comparisson, to see if it really worth the effort.
> >
> > Well most of the errors seem to be with the fact that my list of called functions never changed because startanimate that hold canvas rebuild only called 1 time. Instead i will use mouse down/up to start and stop animation i think it will work. And that terrible noise of rendering in earphones will stop ;), well unless i do mousedown.
>
> An annoyance is that since the function calls can make the array length differ i would have to push and pop elements. But i think i cheat that to start with using function empty(){}
>
> Or is there another way to tell interpretator that sometimes an element have no function AKA callfunctions[m]==undefined? when using callfunctions[m]()
Well i solved it with call of an empty function, the structural change did not effect most of the functionality, however move, mark and reshape no longer work, and it is very odd behaviour that i just do not understand like odd working first time it is used but after mark / unmark, you can still fetch it but when you move mouse it refuse to follow it is just weird. And i probably need a full day to sort it all out what is going on i thought i did not reset boolean values so i made a reset boolean function that is called before i change mode and it does not seem to be it.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 13:27 -0700 |
| Message-ID | <025569bd-3016-4b58-bd7c-ba7577cffd72@googlegroups.com> |
| In reply to | #33108 |
Den måndag 24 april 2017 kl. 21:08:03 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 23 april 2017 kl. 16:29:26 UTC+2 skrev John G Harris:
> > On Sat, 22 Apr 2017 15:46:53 -0700 (PDT), jonas.thornvall@gmail.com
> > wrote:
> >
> > >Den söndag 23 april 2017 kl. 00:39:50 UTC+2 skrev RobG:
> > >> On 17/04/2017 19:49, John G Harris wrote:
> > >> [...]
> > >> > For the paint_graph function it looks as though only one of the
> > >> > markers can be true at a time. You could use a code instead and use it
> > >> > to address an array of functions.
> > >> >
> > >> > var fd = [markDraw, moveDraw, boundariesDraw, reshapeDraw];
> > >> >
> > >> > // if m is the code, call the required function by :
> > >> > fd.m();
> > >>
> > >> Or if "m is the code" means m is a variable to which the code is
> > >> assigned, then perhaps:
> > >>
> > >> var m = /* expression to generate required code */
> > >>
> > >> fd[m]();
> > <snip>
> >
> > Sorry Jonas, I must have written it in a hurry. The dot notation can't
> > be used for this purpose.
> >
> > Here are two examples that work.
> > First, using an array.
> >
> > /***************/
> > function al(){return "alpha"};
> > function be(){return "beta"};
> > function ga(){return "gamma"};
> >
> > var fd = [al, be, ga];
> > var m;
> >
> > m = 1;
> > alert( fd[m]() );
> >
> > m = 2;
> > alert( fd[m]() );
> > /***************/
> >
> >
> > Second, using an object.
> >
> > /***************/
> > function fal(){return "alpha"};
> > function fbe(){return "beta"};
> > function fga(){return "gamma"};
> >
> > var fd = {al: fal, be: fbe, ga: fga};
> > var m;
> >
> > m = "be";
> > alert( fd[m]() );
> >
> > m = "ga";
> > alert( fd[m]() );
> > /***************/
> >
> > John
>
> I have tried your approach i get a type error
>
> TypeError: callfunctions[m] is not a function
> at redraw (6PAINTCANVAS.4
>
> // Paint logic *here i call redraw
> function redraw() {
> // Redraw graph every x-th millisec
> for (var m=0;m<callfunctions.length;m++) {callfunctions[m]()} //TYPEERROR
> }
>
> //This is in init *global*
> callfunctions = new Array();
>
> //HERE I BUILD UP CANVAS *HARDCODED* probably should use push...
> function build_canvas(arr) {
> callfunctions[0]=back_ground;
>
> if (grid==true) { callfunctions[1]=graphBackground; }
>
> if (markarea == true) {
> callfunctions[2]=markDraw;
> } else if (moveit == true) {
> callfunctions[2]=moveDraw;
> } else if (reshape == true) {
> callfunctions[2]=boundariesDraw;
> } else if (doreshape == true) {
> callfunctions[2]=reshapeDraw;
> } else if (holdbezier1==true){
> callfunctions[2]=moveBezierDraw1;
> } else if (holdbezier2==true){
> callfunctions[2]=moveBezierDraw2;
> }
>
> callfunctions[3]=graphDraw;
>
> if (handles==true){
> callfunctions[4]=nodeDraw;
> }
>
> callfunctions[4]=paint_message;
> }
>
> And i am sure i call build array before i start to draw.
>
> // Start animation "form"
> function startanime() {
> //Start animation
> message2 = "";
> build_canvas(arr);
> refresh = setInterval(redraw, 33);
> }
Oops turned out the if never was true so explain why no function, well i set moveit to true.
[toc] | [prev] | [standalone]
Page 4 of 4 — ← Prev page 1 2 3 [4]
Back to top | Article view | comp.lang.javascript
csiph-web