Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / code simplification

Author
Message
1beginner1
15
Years of Service
User Offline
Joined: 28th Jun 2009
Location: Belgium
Posted: 2nd Mar 2011 22:08 Edited at: 3rd Mar 2011 19:53
Hello

A part of my code is about 100 lines long, the lines are almost the same. See code

Now my question is, how to simplify this code. I already give it a try but failed for the radius. Need to start from 0 and rise for each circle apart of eachother

thanks in advance
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 3rd Mar 2011 10:45
is this what you are trying to get to.



Dark Physics makes any hot drink go cold.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Mar 2011 10:53 Edited at: 3rd Mar 2011 10:55
Is this what you mean?


EDIT: HowDo beat me to it!! I think he's only increasing the radius by one though each loop... also it should be within the "if" condition too I think

1beginner1
15
Years of Service
User Offline
Joined: 28th Jun 2009
Location: Belgium
Posted: 3rd Mar 2011 17:37 Edited at: 3rd Mar 2011 19:55
Both have the same result, but not the one I wanted. They just make each new circle a bit bigger.
I searched on youtube for a video that shows what I want and I found a good one
http://www.youtube.com/watch?v=-Zu5SGllmwc&feature=related
EDIT: Want only to create the first animation showed in the video
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Mar 2011 18:03 Edited at: 3rd Mar 2011 18:10
You need to use an array to store the radius and position of each circle. Then each loop you need to increase the radius and edit the position slightly.

Use an array something like this:


Then each loop do something like this:


EDIT: To add a new circle during the loop you'll need to find a free slot in the array like this:


...but you may need to fade your circles out and make them not 'active' before there's any chance you can fill your array. The function will return a zero if you have used all 100. There are better ways around this but I need to go home now!

1beginner1
15
Years of Service
User Offline
Joined: 28th Jun 2009
Location: Belgium
Posted: 3rd Mar 2011 19:52 Edited at: 3rd Mar 2011 20:06
Don't get your code to work ( i am new to programming and never followed a course for it <-- so there is a big problem ), but you say
Quote: "Then each loop you need to increase the radius and edit the position slightly."

The position of each circle need to stay at the same position as it is positioned in the beginning. And you say I need to store the position of each circle but I can do it with a formula to position them, look at first post.
Please correct me if I am wrong.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Mar 2011 10:05
Quote: "The position of each circle need to stay at the same position as it is positioned in the beginning. And you say I need to store the position of each circle but I can do it with a formula to position them, look at first post.
Please correct me if I am wrong."

Aah, I was using the video you posted as an example (they move to the right on the video). Arrays are not the only way to solve this problem but that's how I would do it...

As far as I can tell you have several circles which increase in size gradually. You can either store the size of each circle as a variable or as part of an array. An array is more logical because you can just edit which part of the array to look at using your existing "for->next" loop.

Perhaps you could post more code to give a better example of what you are trying to achieve?

1beginner1
15
Years of Service
User Offline
Joined: 28th Jun 2009
Location: Belgium
Posted: 4th Mar 2011 17:26 Edited at: 4th Mar 2011 17:30
Ok, this is my complete code (changed 3d objects and background so you don't need to download the files). When you run it just type 3numbers (2 numbers of 2digits and 1 number of 3digits) and press F2. Then you see the circles being created.


Quote: "they move to the right on the video"

Just to make sure, the circles don't move their is just always a new circle created next the one before it.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Mar 2011 18:10
OK, I'm confused. What is not working here? Looks fine to me.

It makes the circles and they expand as the object goes past. What is happening not as it should?

1beginner1
15
Years of Service
User Offline
Joined: 28th Jun 2009
Location: Belgium
Posted: 4th Mar 2011 18:13
Like I said in the title, I want a code simplification for creating the circles so it uses less lines then now. For positioning them it worked fine (look first post) but for the radius I failed. Or isn't this possible or would I get back so much lines?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Mar 2011 18:36
OK, got it now...


There you go (using array as suggested)

1beginner1
15
Years of Service
User Offline
Joined: 28th Jun 2009
Location: Belgium
Posted: 4th Mar 2011 19:38 Edited at: 4th Mar 2011 19:38
Ok wow thanks, it is working perfectly and my code is shorter now. Tomorrow I am going to try to understand how the code with arrays work
Sorry for the confusing about the problem I posted.

Thanks once again for your help and time
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Mar 2011 19:03
No problem! Half the time on these forums the main problem is trying to work out exactly what the problem is!

I like finding solutions to problems.

It's well worth getting your head around arrays as they are very useful, as you can see.

Login to post a reply

Server time is: 2024-11-23 02:39:54
Your offset time is: 2024-11-23 02:39:54