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 2157 times)
Re: NOT Gate
Reply #15 - Mar 19th, 2009, 8:47am
 
Hello Noah , I have send you an email regarding my task ..The actual diagram looks like  the one in the email .. So if the mouse pressed  the input is indicated as "1" and the bottom line should be zero that means it should move backwards..
Re: NOT Gate
Reply #16 - Mar 19th, 2009, 4:52pm
 
I think the answer depends on whether you only need to draw the operation or truly simulate it.

For simply drawing:
Code:

...
void draw() {
background(255);

noFill();
rect(20,20,40,40);

if (inputvalue) {
//Z shape
line(20,30,50,30);
line(30,50,60,50);
line(50,30,30,50);
} else {
//draw default state
line(10,30,40,30);
line(40,50,70,50);
line(40,30,40,50);
}

}
...


For simulation, you may want to look into the BoxWrap2D library:
http://jbox2d.nfshost.com/processing/

It would be more complex to program, but would provide an animated operation of your NOT gate.
Re: NOT Gate
Reply #17 - Mar 19th, 2009, 5:17pm
 
Can we do it by replacing the lines with pictures that are being imported like nanotubes so that we can animate it by ourselves ?
Re: NOT Gate
Reply #18 - Mar 19th, 2009, 7:03pm
 
Yes.
There are a couple animation examples that come with processing or at:

http://processing.org/learning/topics/sequential.html

and
http://processing.org/learning/topics/animatedsprite.html
Re: NOT Gate
Reply #19 - Mar 19th, 2009, 7:10pm
 
If we  import three images for the three lines as we created ..will they move in the same manner  as the lines do ? .Because we dont need moving  pictures we just need  the images get moved when we give input right ?
Re: NOT Gate
Reply #20 - Mar 20th, 2009, 4:41pm
 
Yep.
If your images have the same width as the length of the lines, all you have to do is use the same first x and y coordinate of the horizontal lines.

If they are a difference size, you will have to scale those values.

For the angled line (the one that appears to rotate), using two images may be easier. You can rotate images if you want to try that though.

See this link for an example of rotating an image by a set amount.

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1213532886
Re: NOT Gate
Reply #21 - Mar 20th, 2009, 4:57pm
 
Thank you very much Smiley .. I will try it in that way..
Re: NOT Gate
Reply #22 - Mar 24th, 2009, 5:50pm
 
Hello  I have kept it in the class named NOT .I want to export it into the library .How can i do that ?

the final code is like this :

class NOT {
boolean inputvalue = false;//store the input state
PImage a;
PImage b;
PImage c;

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

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

 noFill();
 rect(20,20,40,40);
 a= loadImage("nanotube1.jpg"); // load image
 
 if (inputvalue) {
   //Z shape
   line(20,30,50,30);
   line(30,50,60,50);
   line(50,30,30,50);
 } else {
   //draw default state
   //line(10,30,40,30);
   image(a,10,30);
   line(40,50,70,50);
   line(40,30,40,50);
 }  
 
}  
}
Re: NOT Gate
Reply #23 - Mar 24th, 2009, 9:53pm
 
If you mean to export it for distribution, simply take it out of the NOT class.

Processing will put setup(), draw(), and mouseReleased() inside a class with the name of your sketch.

Then go to 'file->export' to put on a web page or 'file->Export Application' to run from disk.
Re: NOT Gate
Reply #24 - Mar 25th, 2009, 4:40am
 
Thank you Smiley
Re: NOT Gate
Reply #25 - Mar 25th, 2009, 3:49pm
 
Hello Noah I was asked to improvize these two points

2) See if you can make it inside a class, if possible,
and then see if there is a way to connect the output
of one to the input of another without having to actually
create the code for more than one.

3) Experiment with the "export" feature to see if there
is a way we can save our models as an .exe file.

Is this the third one you have told me ?
Re: NOT Gate
Reply #26 - Mar 26th, 2009, 9:45am
 
In reverse order:

The 'export as application' will create an *.exe. Java is still required and will direct the user to download if necessary.

An example of using a custom class is found here:

http://processing.org/reference/class.html

To have one 'feed' another like a circuit, you could use a reference to your NOT class inside that class.

Code:


class Not {
Not connectedTo;

Not {
//setup
}

void connectMeTo(Not cn) {
connectedTo = cn;
}

//to match the example
void update() {
//check the output of connectedTo
//change state based on that
//
//draw stuff
}

}


Now, to control more than one Not gate, you would have to add a test within the mouseReleased method to see if the mouse is over the gate. Similar to making your own button.

Re: NOT Gate
Reply #27 - Apr 9th, 2009, 4:56pm
 
Hello Noah,

                Can you please explain this class approach in detail.
Re: NOT Gate
Reply #28 - Apr 10th, 2009, 8:26am
 
I would probably follow this example:

http://processing.org/learning/topics/buttons.html

and create buttons for each NOT gate that you would like to display.

After clicking on one, make sure to update any that reference the gate that was clicked.

May not be exactly what you need:
Code:

//when NOT gate has been clicked
clickedGate.updateState();

...
//inside Not class
void updateState() {
//do update code for this gate

if (pointsTo != null)
pointsTo.updateState();

}

That way, any click will update the input of the next.

If you have specific questions, feel free to ask.
Pages: 1 2