This forum is in permanent archive mode. Our new active community can be found here.

Weekend coding

145791039

Comments

  • Processing seems to be Java-like.
  • If you tell me tomorrow to make something in F#, Clojure, Erlang, or Scala, I could do it.
    Dwarf Fortress in COBOL?
  • edited March 2011
    The Arduino and Wiring languages seem to be the same; essentially C/C++ with extra libraries.
    Processing is essentially Java, and you wouldn't be able to program a Processing program onto the Arduino without something like NanoVM or some kind of specialized native Java compiler for the Arduino.
    Post edited by lackofcheese on
  • If you tell me tomorrow to make something in F#, Clojure, Erlang, or Scala, I could do it.
    Dwarf Fortress in Mindfuck?
  • I think you mean Brainfuck.
  • I think you mean Brainfuck.
    Yep, I did, but I remembered wrong.
  • You're both wrong. One word.


    Assembly.
  • Brainfuck is harder to use than Assembly.
  • Agreed. Brainfuck is designed to be hard on purpose, like several other similar "joke" languages (INTERCAL, Malboge, etc.). Assembly is only hard because it's so closely tied to the hardware and so low-level that you need to be aware of every little detail of the program to get it to work. It doesn't go out of its way to sabotage your ability to write a useful program in it like Brainfuck and friends.
  • I should find my Brainfuck interpreter I wrote in assembly.
  • Oh? You should've written it in Brainfuck ^_~
  • Naa, write it in Malboge.
  • Found this gorgeous piece of code on SO.
    #include <stdio.h>
    #include <stdlib.h>

    void main(int j) {
    printf("%d\n", j);
    (main + (exit - main)*(j/1000))(j+1);
    }
  • Haha, I worked out what it would do before running it; I am pride.
    Nice find, Andrew.
  • edited April 2011
    Long code is loooooooooooooooong.
    Anyway, I finally have a version of the Gravity Applet that works to my satisfaction.
    Any recommendations for new features would be appreciated. (Oh and how can I embed this so that people don't have to compile it themselves to see how it works?)

    Right now, when you run it it randomly generates 30 point masses over the applet, it will then start figuring out how they will interact with each other. The force of gravity in the universe represented here is G*M*m/r as one would expect in a two dimensional universe, instead of the G*M*m/r^2 one expects in a three dimensional universe. As it is set up now it will show you the center of mass and the time elapsed as well. It uses the Vector object I designed for the purpose.

    Occasionally it will not run, this is most likely due to memory limitations, if you try twice and it does not run, reduce n so that less planets are simulated, or lengthen the increase dt so that it doesn't have to do as many calculations per second..

    Gravity Applet

    Vector object

    EDIT: Better?
    Post edited by GreyHuge on
  • Next time use Pastebin.
    Thank you, but could you not be so flippant about it, it seemed rude to me.
  • The force of gravity in the universe represented here is G*M*m/r instead of the standard G*M*m/r^2 as one would expect in a three dimensional universe , instead of the two dimensional universe that is being simulated here.
    I think you need to justify this better.
  • Next time use Pastebin.
    Thank you, but could you not be so flippant about it, it seemed rude to me.
    Sorry. Didn't meant to be rude.
  • I think you need to justify this better.
    Well, it comes from the original derivation of gravitational force by Sir Isaac Newton. I'm not entirely sure how to phrase it, but I'll give it my best shot. First, masses emit force particles. Second, these force particles contain some amount of momentum. Third, masses emit an amount of these particles per second that is constant over time. Fourth, that these particles move at a constant speed directly outward from the source. Fifth, when these particles encounter a mass, they impart this momentum to that mass. Sixth the amount of particles a mass absorbs is proportional to the mass of that mass.

    When you are in a three dimensional universe, these particles spread out over the surface of a sphere. The density of these particles when they encounter a mass determines the magnitude of the attraction, so it is proportional to: #ofParticles/(4*Pi*r^2), hence the inverse square law. In a two dimensional universe, the particles spread out over the surface of a circle so the attraction is proportional to #ofParticler/(2/Pi*r),so it is an inverse law.

    My writing is usually hard to follow, so pleas politely point out anywhere I've gone wrong.
  • Sorry. Didn't meant to be rude.
    I know. Thank you for your help.
  • edited April 2011
    When you are in a three dimensional universe, these particles spread out over the surface of a sphere. The density of these particles when they encounter a mass determines the magnitude of the attraction, so it is proportional to: #ofParticles/(4*Pi*r^2), hence the inverse square law. In a two dimensional universe, the particles spread out over the surface of a circle so the attraction is proportional to #ofParticler/(2/Pi*r),so it is an inverse law.
    But then you'd be saying that something with low mass but a lot of surface area should be more strongly attracted by gravity, which is plainly wrong.
    I don't think Newton posed things in terms of the particles you suggest.

    Granted, if you wanted to appropriately generalize gravity from 3D to 2D, you'd be applying General Relativity and not Newton's laws.
    Post edited by lackofcheese on
  • But then you'd be saying that something with low mass but a lot of surface area should be more strongly attracted by gravity, which is plainly wrong.
    Are you sure? Can you explain your complaint more?
  • edited April 2011
    Well, if you postulate this in terms of "force particles" that spread out as they move further and further away, then wouldn't an object with a large surface area but low mass catch quite a lot of "force particles"? Indeed, an object whose surface area is twice as large would catch twice as many force particles, and hence be attracted with twice the force, no?
    Post edited by lackofcheese on
  • Well, if you postulate this in terms of "force particles" that spread out as they move further and further away, then wouldn't an object with a large surface area but low mass catch quite a lot of "force particles"? Indeed, an object whose surface area is twice as large would catch twice as many force particles, and hence be attracted with twice the force, no?
    Your objection makes sense, but I can't remember for the life of me how I addressed this when I originally derived the equation a year or two ago. I'll have to get back to you. Anyway, I did not come here to debate the assumptions I made about the universe I am simulating, I came here to receive criticism on the code that simulates that universe. So if you have some comment on my code I would be more than happy to discuss it.
  • Your objection makes sense, but I can't remember for the life of me how I addressed this when I originally derived the equation a year or two ago.
    I think I just remembered it. It doesn't matter because everything is point masses, saying that one is larger or smaller does not have any meaning. Unfortunately this doesn't bode well for the same argument in a universe where nothing is point masses, though it does seem to work out for the most part in ours.
  • edited April 2011
    I updated it to use floats instead of doubles, so I did. Right now I am running a simulation with 120 objects. It looks pretty good.
    Gravity Applet (float)
    Vector Object (float)

    Okay, this is getting an argument out of bounds every time I start it with a large number of objects. Does this have anything to do with me running out of memory?

    EDIT: I made it reinitialize the counter variables each time and that has cleared up most of the errors. I also made it so that if any two masses occupy the same space that the force exerted is zero.
    Post edited by GreyHuge on
  • For some reason I'm getting a lot of errors from java.util.Vector when I try to run your code. Is there somewhere I can download this, do I have to change my classpath, or what?
  • For some reason I'm getting a lot of errors from java.util.Vector when I try to run your code. Is there somewhere I can download this, do I have to change my classpath, or what?
    What kind of errors?
Sign In or Register to comment.