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


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 39 of 39

Thread: Java light source simulation

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,152
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Sep 2013
    Posts
    51
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Java light source simulation

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

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,152
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: Java light source simulation

    That would be a part of the algorithm.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    Sep 2013
    Posts
    51
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default 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. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,152
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default Re: Java light source simulation

    That's what we've been working on. Start with this one question:
    What are the rules for setting the lightedness for squares when there is a light source (hole) at a square in the array?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Member
    Join Date
    Sep 2013
    Posts
    51
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default 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. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,152
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    Member
    Join Date
    Sep 2013
    Posts
    51
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default 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
    }
    }
    Last edited by Bingo90; April 2nd, 2014 at 12:13 PM.

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,152
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #35
    Member
    Join Date
    Sep 2013
    Posts
    51
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default 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. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,152
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #37
    Member
    Join Date
    Sep 2013
    Posts
    51
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default 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. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,152
    Thanks
    49
    Thanked 2,158 Times in 2,131 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Bingo90 (April 2nd, 2014)

  15. #39
    Member
    Join Date
    Sep 2013
    Posts
    51
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Java light source simulation

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

Page 2 of 2 FirstFirst 12

Similar Threads

  1. The Light is ON!
    By yosukelight in forum Member Introductions
    Replies: 1
    Last Post: March 25th, 2014, 11:15 PM
  2. java simulation library
    By aceavong in forum Java Theory & Questions
    Replies: 1
    Last Post: March 12th, 2014, 05:45 AM
  3. Java Console American Football Simulation Tutorial/Example
    By TripleChickenJumpman in forum Java SE API Tutorials
    Replies: 0
    Last Post: January 4th, 2014, 05:40 PM
  4. Traffic Light problems
    By sircamolate in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 28th, 2011, 02:02 PM
  5. PeerSim P2P simulation based on JAVA
    By aditya149149 in forum Threads
    Replies: 0
    Last Post: August 24th, 2011, 04:26 PM

Tags for this Thread