pfalstad / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
1.64k stars 279 forks source link

I want to customize the color of the wire. #44

Open WenterQ opened 1 year ago

WenterQ commented 1 year ago

I want to customize the color of the wire. If there is no current passing, it is gray. If there is current passing, I want to customize the display color. How can I achieve this? Thank you!

PennRobotics commented 1 year ago

Neutral, positive, and negative voltage colors are changeable in the web interface via the menu: Options → Other Options

If you need to change it in the Java source: setColorScale()

WenterQ commented 1 year ago

The effect achieved is that some wires are yellow, some wires are blue, and so on

PennRobotics commented 1 year ago

... like wire-specific voltage colors? e.g. one wire at 5 volts is red while another at 5 volts is blue? That's an interesting use case.

It could be maybe confusing when two elements with different colors intersect---particularly components. If a resistor is 5 v blue at one end and 5 v red at the other, should the color blend? Should the max and min voltage for choosing color also be per-wire variable?

That would generally be cool for a circuit like "op-amp internals" or "555 internals" or some CPU register circuits, where you can split each subcircuit—level shifters, comparators, mirror, output stage—into its own color.

I don't know how the JavaScript elements are drawn, but the easiest way (for me) to implement this (if everything is an SVG) is by figuring out the id/data-name/class for each drawn component and override whatever property is being used for gradients AFTER everything is already drawn on the JavaScript-enabled page. I'm on my phone right now and haven't ever looked thru the new (non-java) source, so i don't know if anything in this paragraph would work. If I remember and have time, I'll try to do this soon

pfalstad commented 1 year ago

"If there is no current passing, it is gray." I suppose you mean that the amount of current is under some threshold value?

Changing the color for individual wires is not that bad, but every component has small pieces of wire embedded in it, so they would all have to change. Nothing is an SVG, unfortunately, all the drawing is done in code. I suppose you could store the wire color on a per-node basis and each element could get the color from the node.