Schroedingers-Hat / jsphys

Libraries for physics simulation on javascript canvas
GNU Affero General Public License v3.0
11 stars 1 forks source link

Doppler-shifted light circle thingies #120

Open capnrefsmmat opened 12 years ago

capnrefsmmat commented 12 years ago

Currently drawCircle draws a white ring to represent a light flash. Presumably this ring should be colored according to the photon's wavelength, and Doppler shifted. But I'm not sure whether it makes sense to Doppler-shift the entire ring uniformly in color, or if it'll have to be different colors in different parts. This is hard to visualize.

Schroedingers-Hat commented 12 years ago

hrmm, hadn't thought of this it'd be different colours, but the relevant maths isn't done atm easiest way would bet to emit four (or more) photons radially when we want a ring and doppler shift them all. Then use that for a gradient. This will miss out on yellow and cyan some of the time (without large numbers of photons), but otherwise be a reasonable approximation.

This would actually represent the link between the way photons work (in this simulation) and the way you'd see things (and how apparent position+doppler works). If an object emits a light circle, then when it hits you, the colour you see its image, and the colour of the part of the light circle that interacts with you should match (if they matched to begin with).

capnrefsmmat commented 12 years ago

Hm. It seems, then, that a reasonable strategy would be to make light rings a separate object which creates four (or however many) photons moving in different directions. When lightRing.draw() is called, it would compute the colors of its constituent photons and set up a linear gradient:

https://developer.mozilla.org/en/Canvas_tutorial/Applying_styles_and_colors#A_createLinearGradient_example

Then we draw the circular path.

Does that sound sensible?

Schroedingers-Hat commented 12 years ago

that's pretty much what i had in mind

Schroedingers-Hat commented 12 years ago

might be able to do some trig to avoid redundant calculations

capnrefsmmat commented 12 years ago

I've committed a basic version of this to the lightFlash branch. My original implementation idea won't work perfectly; we'll need more than four photons, because as soon as the frame changes, the photons are not traveling perpendicular to each other, and so one side of the ring gets even Doppler-shifted gradients and the other doesn't.

I'll try upgrading to more photons soon.

capnrefsmmat commented 12 years ago

Hm. This is essentially the headlight effect in action, now that I think about it. Wonder if I can capitalize on that...

capnrefsmmat commented 12 years ago

So I'm fairly certain the current method -- create some photons to track -- isn't going to work directly. Under frame changes, the photons are no longer arranged nicely (due to the headlight effect), and so my current methods of keeping track of the light flash won't work.

@Schroedingers-Hat: If I rewrite lightFlash to use a different method, we could still do the headlight effect, if I adjust colors.js to let me fiddle with color brightness directly. Do you think that would be sensible? I'm worried about what has a sensible interpretation in a 2D view.