This object is in archive! 

JS for loop in array changes every each time.

Math123 shared this question 1 year ago
Answered

Pls see attached and create more points and see why previous objects also changes color along with newly created object. In global JS pls see script, i have tried so many things i don't what am i doing worng.

It should trigger JS for only newly created object not for previous objects which already created.

means why previous objects changes color , i tried with point size with slider as well by all objects affected whenever new object created.


Pls see attached and suggest solution.

Best Answer
photo

I don't know if anyone on this earth (including me and you) knows what you want.

But how do you want know what you want before you see it?

Comments (37)

photo
1

It worked , after the for loop i removed previous items from the list (unsing shift method) so it can not affect the object in the applet.


If there is any other better solution. pls suggest


Is it possible to add element in the array whenever object is created in the applet???

photo
3

Hi,

see the attached file

to avoid coloring old objects every time:

pre-find the number of objects before changing - > button 0,

add new objects and click -->button 1

photo
1

Thanks Roman,

your solution work for every object type. Next i try to do the same with other objects also, and your solution already did this for every object type. It helped me.

photo
2

I don't know if anyone on this earth (including me and you) knows what you want.

But how do you want know what you want before you see it?

photo
2

Hello rami,

Except your comment your solution is superb. :wink:

I must say, you appreciate that how much i learnt since i was joined. I experiment things and i tried different possibilities. When there is no solution i post the thread.

If you don't mistake, don't practice , especially don't experiment trying new things one can never ever learn anything in the world. who always follow SOP never learn new things. SOP are good to follow but at some extent not always. I always try to do my work easy with different possibilities and much more immersive than previously. These things creating new questions, demand and challenges.

May be my post is not very important for you because you have a lot experience, but it make my project easy.

At very last No Doubt GGB is superb software.

Thanks all of you.

photo
1

It's true, sometimes you know what you want. And very rarely you can even formulate it.

But how I am supposed to figure that out only based on a few possibly wrong lines of code?

photo
1

First of all Thanks rami and all other guys for supporting.

you can ask questions. These wrong lines of code i created from trying experiment. These wrong snippet most of the time piece of hard work :smile: . I am not a programmer but my requirement demand programming. That's why i learnt JS, python, HTML , CSS very little am not an expert like you.

I am here still just because GGB community always supportive to facilitate users. No matter question are very naive or expert.

photo
2

First of all Thanks @rami for your continuous support !!!

We are all learning, constantly and inevitably...

@Math123: There is still a possibility:

use the construction protocol(tab ->view ) and you can choose the numbers of objects that you want to color...

photo
1

One thing i would like to say because i am a teacher. Even Einstein can not solve all the problems by his own which he proposed. Specially during his theory of relativity when he did not understand something he called conferences so many times and invited top scientist. He ally with David Hilbert top mathematician of his time. More importantly when even Hilbert stuck somewhere he and Einstein hired one of great lady Mathematician Emmy Noether. She came with the solution and explained the generalized idea conservation principle . Noether's Theorem. No one before understand this.

Conclusion : My way of thinking, we learn from everyone and no question is small. If someone knows all the answer why there are FAQ forums/schools/universities. Who has ability to ask questions and curious about things has potential to discover new ideas.


Sorry for the long message. :smile:


Lastly Thanks rami for the support, i always use your ideas and your ideas give me new ways of thinking to uncover more things.

photo
1

Hello rami and other guys,

Pls see attached . What am i doing wrong in script. I try to point size increase with slider value.

Here in this i need your constant support as always. I am very thankful to you rami....!

photo
1

Please describe (exactly) what the scripts should do at which events.

What can be seen on the screen in which time period.

photo
1

I need to use JS because i think it is easy to achieve my requirement and also new learning.


I try to achieve whenever i create new point automatically randomly select new color of that point and starting from Point Size zero size to maximum size (if possible more than 9).


Any JS script technique and event can be used. Whatever easy to get the objective.


Next i will try to caption size size increase/decrease in the same on each point.

photo
1

not complete (listing of all events and their influence) but OK.

One question more:

What should happen if several points are created (almost) simultaneously (within the period of time in which the growth of a previous point is not yet complete).

photo
1

First of all thanks rami your support . You are awesome.


If previous points are not completed and new point is created. they should go for their loop process to complete and we need. Size go to maximum. and caption go negative to positive.

And this same for each point.

photo
1

OK

How many sliders do we need for this?

And according to which principle the sliders should be assigned to the respective points.

And which object is responsible for the growth of the point.

photo
1

Only one slider for point size and one for caption total two sliders handle each point. That's why specially i try to use JS. One event these two slider work for point 1, and once again these two sliders work once again work for point 2.

For easiness it can also possible until loop to point one completed two 2 not created.

photo
1

OK

And where is the script for the dynamic change of the point.

And how (in the detail, exact) do you get the script into that (generated !!!) object

photo
1

Answer:

There is absolutely no command to do that!!!

photo
1

