Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Python Diffraction applet - how to make one in one day

  1. Sep 2, 2016 #1
    I'm not sure which forum this would go into, but I'm desperate so I'll just post here.

    So, I have exactly one day to make a diffraction applet. I know a lot about diffraction, nothing about making applets. I've programmed a tiny bit in python, but never made an actual project before.

    Here's an email describing what I need to make

    HI erisedk, Thanks for the questions:

    Is the simulation supposed to include only single slit diffraction or both single slit and multiple slit (diffraction grating)?

    Ans: only multiple slits (say 10, for concreteness). And I wouldn’t worry about the single-slit envelope, since the grating slit width is usually small enough that the light diffracts into the forward half-plane.

    Should it model only a single wavelength of light or should you be able to model any number of wavelengths, including white light?

    Ans: Just one wavelength. It will be for light, but you don’t need to constrain yourself to that. In particular, the applet I was looking at was http://falstad.com/ripple/ Setup: plane wave 1 plane source, 1 frequency Edit walls, and then put in a periodic grating (at least on my computer there’s a location indicator is the lower left — the slits must be equally spaced and of equal size). Note: Changing the resolution erases any modifications. 2nd note: if you can figure out what the coding for the import file is (just put some walls in and look at the export text), you could do the whole thing by numbers, and it would be very easy to modify to find the best setting. (I have no idea what the second part of the answer means)

    Are there any very specific controls that you would like to see, that are not commonly available in most applets?

    Ans: For this I’d be happy with a video (i.e., no controls). Though if there was to be any controls, then controlling the wavelength (to show how different colors diffract in different directions) would be good.

    These are the details. I'd be so grateful for help, especially, step by step instructions.
     
  2. jcsd
  3. Sep 2, 2016 #2

    DrClaude

    User Avatar

    Staff: Mentor

    In one day? Forget about it. Even if you were a seasoned programmer, I would be surprised if you could pull that off in one day.
     
  4. Sep 2, 2016 #3
    Well, I technically had 3 days to do it. But I couldn't figure out how to get started really. I downloaded scipy and xrt for python and read a bit. I learnt about diffraction. But I feel so technically challenged. I could at the most turn it in on Sunday I think. I'm willing to spend all my time on it (like literally, no sleep no eat etc). I just need to get it done. Please help!!

    Also, I think that the tag shouldn't be java, it should be python.
     
  5. Sep 2, 2016 #4
    If you need your simulation to run in a web browser, I would think JavaScript is the sensible option.

    However, due to time constraints and as I understand it, Python is the language you are most comfortable with, it is possible to make do. The options I think you have are to write your simulation in python and use a python to java compiler such as "pyjamas", or use "empythoned" to run CPython in your browser.

    Take a look at PyGame as an environment to house your physics simulation.
     
  6. Sep 2, 2016 #5

    jedishrfu

    Staff: Mentor

    I would use processing IDE for this. Download it look at the tutorials on the site and go for it. In general, I'd guess it would be about 50 lines or less to do. Processing comes with examples, has the graphics built in. You'd be using Java but they provide the wrapper. All you to provide are two methods setup which runs once and draw which is called every sixtieth of a second. Processing geared toward beginners and graphic artists who want to code.

    https://processing.org/examples/reflection1.html

    More examples and animations here

    https://processing.org/examples/

    Processing does have a python/jython mode that works in a similar fashion with examples too.
     
  7. Sep 2, 2016 #6

    jedishrfu

    Staff: Mentor

    If you have an iPhone or iPad then there's the pythonista app to consider at around $5 which works in a similar fashion to processing. You'd have to hand in your phone to get a grade haha or you could video record the app running.

    There's also a processing app on both iPhone and android too. On iPhone it's JavaScript based and on android it's Java based.
     
  8. Sep 2, 2016 #7
    Would look nice and professional encapsulated in a Mathematica Manipulate. Are you familiar with the Wolfram Demonstration Project? You could download one that is similar and just edit it for your needs.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Diffraction applet - how to make one in one day
Loading...