Python Diffraction applet - how to make one in one day

AI Thread Summary
A user is seeking assistance to create a diffraction applet within a tight deadline of one day, although they clarify they technically have three days. They possess knowledge of diffraction but lack experience in app development, having only done minimal programming in Python. The applet needs to simulate multiple slit diffraction for a single wavelength of light, ideally without complex controls, although the ability to adjust wavelength would be beneficial. Responses emphasize the difficulty of completing such a project in the given timeframe, even for experienced programmers. Suggestions include using Python with libraries like SciPy and XRT, or considering JavaScript for web compatibility. Alternatives such as using a Python-to-Java compiler or the Processing IDE are recommended, as Processing is beginner-friendly and includes built-in graphics capabilities. Additionally, resources like the Wolfram Demonstration Project are mentioned as potential starting points for editing existing simulations.
erisedk
Messages
372
Reaction score
7
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.
 
Technology news on Phys.org
erisedk said:
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.
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.
 
DrClaude said:
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.

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 learned 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.
 
erisedk said:
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 learned 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.

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.
 
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.
 
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.
 
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.
 
Back
Top