Sorry for the late answer rami. I was in travelling.

1. And where is the script for the dynamic change of the point. (In global JS becuase it need to be applied for each nely created point/object).

Point creation with color change and specific point size you have already made. I try to add change the point size with slider value in the same script. "I have done this 2 days ago during my try different thing , but i unfortunately lost my work. and in so many tries i can't remember what i did."

photo
1

No (!!!!!!!!!!). The script must be in the slider. Otherwise there is no action onUpdate of slider.

The addListener has only 1 event for one point.

In the slider a lot event exist for one point.

Before you not understand this, its make no sens to go to next step.

photo
1

Yes i understand. I can remember now exactly i scripted in the slider. Which worked with point size change. (Means there is no event listener for dynamically values???) but it also continuously change the random color also.

photo
1

---

photo
1

rami now i understand the situation little bit. Pls if possible share an attachment i can see the code and understand better.

When in my try i found accidentally, slider change the point size. I found that it continuously change the random color of point continuously with the slider.

photo
1

sorry no.

First explain what you want do (coding).

photo
1

rami you have magic of coding in your fingers. pls do it.

1. I try to create points creation with random color.and each point created from point size zero to max size.

2. I have another task to explain locus of points to create line and a script for creation of so many points one after other continuously go bigger size to smaller and finally it look like a line. (Is it possible)

photo
2

The idea is:

Not the original point him self change. It is a representative/actor showing the animation. In this time the original point is hidden. The actor become 2 parameter: Label/adress of original-point and the color.

This will be expanded later so that any actor (from several) can be selected to do the job. Even later, the instantiation of an actor should be integrated into the add-listener and finally the caption should also be animated by the same actor.

wait some hours.

photo
1

Thanks rami......


Also pls look my 2nd case locus of points create a line in your plan.

photo
1

no: step by step

photo
1

If you are free from my first case we can discuss my 2nd case. How can i build my imagination in words. Let's try with my excellent English. :)

I need to show locus of points create a line. Image last results is line.

Step 1. at the corner first point appear at a big size and size decrease to let say final point size is 8 and start with 15.

Step 2. Same way as in steps step1 2nd point appear (it is not necessary 1st point reached point1 to minimum size then point1 appear animation is fast) at the neighbor of point-1.

Step 3. Few points appears one by one at their neighbor than more points come with each other.

Step 4. All points finally look like a line.

Hope with your fast intuition you understand my English and imagination.

photo
1

Sorry You are disturbing I work (for you)

I read nothing from you until I send you a File (maybe tomorrow)

Then we will talk about this file. When you have understood the principle, you will add a small extension.

Then and only then we will see further.

If you agree: keep still. If you not agree: just let me know, so I can stop my work.

photo
1

rami i always agreed with you. which extension i need to add.

photo
2

Good morning,

Now your part is comming.

Pleas read (very attentive!) this thread from here until here.

Answer the following questions (about 2 sentences for 1 question) (please, please !! nothing else or more):

1. What is the goal, what do we want to achieve (without those ideas you also have)?

2. What is the primary problem to be solved? (Note: it's not a Bug, it's a (new) possibility/feature)

photo
1

Hello GooD MorNinG....!

1. What is the goal, what do we want to achieve (without those ideas you also have)?

A. Goal is to explain point, line and primary geometric concepts with this to students. Point size start from zero to bigger , it convert attention of students to the new creating object in the canvas and it is self explanatory.

2. What is the primary problem to be solved? (Note: it's not a Bug, it's a (new) possibility/feature)

A. I have created too many transition effect with the available resources in GGB. But it required too many sliders and i used too many colors in my projects , it consumes a lot of time. Because it is a part of all my projects so it is better to make this easy. Then i realized that if i make JS code it can be possible to achieve the same with few sliders and few line of code. Color with random color. Dynamic Point size change with few or one slider .

Also it is new learning for me and give me new destination/way to create more useful ideas. which may be difficult or not possible with current features of GGB. Because transition effect is mandatory part to explain something to students. Future like the use jQuery and other useful libraries for this effects.

Sorry about that answer is long because i try to explain it is not useless or waste of time. It is very useful and highly required. Hopefully GGB TEAM will think about it to add these features . Which make GGB software more immersive, interactive.

photo
1

1) OK

2) not OK

---------------------------new question

3) what must be created/exist, when a new object (for example a point) with animation of his size is to be established?

Example: a script or a user create a new point. The point appears very small and becomes larger for about 1 second, then the size remains constant. To do this animation, what are the objects there must exists.

(correct answer less then 10 words)

photo
1

"what are the objects there must exists."

A. Not must exist. If i need i can create line, ray, segment, circle, angle.

photo
1

sorry, wrong. (both: in terms of content and number of words)

Try again.

Note: if the animation run: what objects must exist.

photo
1

sorry rami, i don't understand the question. Pls explain it with example and give me options.

Comments have been locked on this page!

© 2021 International GeoGebra Institute