Good morning. Thanks to jb4x I been able to draw a simple electric circuit
boolean isOpen;
float Vpila=10.0;
float R1=100.00;
float Rv=500.00;
float DR=5.00;
float color_alpha=0;
float I=0.00;
void setup() {
size(600, 600);
isOpen = true;
}
void draw() {
background(200); // CLear the screen
fill(255);
ellipse (300, 150, 40, 40);
line (280, 150, 120, 150);
line (120, 150, 120, 220);
stroke (0);
if (!isOpen) {
line (120, 220, 120, 290); //closed circuit
}
line (120, 290, 120, 380);
if (isOpen) {
line (80, 240, 120, 290); // open circuit
//line (120,220,120,300);
}
line (320, 150, 500, 150);
line (500, 150, 500, 250);
line (500, 250, 500, 380);
line (500, 380, 350, 380);
rect (250, 350, 100, 50);
line (250, 380, 120, 380);
ellipse (500, 250, 40, 40);
if (isOpen) {
fill(0);
} else {
fill(255);
}
ellipse (500, 250, 40, 40);
line (270, 320, 325, 425);
}
void mouseClicked() {
isOpen = !isOpen;
}
And works fine
The purpose of the exercise is to control with up & down the value of the variable resistance, and thus making the alpha channel of the bulb higher or lower.
I have a concept like this one
void setup() {
Vpila = 10.0; // Battery voltage in volts
Rl = 100.0; // Bulb resistance in Ohms
Rv=500.0; // Initial variable resistance in Ohms
DR=5.; // Incremental step of variable resistance in ohms
color_alpha= 0; // Initial transparency in zero
start = false; // Closed switch
}
//
// In draw() animations are implemented
//
void draw() {
if (start) { // Close switch.
I = Vpila/Req; // Intensity in the circuit, Ohm’s LawLlei
color_alpha = 255*I/Imax; // Brightness is proportional to intensity using alpha transparency
}
//
// For changing the value of variable resistance we use UP for increasing resistance
//
void keyPressed() { //
if (key == CODED & keyCode == UP ) {
Rv = Rv+DR;
}
}
// Mouse click closes swith and simulation begins
void mouseClicked() {
start = true;
}
// End
But the problem is that i’m not able to integrate the design with the bulb glowing function.
I’m really an absolute begginer and by now this seems very difficult for me.
Thanks to all