# Java light source simulation

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• April 2nd, 2014, 11:03 AM
Norm
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?
• April 2nd, 2014, 11:05 AM
Bingo90
Re: Java light source simulation
When placing a wall, it should remove the light from the no longer existing light source.
• April 2nd, 2014, 11:08 AM
Norm
Re: Java light source simulation
That would be a part of the algorithm.
• April 2nd, 2014, 11:10 AM
Bingo90
Re: Java light source simulation
I know, that's why I made a thread here. I don't know how I can achieve this.
• April 2nd, 2014, 11:33 AM
Norm
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?
• April 2nd, 2014, 11:42 AM
Bingo90
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.
• April 2nd, 2014, 11:45 AM
Norm
Re: Java light source simulation
Quote:

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?
• April 2nd, 2014, 11:58 AM
Bingo90
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:

Quote:

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:

Quote:

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
}
}
• April 2nd, 2014, 12:05 PM
Norm
Re: Java light source simulation
Quote:

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?

Quote:

if(getWall(x,y) == null)
What does that mean? That looks like code, not some text for the algorithm.
• April 2nd, 2014, 12:12 PM
Bingo90
Re: Java light source simulation
Quote:

Quote:

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
• April 2nd, 2014, 12:17 PM
Norm
Re: Java light source simulation
Quote:

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.
• April 2nd, 2014, 12:23 PM
Bingo90
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 :/
• April 2nd, 2014, 12:46 PM
Norm
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.
• April 2nd, 2014, 12:56 PM
Bingo90
Re: Java light source simulation
Hmm that could work... I'll try that.
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12