We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Pages: 1 2 
NOT Gate (Read 2158 times)
NOT Gate
Mar 17th, 2009, 5:06pm
 
Hi, I am new to the processing and i am working on a project .I need to Create an application of not gate that is to draw a Line at a particular place and if mousepressed line should move towards right.I have just tried it by using MousePressed that is
line(20,30,50,30);
if (mousepressed)
line(40,30,70,30);

. My problem is I need the old line get deleted after new line appears .Could any one help me ?
Re: NOT Gate
Reply #1 - Mar 17th, 2009, 5:17pm
 
add background(128,128,128); before the first line(..);
Re: NOT Gate
Reply #2 - Mar 17th, 2009, 6:01pm
 
You mean inside the if(mousepressed) loop ?
Re: NOT Gate
Reply #3 - Mar 17th, 2009, 6:07pm
 
No, before any of the drawing is the best place, that way you're never going to have left-over drawn things on screen when you get to more complicated things.
Re: NOT Gate
Reply #4 - Mar 17th, 2009, 6:49pm
 
So if i keep the statement background() before first line , After second line is drawn do the first line dissappears ?
Re: NOT Gate
Reply #5 - Mar 17th, 2009, 6:57pm
 
venkata, the idea is to clear all the screen at the start of draw() routine (with background()), and re-draw all the graphics there. That's the base concept of Processing, although some special sketches use persistence of drawing between draw() calls.
Re: NOT Gate
Reply #6 - Mar 17th, 2009, 8:51pm
 
I think what you want is to use an if/else block:

Code:

background(yourfavoritecolor);

if (mousepressed) {
//draw the second line
line(40,30,70,30);
} else {
//draw the normal line
line(20,30,50,30);
}


This way, only one of the lines would be drawn.
Re: NOT Gate
Reply #7 - Mar 17th, 2009, 9:06pm
 
Actually the first line should be there at the beginning but after mouse click at one end the line should move towards right.that is as per properties of NOT gate when we give 1(Mouse click) as input output should be 0 as it should move towards right.
Re: NOT Gate
Reply #8 - Mar 18th, 2009, 5:58am
 
Do you mean to flip the state with each mouse click (instead of only showing when the mouse button is held)?

Code:

boolean inputvalue = false;//store the input state

void setup() {
size(100,100);
}

void mouseReleased() {
//toggle the input state
inputvalue = !inputvalue;
}

void draw() {
background(255);

if (inputvalue) {
//draw the second line
line(40,30,70,30);
} else {
//draw the normal line
line(20,30,50,30);
}

}
Re: NOT Gate
Reply #9 - Mar 18th, 2009, 6:14am
 
This is what i need exactly naohbuddy Smiley thank you very much
for this i just need to improve like this .. The nano not gate looks like this
(input)
    -------------- 1
                 /
                /
               /
              /
              ---------------
             2              (output)

when we give click on the input side( i.e input as "1" output should be 0) therefore the point 1 will move forward so that point 2 will move backward and the output goes backward (that is it indicates "0")
Can you please help me ?
Re: NOT Gate
Reply #10 - Mar 18th, 2009, 6:15am
 
Sorry the gate is not diplayed well it looks like Z shape.
Re: NOT Gate
Reply #11 - Mar 18th, 2009, 6:15am
 
There is a connection between positions 1 and 2
Re: NOT Gate
Reply #12 - Mar 18th, 2009, 7:27am
 
If I understand correctly, you only have to draw more lines (or other shapes) within the if/else block.

Since it is a not gate, there are still only two states.
Code:

if (inputvalue) {
//draw state one

} else { //same as NOT(inputvalue)
//draw state two

}

Sorry, I'm not sure exactly what it is supposed to look like.
Re: NOT Gate
Reply #13 - Mar 18th, 2009, 7:44am
 
Is there any other means to send you my exact question so that i can explain you clearly, i mean your email or so ... only thing is  the line for which you have written code should move forward and the  line at the bottom that is connected through a pivot should move backward to indicate zero output
Re: NOT Gate
Reply #14 - Mar 18th, 2009, 4:40pm
 
You can reach me by email through

buddyDOTnoah AT Google Mail DOT com

Replace AT with '@'
Google Mail with 'gmail'
and DOT with '.'
No spaces.
Pages: 1 2