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 | 20 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 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2017-04-19 23:50 -0700 |
| Message-ID | <d0e60f7c-08b2-4d0a-b0fa-3e92d8ddbfa2@googlegroups.com> |
| In reply to | #33016 |
On Saturday, April 15, 2017 at 5:18:22 PM UTC-5, jonas.t...@gmail.com wrote: > Well the NG's name is comp.lang.javascript one would think that after 20 years you should be >used to people refering to Javascript i never ever seen ECMASCRIPT refered to unless reading your >posts. Ignore him, he's a dumb spastic antisocial FUCK. He's been told REPEATEDLY by me not to pull this behaviour, yet he does over....and over.....and over.....and over..... again :(
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2017-04-20 19:02 +1000 |
| Message-ID | <idWdnbuR1LCQ5GXFnZ2dnUU7-N-dnZ2d@westnet.com.au> |
| In reply to | #33072 |
On 20/04/2017 4:50 PM, bit-naughty@hotmail.com wrote: > On Saturday, April 15, 2017 at 5:18:22 PM UTC-5, jonas.t...@gmail.com wrote: > >> Well the NG's name is comp.lang.javascript one would think that after 20 years you should be >used to people refering to Javascript i never ever seen ECMASCRIPT refered to unless reading your >posts. > > Ignore him, he's a dumb spastic antisocial FUCK. He's been told REPEATEDLY by me not to pull this behaviour, yet he does over....and over.....and over.....and over..... again :( > Your post says more (negative) things about you than the person you're referring to. Andrew Poulos
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2017-04-20 11:24 +0200 |
| Message-ID | <XnsA75D740C4F607eejj99@194.109.6.166> |
| In reply to | #33073 |
Andrew Poulos <ap_prog@hotmail.com> wrote on 20 Apr 2017 in comp.lang.javascript: > On 20/04/2017 4:50 PM, bit-naughty@hotmail.com wrote: >> On Saturday, April 15, 2017 at 5:18:22 PM UTC-5, jonas.t...@gmail.com >> wrote: >> >>> Well the NG's name is comp.lang.javascript one would think that after >>> 20 years you should be >used to people refering to Javascript i never >>> ever seen ECMASCRIPT refered to unless reading your >posts. >> >> Ignore him, he's a dumb spastic antisocial FUCK. He's been told >> REPEATEDLY by me not to pull this behaviour, yet he does over....and >> over.....and over.....and over..... again :( >> > > Your post says more (negative) things about you than the person you're > referring to. Agree, well half so. Finding some ideas wrong does not mean the person is. That is the ad-hominem falacy in the making. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-15 15:14 -0700 |
| Message-ID | <f6ead0db-92e6-4ba5-a04d-7e4c467bfdb1@googlegroups.com> |
| In reply to | #33013 |
Den söndag 16 april 2017 kl. 00:04:13 UTC+2 skrev jonas.t...@gmail.com:
> Den lördag 15 april 2017 kl. 23:52:49 UTC+2 skrev jonas.t...@gmail.com:
> > Den lördag 15 april 2017 kl. 21:04:37 UTC+2 skrev jonas.t...@gmail.com:
> > > Den lördag 15 april 2017 kl. 20:52:19 UTC+2 skrev jonas.t...@gmail.com:
> > > > Den lördag 15 april 2017 kl. 12:07:38 UTC+2 skrev John G Harris:
> > > > > On Fri, 14 Apr 2017 11:49:16 -0700 (PDT), jonas.thornvall@gmail.com
> > > > > wrote:
> > > > >
> > > > > >High level computer programming of graphics seem to suffer from the fact that you can not tell what should be executed in the actual rendering algorithm.
> > > > > >
> > > > > >It is so wrong to have to check what should be written out within the actual render algorithm again and again.
> > > > > >
> > > > > >Why can't you send what algorithms to render to the pain function?
> > > > > >
> > > > > >Example, instead of checking what to render in the render algo again and agin why not use the individual function names to render as paramters to the render function.
> > > > > >
> > > > > >As far as i understand today you must check what to render within the render with in redraw where you render to canvas, and this happen as often you draw to the canvas.
> > > > > >
> > > > > >WHY can't one tell the redraw what functions/procedures to reder before it start?
> > > > > >
> > > > > >Is there a way to tell the rendering "redraw" from outside what functions that should be executed, i really would like an example. Right now i use booleans within the rendering "redraw" to tell what code should be executed and not.
> > > > > >
> > > > > >But it seem fucking weird to me, so possibly i have not understood the principle, because these are checked every time when you redraw and that must be a waste of cpu cycles. So is there a way to avoid this in highlevel programming languages?
> > > > > >My idea would be to tell the rendering what functions should be executed, so they become a parameter to the rendering, but maybe i totally missunderstood rendering?
> > > > >
> > > > > This is where Object Oriented design can be so useful. You have an
> > > > > object with a Draw method. Draw draws the entire picture. It does this
> > > > > by using a sequence of objects with Draw methods. In each of these
> > > > > objects Draw draws part of the picture by using a sequence of objects
> > > > > with Draw methods, etc. Eventually you reach objects whose Draw method
> > > > > draw a line, circle, rectangle, etc, using values remembered by the
> > > > > objects.
> > > >
> > > > You seem to say the objects know themself if they should be drawn or not?
> > > > I mean the method itself just draw objects you tell it to draw.
> > > >
> > > > Now the user interface is what steer the logic of the drawouts.
> > > >
> > > > You seem to say it somehow can tell a group of objects if they should be drawn or not. And i am totally lost here, because as you see i have to poll what should be drawn within the drawmethod and that gives alot of overhead.
> > > >
> > > > Could you direct me to "a short" "simple" example how it really should be done?
> > > >
> > > > Also my script do rendering using mouse inputs, so then the graphic objects must take/listen input parameters from mouse, would not that cause even more overhead?
> > > >
> > > > Of couse i must also poll what to be drawn out every redraw, and that is the main thing i want to get rid off. Say i have 15 function that do different parts of things to draw, that you can steer from the user interface.
> > > >
> > > > Now that would be 15! cases to handle within programming, so that is not an option. I think i have 3 right now or so but it still 6 cases.
> > > >
> > > > My code is probably not suited to transform into objectoriented programming, but i still want a look how it could work.
> > > >
> > > > What i really would like advice on is howto move the polling out of the redraw, now i decide what to draw within redraw ***every time*** method is called.
> > > >
> > > > I wanted to find a strategy/method where you set booleans for drawmethods, and check them once and somehow pass a bulk of what should be redrawn.
> > > >
> > > > I understand i could create cases with redraws, but that really does not seem to fit drawing.
> > >
> > > Here is an example of my style of graphic rendering, and i understand it is wrong. As you can see the logic is within the draw method "animation" to offer live update of drag and drop, that all these booleans called every "x-th" millisec. While drawing. Some is always drawn and some other just drawn depending on settings of the UI. I probably can not change all the code into OO-programming i do not think i have the skill, nor knowledge. Right now i let the animation run all time and that ain't necessary i can fix that from UI, start and stop it on UI mouse and animation redraws. But howto move the booleans out of redraw i just do not get. But if you show me an example of how it is done with OO code i may be able to grasp it.
> > >
> > > // Paint logic
> > > function redraw() {
> > > // Clear canvas
> > > ctx.clearRect(0, 0, canvas.width, canvas.height);
> > > // // Redraw canvas
> > > ctx.fillStyle = mybgcolor;
> > > ctx.fillRect(0, 0, canvas.width, canvas.height);
> > > if (grid==true) {graphBackground();}
> > > // Redraw graph
> > > paint_graph(arr);
> > > paint_message();
> > > }
> > >
> > > function paint_graph(arr) {
> > > ctx.lineWidth = 1;
> > > if (markarea == true) {
> > > markDraw();
> > > } else if (moveit == true) {
> > > moveDraw();
> > > } else if (reshape == true) {
> > > boundariesDraw();
> > > } else if (doreshape == true) {
> > > reshapeDraw();
> > > }
> > > graphDraw();
> > > if (handles==true){
> > > nodeDraw();
> > > }
> > > }
> > >
> > >
> > > function graphDraw() {
> > > for (var t = 0; t < arr.length; t++) {
> > > if (arr[t].print == true) {
> > > ctx.strokeStyle = arr[t].bcolor;
> > > var tempcolor=arr[t].bcolor;
> > > for (s = 0; s < arr[t].nodelinks.length; s++) {
> > > var myvar = arr[t].nodelinks[s];
> > > if (arr[t].BcurveX1[myvar] == undefined) {
> > > ctx.beginPath();
> > > ctx.moveTo(arr[t].rposX, arr[t].rposY);
> > > ctx.lineTo(arr[myvar].rposX, arr[myvar].rposY);
> > > ctx.stroke();
> > > } else {
> > > if (bhandles==true) { bezcontrol(t,myvar,tempcolor);ctx.strokeStyle=tempcolor;}
> > > ctx.beginPath();
> > > ctx.moveTo(arr[t].rposX, arr[t].rposY);
> > > ctx.bezierCurveTo(arr[t].BcurveX1[myvar], arr[t].BcurveY1[myvar], arr[t].BcurveX2[myvar], arr[t].BcurveY2[myvar], arr[myvar].rposX, arr[myvar].rposY);
> > > ctx.stroke();
> > > if (holdbezier1==true){ moveBezierDraw1(); }
> > > else if (holdbezier2==true){ moveBezierDraw2(); }
> > > }
> > > }
> > > }
> > > }
> > > }
> >
> > Should i put the start animation redraw within each of these functions?
> >
> > Or maybe even even on block level of things i draw, it seem the code lose structure?
> >
> > That is why i wanted the functions as parameters passed to draw rather then start and stop redraw everywhere in the code?
> >
> > But that is what you suggest, well with objects rather then my functions?
> >
> > function paint_graph(arr) {
> > ctx.lineWidth = 1;
> > if (markarea == true) {
> > markDraw();
> > } else if (moveit == true) {
> > moveDraw();
> > } else if (reshape == true) {
> > boundariesDraw();
> > } else if (doreshape == true) {
> > reshapeDraw();
> > }
> > graphDraw();
> > if (handles==true){
> > nodeDraw();
> > }
> > }
>
> It probably is a good idea to start animation within the functions that handle the graphics output, but it seem a bit unorganised.
//Select animation
function UI_select_animation() {
if (document.getElementById('graphic').checked) {
startanime();
} else {
stopanime();
}
}
Right now i just start and stop it from UI, it add some complexity to have it within each graphicals elements function but maybe that is the right way to do it.
Personally i would prefered the other way around tell the setInterval which layers or graphic elements to draw out and in which order. Now it gets much harder getting an overview of what goes wrong during redraw.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-15 15:24 -0700 |
| Message-ID | <6de87d05-bc5f-44bc-98ce-5981157a6ee8@googlegroups.com> |
| In reply to | #33015 |
Den söndag 16 april 2017 kl. 00:14:55 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 16 april 2017 kl. 00:04:13 UTC+2 skrev jonas.t...@gmail.com:
> > Den lördag 15 april 2017 kl. 23:52:49 UTC+2 skrev jonas.t...@gmail.com:
> > > Den lördag 15 april 2017 kl. 21:04:37 UTC+2 skrev jonas.t...@gmail.com:
> > > > Den lördag 15 april 2017 kl. 20:52:19 UTC+2 skrev jonas.t...@gmail.com:
> > > > > Den lördag 15 april 2017 kl. 12:07:38 UTC+2 skrev John G Harris:
> > > > > > On Fri, 14 Apr 2017 11:49:16 -0700 (PDT), jonas.thornvall@gmail.com
> > > > > > wrote:
> > > > > >
> > > > > > >High level computer programming of graphics seem to suffer from the fact that you can not tell what should be executed in the actual rendering algorithm.
> > > > > > >
> > > > > > >It is so wrong to have to check what should be written out within the actual render algorithm again and again.
> > > > > > >
> > > > > > >Why can't you send what algorithms to render to the pain function?
> > > > > > >
> > > > > > >Example, instead of checking what to render in the render algo again and agin why not use the individual function names to render as paramters to the render function.
> > > > > > >
> > > > > > >As far as i understand today you must check what to render within the render with in redraw where you render to canvas, and this happen as often you draw to the canvas.
> > > > > > >
> > > > > > >WHY can't one tell the redraw what functions/procedures to reder before it start?
> > > > > > >
> > > > > > >Is there a way to tell the rendering "redraw" from outside what functions that should be executed, i really would like an example. Right now i use booleans within the rendering "redraw" to tell what code should be executed and not.
> > > > > > >
> > > > > > >But it seem fucking weird to me, so possibly i have not understood the principle, because these are checked every time when you redraw and that must be a waste of cpu cycles. So is there a way to avoid this in highlevel programming languages?
> > > > > > >My idea would be to tell the rendering what functions should be executed, so they become a parameter to the rendering, but maybe i totally missunderstood rendering?
> > > > > >
> > > > > > This is where Object Oriented design can be so useful. You have an
> > > > > > object with a Draw method. Draw draws the entire picture. It does this
> > > > > > by using a sequence of objects with Draw methods. In each of these
> > > > > > objects Draw draws part of the picture by using a sequence of objects
> > > > > > with Draw methods, etc. Eventually you reach objects whose Draw method
> > > > > > draw a line, circle, rectangle, etc, using values remembered by the
> > > > > > objects.
> > > > >
> > > > > You seem to say the objects know themself if they should be drawn or not?
> > > > > I mean the method itself just draw objects you tell it to draw.
> > > > >
> > > > > Now the user interface is what steer the logic of the drawouts.
> > > > >
> > > > > You seem to say it somehow can tell a group of objects if they should be drawn or not. And i am totally lost here, because as you see i have to poll what should be drawn within the drawmethod and that gives alot of overhead.
> > > > >
> > > > > Could you direct me to "a short" "simple" example how it really should be done?
> > > > >
> > > > > Also my script do rendering using mouse inputs, so then the graphic objects must take/listen input parameters from mouse, would not that cause even more overhead?
> > > > >
> > > > > Of couse i must also poll what to be drawn out every redraw, and that is the main thing i want to get rid off. Say i have 15 function that do different parts of things to draw, that you can steer from the user interface.
> > > > >
> > > > > Now that would be 15! cases to handle within programming, so that is not an option. I think i have 3 right now or so but it still 6 cases.
> > > > >
> > > > > My code is probably not suited to transform into objectoriented programming, but i still want a look how it could work.
> > > > >
> > > > > What i really would like advice on is howto move the polling out of the redraw, now i decide what to draw within redraw ***every time*** method is called.
> > > > >
> > > > > I wanted to find a strategy/method where you set booleans for drawmethods, and check them once and somehow pass a bulk of what should be redrawn.
> > > > >
> > > > > I understand i could create cases with redraws, but that really does not seem to fit drawing.
> > > >
> > > > Here is an example of my style of graphic rendering, and i understand it is wrong. As you can see the logic is within the draw method "animation" to offer live update of drag and drop, that all these booleans called every "x-th" millisec. While drawing. Some is always drawn and some other just drawn depending on settings of the UI. I probably can not change all the code into OO-programming i do not think i have the skill, nor knowledge. Right now i let the animation run all time and that ain't necessary i can fix that from UI, start and stop it on UI mouse and animation redraws. But howto move the booleans out of redraw i just do not get. But if you show me an example of how it is done with OO code i may be able to grasp it.
> > > >
> > > > // Paint logic
> > > > function redraw() {
> > > > // Clear canvas
> > > > ctx.clearRect(0, 0, canvas.width, canvas.height);
> > > > // // Redraw canvas
> > > > ctx.fillStyle = mybgcolor;
> > > > ctx.fillRect(0, 0, canvas.width, canvas.height);
> > > > if (grid==true) {graphBackground();}
> > > > // Redraw graph
> > > > paint_graph(arr);
> > > > paint_message();
> > > > }
> > > >
> > > > function paint_graph(arr) {
> > > > ctx.lineWidth = 1;
> > > > if (markarea == true) {
> > > > markDraw();
> > > > } else if (moveit == true) {
> > > > moveDraw();
> > > > } else if (reshape == true) {
> > > > boundariesDraw();
> > > > } else if (doreshape == true) {
> > > > reshapeDraw();
> > > > }
> > > > graphDraw();
> > > > if (handles==true){
> > > > nodeDraw();
> > > > }
> > > > }
> > > >
> > > >
> > > > function graphDraw() {
> > > > for (var t = 0; t < arr.length; t++) {
> > > > if (arr[t].print == true) {
> > > > ctx.strokeStyle = arr[t].bcolor;
> > > > var tempcolor=arr[t].bcolor;
> > > > for (s = 0; s < arr[t].nodelinks.length; s++) {
> > > > var myvar = arr[t].nodelinks[s];
> > > > if (arr[t].BcurveX1[myvar] == undefined) {
> > > > ctx.beginPath();
> > > > ctx.moveTo(arr[t].rposX, arr[t].rposY);
> > > > ctx.lineTo(arr[myvar].rposX, arr[myvar].rposY);
> > > > ctx.stroke();
> > > > } else {
> > > > if (bhandles==true) { bezcontrol(t,myvar,tempcolor);ctx.strokeStyle=tempcolor;}
> > > > ctx.beginPath();
> > > > ctx.moveTo(arr[t].rposX, arr[t].rposY);
> > > > ctx.bezierCurveTo(arr[t].BcurveX1[myvar], arr[t].BcurveY1[myvar], arr[t].BcurveX2[myvar], arr[t].BcurveY2[myvar], arr[myvar].rposX, arr[myvar].rposY);
> > > > ctx.stroke();
> > > > if (holdbezier1==true){ moveBezierDraw1(); }
> > > > else if (holdbezier2==true){ moveBezierDraw2(); }
> > > > }
> > > > }
> > > > }
> > > > }
> > > > }
> > >
> > > Should i put the start animation redraw within each of these functions?
> > >
> > > Or maybe even even on block level of things i draw, it seem the code lose structure?
> > >
> > > That is why i wanted the functions as parameters passed to draw rather then start and stop redraw everywhere in the code?
> > >
> > > But that is what you suggest, well with objects rather then my functions?
> > >
> > > function paint_graph(arr) {
> > > ctx.lineWidth = 1;
> > > if (markarea == true) {
> > > markDraw();
> > > } else if (moveit == true) {
> > > moveDraw();
> > > } else if (reshape == true) {
> > > boundariesDraw();
> > > } else if (doreshape == true) {
> > > reshapeDraw();
> > > }
> > > graphDraw();
> > > if (handles==true){
> > > nodeDraw();
> > > }
> > > }
> >
> > It probably is a good idea to start animation within the functions that handle the graphics output, but it seem a bit unorganised.
>
> //Select animation
> function UI_select_animation() {
> if (document.getElementById('graphic').checked) {
> startanime();
> } else {
> stopanime();
> }
> }
>
> Right now i just start and stop it from UI, it add some complexity to have it within each graphicals elements function but maybe that is the right way to do it.
>
> Personally i would prefered the other way around tell the setInterval which layers or graphic elements to draw out and in which order. Now it gets much harder getting an overview of what goes wrong during redraw.
Isn't there a risc also that one forget to close the animation, before next function call to setInterval what happen then will there be two threads running animation?
If so is there a way to check it?
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2017-04-17 10:49 +0100 |
| Message-ID | <or39fcp5eirh6t4tht3kjusp4jjg9hjskt@4ax.com> |
| In reply to | #33011 |
On Sat, 15 Apr 2017 12:04:26 -0700 (PDT), jonas.thornvall@gmail.com
wrote:
<snip>
>function paint_graph(arr) {
> ctx.lineWidth = 1;
> if (markarea == true) {
> markDraw();
> } else if (moveit == true) {
> moveDraw();
> } else if (reshape == true) {
> boundariesDraw();
> } else if (doreshape == true) {
> reshapeDraw();
> }
> graphDraw();
> if (handles==true){
> nodeDraw();
> }
>}
<snip>
I don't know what picture you are drawing and I don't know why bits of
it don't get drawn so I can't say much more.
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();
John
[toc] | [prev] | [next] | [standalone]
| From | RobG <rgqld@iinet.net.au> |
|---|---|
| Date | 2017-04-23 08:39 +1000 |
| Message-ID | <Y8adncdLCZowRmbFnZ2dnUU7-V3NnZ2d@westnet.com.au> |
| In reply to | #33026 |
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](); -- Rob
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-22 15:46 -0700 |
| Message-ID | <3191717e-3652-45ad-a526-86f07b74f6d5@googlegroups.com> |
| In reply to | #33093 |
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](); > > > -- > Rob Well this coding style/paradigm is totally beyond my knowledge. If one of you give a snippet/example where two functions is called with alerts this way maybe i understand it, i even have a hard time see the relevance to the call of the draw function. Probably because i just do not understand the approach.
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2017-04-23 15:29 +0100 |
| Message-ID | <9depfctc9stkatqhtk8b5g6v8g754bda0u@4ax.com> |
| In reply to | #33094 |
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
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-23 09:47 -0700 |
| Message-ID | <bd025b2f-c9dc-422d-b5b9-b737c51158b7@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
Thanks John!
I think i can wrap my head around it, so the alert could be the redraw and the functions could be the array objects,arrayelements that is called, it is a smart approach i like it. Is this a javascript only feature or is similar approach allowed in C++ and JAVA?
Would it seem correct to build up an array with the functions you want called, so i use the user inputs "and my knowledge of draworder", to build up the array and the functions to be called/stepped thru "for my purpose"?
Have i understood it correct?
I think i may try to implement splines first before changing the redraw calls.
But it seem alot easier then i would have thought.
Jonas
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-23 09:57 -0700 |
| Message-ID | <72f890c2-011a-4732-91ab-defcaaf350ce@googlegroups.com> |
| In reply to | #33096 |
Den söndag 23 april 2017 kl. 18:47:14 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
>
> Thanks John!
>
> I think i can wrap my head around it, so the alert could be the redraw and the functions could be the array objects,arrayelements that is called, it is a smart approach i like it. Is this a javascript only feature or is similar approach allowed in C++ and JAVA?
>
> Would it seem correct to build up an array with the functions you want called, so i use the user inputs "and my knowledge of draworder", to build up the array and the functions to be called/stepped thru "for my purpose"?
> Have i understood it correct?
>
> I think i may try to implement splines first before changing the redraw calls.
> But it seem alot easier then i would have thought.
>
> Jonas
Actually it is just what i wanted i just was not aware it was a part of javascript, the array elements are functions that can be called fantastic i think. When was this introduced into Javascript, i like functions as parameters to other functions "sort of".
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2017-04-24 11:09 +0100 |
| Message-ID | <uijrfcd0kgrocvbs5ulcpp62cu7plu34r8@4ax.com> |
| In reply to | #33098 |
On Sun, 23 Apr 2017 09:57:55 -0700 (PDT), jonas.thornvall@gmail.com wrote: >Den söndag 23 april 2017 kl. 18:47:14 UTC+2 skrev jonas.t...@gmail.com: <snip> >> I think i can wrap my head around it, so the alert could be the redraw >> and the functions could be the array objects,arrayelements that is called, >> it is a smart approach i like it. Is this a javascript only feature or >>is similar approach allowed in C++ and JAVA? C++ : Yes, Java : Sort of. >> Would it seem correct to build up an array with the functions you want >> called, so i use the user inputs "and my knowledge of draworder", to build >> up the array and the functions to be called/stepped thru "for my purpose"? >> Have i understood it correct? <snip> You can build the array and use it any way you like, just like any other array. >Actually it is just what i wanted i just was not aware it was a part of >javascript, the array elements are functions that can be called fantastic i >think. When was this introduced into Javascript, i like functions as parameters >to other functions "sort of". Functions in ECMAScript have always been Function Objects. They can be put anywhere an object can be put. The difference from other kinds of object is that if b contains a Function Object you can call the function by doing b() [with whatever is needed inside the brackets of course]. John
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 05:26 -0700 |
| Message-ID | <3b15914a-0362-4ba7-9055-4ebf4bea9220@googlegroups.com> |
| In reply to | #33100 |
Den måndag 24 april 2017 kl. 12:09:10 UTC+2 skrev John G Harris: > On Sun, 23 Apr 2017 09:57:55 -0700 (PDT), jonas.thornvall@gmail.com > wrote: > > >Den söndag 23 april 2017 kl. 18:47:14 UTC+2 skrev jonas.t...@gmail.com: > <snip> > > >> I think i can wrap my head around it, so the alert could be the redraw > >> and the functions could be the array objects,arrayelements that is called, > >> it is a smart approach i like it. Is this a javascript only feature or > >>is similar approach allowed in C++ and JAVA? > > C++ : Yes, Java : Sort of. > > > >> Would it seem correct to build up an array with the functions you want > >> called, so i use the user inputs "and my knowledge of draworder", to build > >> up the array and the functions to be called/stepped thru "for my purpose"? > >> Have i understood it correct? > <snip> > > You can build the array and use it any way you like, just like any > other array. > > > >Actually it is just what i wanted i just was not aware it was a part of > >javascript, the array elements are functions that can be called fantastic i > >think. When was this introduced into Javascript, i like functions as parameters > >to other functions "sort of". > > Functions in ECMAScript have always been Function Objects. They can be > put anywhere an object can be put. The difference from other kinds of > object is that if b contains a Function Object you can call the > function by doing b() [with whatever is needed inside the brackets of > course]. > > John Is there any disadvantages in speed doing the function calls this way, because obviously being within redraw there will be alot of them? If the calls turn out to be slower then actually doing the checks, there will be no point, but my guess is these calls do not differ in speed compared to an ordinary function call? And you have to add up the counter in the loop for every drawing element, how does that compare to doing a boolean check? if (argument==true) doThis(); else if ..... else if ..... else if ..... vs for (m=0;m<arguments.length;m++) fd[m](); "I realise you need some structure to hold an arbitrary number of calls so why not an array, #it is a bit harder for me to understand why a counter needed, but maybe my case isn't the typical? I was a bit dreaming of it as a "heap" of calls constructed? But that does not seem to be the case? MYHEAP="X(),Y(),Z()"; CALL(MYHEAP) EQUALS DO X(),DO Y(),DO Z() But maybe the above is equivalent to stepping thru an array of function arguments?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 05:32 -0700 |
| Message-ID | <0af59f6f-8ad6-4d68-af0c-ad3685e828c3@googlegroups.com> |
| In reply to | #33102 |
Den måndag 24 april 2017 kl. 14:26:09 UTC+2 skrev jonas.t...@gmail.com: > Den måndag 24 april 2017 kl. 12:09:10 UTC+2 skrev John G Harris: > > On Sun, 23 Apr 2017 09:57:55 -0700 (PDT), jonas.thornvall@gmail.com > > wrote: > > > > >Den söndag 23 april 2017 kl. 18:47:14 UTC+2 skrev jonas.t...@gmail.com: > > <snip> > > > > >> I think i can wrap my head around it, so the alert could be the redraw > > >> and the functions could be the array objects,arrayelements that is called, > > >> it is a smart approach i like it. Is this a javascript only feature or > > >>is similar approach allowed in C++ and JAVA? > > > > C++ : Yes, Java : Sort of. > > > > > > >> Would it seem correct to build up an array with the functions you want > > >> called, so i use the user inputs "and my knowledge of draworder", to build > > >> up the array and the functions to be called/stepped thru "for my purpose"? > > >> Have i understood it correct? > > <snip> > > > > You can build the array and use it any way you like, just like any > > other array. > > > > > > >Actually it is just what i wanted i just was not aware it was a part of > > >javascript, the array elements are functions that can be called fantastic i > > >think. When was this introduced into Javascript, i like functions as parameters > > >to other functions "sort of". > > > > Functions in ECMAScript have always been Function Objects. They can be > > put anywhere an object can be put. The difference from other kinds of > > object is that if b contains a Function Object you can call the > > function by doing b() [with whatever is needed inside the brackets of > > course]. > > > > John > > Is there any disadvantages in speed doing the function calls this way, because obviously being within redraw there will be alot of them? > > If the calls turn out to be slower then actually doing the checks, there will be no point, but my guess is these calls do not differ in speed compared to an ordinary function call? > > And you have to add up the counter in the loop for every drawing element, how does that compare to doing a boolean check? > > if (argument==true) doThis(); > else if ..... > else if ..... > else if ..... > > vs > > for (m=0;m<arguments.length;m++) fd[m](); > > "I realise you need some structure to hold an arbitrary number of calls so why not an array, #it is a bit harder for me to understand why a counter needed, but maybe my case isn't the typical? > > I was a bit dreaming of it as a "heap" of calls constructed? But that does not seem to be the case? > > MYHEAP="X(),Y(),Z()"; > > CALL(MYHEAP) > > EQUALS > > DO X(),DO Y(),DO Z() > > But maybe the above is equivalent to stepping thru an array of function arguments? Well maybe i am a bit confused here, i am not that lowlevel knowledgable, maybe i mean a stack here rather than a heap, a set of pointers to the memory adresses of the functions?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 05:36 -0700 |
| Message-ID | <fae573bc-f7ed-40cb-9d80-a1c65cea881b@googlegroups.com> |
| In reply to | #33103 |
Den måndag 24 april 2017 kl. 14:32:50 UTC+2 skrev jonas.t...@gmail.com: > Den måndag 24 april 2017 kl. 14:26:09 UTC+2 skrev jonas.t...@gmail.com: > > Den måndag 24 april 2017 kl. 12:09:10 UTC+2 skrev John G Harris: > > > On Sun, 23 Apr 2017 09:57:55 -0700 (PDT), jonas.thornvall@gmail.com > > > wrote: > > > > > > >Den söndag 23 april 2017 kl. 18:47:14 UTC+2 skrev jonas.t...@gmail.com: > > > <snip> > > > > > > >> I think i can wrap my head around it, so the alert could be the redraw > > > >> and the functions could be the array objects,arrayelements that is called, > > > >> it is a smart approach i like it. Is this a javascript only feature or > > > >>is similar approach allowed in C++ and JAVA? > > > > > > C++ : Yes, Java : Sort of. > > > > > > > > > >> Would it seem correct to build up an array with the functions you want > > > >> called, so i use the user inputs "and my knowledge of draworder", to build > > > >> up the array and the functions to be called/stepped thru "for my purpose"? > > > >> Have i understood it correct? > > > <snip> > > > > > > You can build the array and use it any way you like, just like any > > > other array. > > > > > > > > > >Actually it is just what i wanted i just was not aware it was a part of > > > >javascript, the array elements are functions that can be called fantastic i > > > >think. When was this introduced into Javascript, i like functions as parameters > > > >to other functions "sort of". > > > > > > Functions in ECMAScript have always been Function Objects. They can be > > > put anywhere an object can be put. The difference from other kinds of > > > object is that if b contains a Function Object you can call the > > > function by doing b() [with whatever is needed inside the brackets of > > > course]. > > > > > > John > > > > Is there any disadvantages in speed doing the function calls this way, because obviously being within redraw there will be alot of them? > > > > If the calls turn out to be slower then actually doing the checks, there will be no point, but my guess is these calls do not differ in speed compared to an ordinary function call? > > > > And you have to add up the counter in the loop for every drawing element, how does that compare to doing a boolean check? > > > > if (argument==true) doThis(); > > else if ..... > > else if ..... > > else if ..... > > > > vs > > > > for (m=0;m<arguments.length;m++) fd[m](); > > > > "I realise you need some structure to hold an arbitrary number of calls so why not an array, #it is a bit harder for me to understand why a counter needed, but maybe my case isn't the typical? > > > > I was a bit dreaming of it as a "heap" of calls constructed? But that does not seem to be the case? > > > > MYHEAP="X(),Y(),Z()"; > > > > CALL(MYHEAP) > > > > EQUALS > > > > DO X(),DO Y(),DO Z() > > > > But maybe the above is equivalent to stepping thru an array of function arguments? > > Well maybe i am a bit confused here, i am not that lowlevel knowledgable, maybe i mean a stack here rather than a heap, a set of pointers to the memory adresses of the functions? I looked around and i probably meant a sequential stack of instruction calls to memory adresses, it is faster then the use of heap isn't it?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 05:44 -0700 |
| Message-ID | <16399cc8-7abd-4eec-99a6-e5f53a3b8dbd@googlegroups.com> |
| In reply to | #33104 |
Den måndag 24 april 2017 kl. 14:37:01 UTC+2 skrev jonas.t...@gmail.com: > Den måndag 24 april 2017 kl. 14:32:50 UTC+2 skrev jonas.t...@gmail.com: > > Den måndag 24 april 2017 kl. 14:26:09 UTC+2 skrev jonas.t...@gmail.com: > > > Den måndag 24 april 2017 kl. 12:09:10 UTC+2 skrev John G Harris: > > > > On Sun, 23 Apr 2017 09:57:55 -0700 (PDT), jonas.thornvall@gmail.com > > > > wrote: > > > > > > > > >Den söndag 23 april 2017 kl. 18:47:14 UTC+2 skrev jonas.t...@gmail.com: > > > > <snip> > > > > > > > > >> I think i can wrap my head around it, so the alert could be the redraw > > > > >> and the functions could be the array objects,arrayelements that is called, > > > > >> it is a smart approach i like it. Is this a javascript only feature or > > > > >>is similar approach allowed in C++ and JAVA? > > > > > > > > C++ : Yes, Java : Sort of. > > > > > > > > > > > > >> Would it seem correct to build up an array with the functions you want > > > > >> called, so i use the user inputs "and my knowledge of draworder", to build > > > > >> up the array and the functions to be called/stepped thru "for my purpose"? > > > > >> Have i understood it correct? > > > > <snip> > > > > > > > > You can build the array and use it any way you like, just like any > > > > other array. > > > > > > > > > > > > >Actually it is just what i wanted i just was not aware it was a part of > > > > >javascript, the array elements are functions that can be called fantastic i > > > > >think. When was this introduced into Javascript, i like functions as parameters > > > > >to other functions "sort of". > > > > > > > > Functions in ECMAScript have always been Function Objects. They can be > > > > put anywhere an object can be put. The difference from other kinds of > > > > object is that if b contains a Function Object you can call the > > > > function by doing b() [with whatever is needed inside the brackets of > > > > course]. > > > > > > > > John > > > > > > Is there any disadvantages in speed doing the function calls this way, because obviously being within redraw there will be alot of them? > > > > > > If the calls turn out to be slower then actually doing the checks, there will be no point, but my guess is these calls do not differ in speed compared to an ordinary function call? > > > > > > And you have to add up the counter in the loop for every drawing element, how does that compare to doing a boolean check? > > > > > > if (argument==true) doThis(); > > > else if ..... > > > else if ..... > > > else if ..... > > > > > > vs > > > > > > for (m=0;m<arguments.length;m++) fd[m](); > > > > > > "I realise you need some structure to hold an arbitrary number of calls so why not an array, #it is a bit harder for me to understand why a counter needed, but maybe my case isn't the typical? > > > > > > I was a bit dreaming of it as a "heap" of calls constructed? But that does not seem to be the case? > > > > > > MYHEAP="X(),Y(),Z()"; > > > > > > CALL(MYHEAP) > > > > > > EQUALS > > > > > > DO X(),DO Y(),DO Z() > > > > > > But maybe the above is equivalent to stepping thru an array of function arguments? > > > > Well maybe i am a bit confused here, i am not that lowlevel knowledgable, maybe i mean a stack here rather than a heap, a set of pointers to the memory adresses of the functions? > > I looked around and i probably meant a sequential stack of instruction calls to memory adresses, it is faster then the use of heap isn't it? MYSTACK="X(),Y(),Z()"; CALL(MYSTACK) EQUALS DO X(),DO Y(),DO Z()
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2017-04-24 15:12 +0100 |
| Message-ID | <as1sfc96cthcbvgctom9ovd3c67upus2mg@4ax.com> |
| In reply to | #33102 |
On Mon, 24 Apr 2017 05:26:04 -0700 (PDT), jonas.thornvall@gmail.com wrote: <snip> >if (argument==true) doThis(); >else if ..... >else if ..... >else if ..... This calls just one function. >vs > >for (m=0;m<arguments.length;m++) fd[m](); <snip> This calls all the functions in the array. John
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-24 10:12 -0700 |
| Message-ID | <df4b1c7b-1485-4529-8884-fde0c8d187a1@googlegroups.com> |
| In reply to | #33106 |
Den måndag 24 april 2017 kl. 16:12:40 UTC+2 skrev John G Harris: > On Mon, 24 Apr 2017 05:26:04 -0700 (PDT), jonas.thornvall@gmail.com > wrote: > > > <snip> > >if (argument==true) doThis(); > >else if ..... > >else if ..... > >else if ..... > > This calls just one function. > > > >vs > > > >for (m=0;m<arguments.length;m++) fd[m](); > <snip> > > This calls all the functions in the array. > > John if (argument=="1") do1(); else if "2" ..... else if "3" ..... else if "4" ..... if (argument=="A") do2(); else if "B" ..... else if "C" ..... else if "D"..... if (argument=="FORGE") do3(); else if "NUTS"..... else if "BOLTS"..... else if "NAILS"..... The meaning was just that their is options for the arguments that select the functions to be called, i did not specify a number of them.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-04-23 09:49 -0700 |
| Message-ID | <044928be-2a3a-44cd-a2db-8f4bb4f90157@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
You would make a great teacher John
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2017-04-24 11:10 +0100 |
| Message-ID | <jmjrfc91osidonald57icpr8m8ktnki9om@4ax.com> |
| In reply to | #33097 |
On Sun, 23 Apr 2017 09:49:29 -0700 (PDT), jonas.thornvall@gmail.com wrote: <snip> >You would make a great teacher John I know someone who would violently disagree with that :-) John
[toc] | [prev] | [next] | [standalone]
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web