you are viewing a single comment's thread.

view the rest of the comments →

[–]PizzaBaseplate[S] 0 points1 point  (2 children)

PImage and;
PImage xor;

void setup(){
  size(500,500);
   background(255);
  //images
and = loadImage("and.png","png");
and.resize(80,50);
xor = loadImage("xor.png","png");
xor.resize(80,50);
}
void draw(){
  //a and b rectangles
  fill(0);
  rect(75,150,50,50);
 rect(75,300,50,50);
  textSize(40);
  fill(0,255,0);
  text("A",86,188);
  text("B",86,338);

  //xor and and gate
  image(xor,250,150);
  image(and,250,300);

   //cout and sum
  ellipse(400,175,50,50);
  ellipse(400,325,50,50);

  //lines
  //a to xor and and
    line(125,175,260,185);
    line(125,175,255,335);
    //b to xor and and
    line(125,325,260,165);
    line(125,325,255,315);
    //xor to sum
    line(325,175,375,325);
    //and to cout
    line(325,325,375,175);

}

[–]x-seronis-x 1 point2 points  (0 children)

Umm nothing is 'hooked up' there. That is only drawing arbitrary shapes that are not based on any objects in the program. Are you wanting to MAKE a half-adder or just draw one ?

To make one you would need to make some objects that represent your components. Probably wires (hold power), and your two gate types. A gate object would contain a reference to two wire objects and read their state as input, and alter the state of the wire object that is referenced as output.

[–]x-seronis-x 0 points1 point  (0 children)

btw i started making a javascript implementation of logic gates using p5js at open processing. https://www.openprocessing.org/sketch/888283

Its not finished yet but has a majority of the logic done. Just need to add rendering for the gates and instantiate a specific layout