Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Java light source simulation

1. ## Re: Java light source simulation

If you have the algorithm for how to set the intensity for squares when a hole is made,
and have written the code for it,
can you explain what your problem is?

2. ## Re: Java light source simulation

When placing a wall, it should remove the light from the no longer existing light source.

3. ## Re: Java light source simulation

That would be a part of the algorithm.

4. ## Re: Java light source simulation

I know, that's why I made a thread here. I don't know how I can achieve this.

5. ## Re: Java light source simulation

What are the rules for setting the lightedness for squares when there is a light source (hole) at a square in the array?

6. ## Re: Java light source simulation

It only updates when placing or removing a wall. There are 2 arrays, a byte array (the light values) and a wall array(the walls). I told you how the light spreads.

7. ## Re: Java light source simulation

I told you how the light spreads.
If you know how the light spreads, you should be able to describe the algorithm in words to get a design for writing the code.

What are you trying to get from this thread? I thought you wanted to work on the algorithm. One of the steps is defining how the light is spread when a new source/hole appears. Given an x,y location for that hole, how will the light intensities be set for the near and far adjoining squares?

8. ## Re: Java light source simulation

Okay, this is how it works (some kind of pseudocode)

void removeWall(int x, int y)
{
setWall(x,y,null);
updateLight(x,y);
}

void updateLight(int x, int y)
{
if(getWall(x,y) == null -> If there's no wall)
{
sets the light level to the lamp's light level and does this for each adjacent space:

checks if the light level is less than the light level of this space -1
if so, it sets the light level to the light level of the space -1 and calls the updateLight method on this position
}
else
{
does this for each adjacent space:

checks if the light level is less than the light level of this space -1
if so, it sets the light level to the light level of the space -1 and calls the updateLight method on this position
}
}

9. ## Re: Java light source simulation

sets the light level to the lamp's light level and does this for each adjacent space:
There are up to 8 near adjacent spaces. What is the level that is to be set for those squares?
What about the next set of spaces in the surrounding ring? and the next one out?
What happens when at edge of the array?

if(getWall(x,y) == null)
What does that mean? That looks like code, not some text for the algorithm.

10. ## Re: Java light source simulation

sets the light level to the lamp's light level and does this for each adjacent space:
There are up to 8 near adjacent spaces. What is the level that is to be set for those squares?
What about the next set of spaces in the surrounding ring? and the next one out?
What happens when at edge of the array?
There's a colon, updated the post and quoted it to make it more understandable

11. ## Re: Java light source simulation

checks if the light level is less than the light level of this space -1
Is that comparing the square at x,y with its adjacent squares and using the value - 1 of the light intensity of the square at x,y?

For testing I'd recommend a small 2D array with a given hole. Run the code with the small array and print out the contents of the array to see if the values are what you want.

12. ## Re: Java light source simulation

Light spreading works fine when removing a wall. But it'll do absolutely nothing when placing a wall, because I haven't implemented the code yet. I tried, but I have no idea how to do this :/

13. ## Re: Java light source simulation

I assume replacing a wall means the removing of a hole/light source. The requirements then are to restore the light intensities to what they were before the hole was made and to consider any changes made after that hole was made.

One approach would be to pass over the whole area and set the intensities again for each hole.

14. ## The Following User Says Thank You to Norm For This Useful Post:

Bingo90 (April 2nd, 2014)

15. ## Re: Java light source simulation

Hmm that could work... I'll try that.

Page 2 of 2 First 12