ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Help with Processing 1.0

(1/1)

SteveK21:
I am working from this code and was wondering if anyone had any tips on how to get each book 2 drop down into a bin by using a key press...

Book myBook1;
Book myBook2;
Book myBook3;
Book myBook4;

void setup()
{
  size(300,300);
  myBook1 = new Book(color(255,0,0),120,200,1);
  myBook2 = new Book(color(0,0,255),80,200,1);
  myBook3 = new Book(color(0,255,0),40,200,1);
  myBook4 = new Book(color(100,100,100),0,200,1);
}

void draw()
{
  background(255);
  myBook1.move();
  myBook1.display();
  myBook2.move();
  myBook2.display();
  myBook3.move();
  myBook3.display();
  myBook4.move();
  myBook4.display();
  line(0, 204, 250, 204);
}

class Book
{
  color c;
  float xpos;
  float ypos;
  float xspeed;

  Book(color tempC, float tempXpos, float tempYpos, float tempXspeed)
  {
    c = tempC;
    xpos = tempXpos;
    ypos = tempYpos;
    xspeed = tempXspeed;
  }

  void display()
  {
    stroke(0);
    fill(c);
    rectMode(CENTER);
    rect(xpos,ypos,35,5);
  }

  void move()
  {
    xpos = xpos + xspeed;
    if (xpos > width)
    {
      xpos = 0;
    }
  }
}

jgpaiva:
Hmm, that looks like school work, right?
What language is it? Oh, Processing 1.0. Didn't know such language existed :)

I can't see any Bin in that code, so I suppose you should start by making one. You could take the book as example, I think. The main difference would be that the Bin wouldn't have the move() function.

mahesh2k:
Maybe you need to ask this question in Discourse section of Processing.org

@jgpaiva, such language does exist. It's made to run on top of JVM,processing sketches run as applets.

Navigation

[0] Message Index

Go to full version