rect1 = new RectButton(x, y, size, buttoncolor, highlight, s);
// Define and create rectangle button #2
x = 130;
y = 450;
size = 90;
buttoncolor = color(153, 153, 153);
highlight = color(102, 102, 102);
s = "OFF";
rect2 = new RectButton(x, y, size, buttoncolor, highlight, s);
// Define and create rectangle button #3
x = 230;
y = 450;
size = 90;
buttoncolor = color(102, 153, 102);
highlight = color(51, 102, 51);
s = "setup";
rect3 = new RectButton(x, y, size, buttoncolor, highlight, s);
}
void draw() {
background(0);
stroke(255);
button();
line (0, ycanvas, xcanvas, ycanvas);
line (xcanvas, 0, xcanvas, ycanvas);
line (1, 1 ,1 ,ycanvas);
line (1 , 1, xcanvas, 1);
rbt.beginDraw();
//red dot for right measurement
rbt.stroke(255, 0, 0);
rbt.pushMatrix();
rbt.translate((xpos+10), (ypos+10));
rbt.rotate(radians(rad));
rbt.translate(0, ymove);
//rbt.line((rxwall+10), 0, (xwall+10), 0);
rbt.point((xwall+10), 0);
rbt.popMatrix();
//blue dot for left measurement
rbt.stroke(0, 0, 255);
rbt.pushMatrix();
rbt.translate((xpos+10), (ypos+10));
rbt.rotate(radians(rad));
rbt.translate(0, ymove);
rbt.point((-xwall-10), 0);
rbt.popMatrix();
//green dot for front measurement
//rbt.stroke(0, 255, 0);
//rbt.point(xpos+5, (ypos-ywall));
rbt.endDraw();
image(rbt, 00, 00);
//create robot representation
pushMatrix();
translate(xpos+10,ypos+10);
rotate(radians(rad));
translate(0, ymove);
stroke(128);
noFill();
strokeWeight(2);
ellipse(0,0,10,10);
strokeWeight(1);
stroke(200);
line(0,0,0,-20);
line(0,-20,5,-15);
line(0,-20,-5,-15);
popMatrix();
// translate(0, -ymove);
}
void keyPressed(){
if (key == CODED) {
if (keyCode == UP){
// xpos = xpos-(cos(radians(rad))*1);
// ypos = ypos-(sin(radians(rad))*1);
ymove=ymove-1;
} else if (keyCode == DOWN){
ymove=ymove+1;
} else if (keyCode == RIGHT){
rad=rad+5;
} else if (keyCode == LEFT){
rad=rad-5;
}
}
if (xpos>=xcanvas){
xcanvas=xcanvas+150;
}else
if (ypos>=ycanvas){
ycanvas=ycanvas+150;
}
}
void button() {
//background(currentcolor);
stroke(255);
update(mouseX, mouseY);
rect1.display();
rect2.display();
rect3.display();
}
void update(int x, int y) {
if(locked == false) {
rect1.update();
rect2.update();
rect3.update();
} else {
locked = false;
}
//Turn LED on and off if buttons pressed where
//H = on (high) and L = off (low)
if(mousePressed) {
if(rect1.pressed()) { //ON button
currentcolor = rect1.basecolor;
println("on");
} else if(rect2.pressed()) { //OFF button
currentcolor = rect2.basecolor;
println("off");
} else if(rect3.pressed()) {
currentcolor = rect3.basecolor;
println("setup");
}
}
}
class Button {
int x, y;
int size;
color basecolor, highlightcolor;
color currentcolor;
boolean over = false;
boolean pressed = false;
String s;
void update()
{
if(over()) {
currentcolor = highlightcolor;
} else {
currentcolor = basecolor;
}
}
boolean pressed()
{
if(over) {
locked = true;
return true;
} else {
locked = false;
return false;
}
}
boolean over()
{
return true;
}
void display()
{
}
}
class RectButton extends Button {
RectButton(int ix, int iy, int isize, color icolor, color ihighlight, String is)
{
x = ix;
y = iy;
size = isize;
basecolor = icolor;
highlightcolor = ihighlight;
currentcolor = basecolor;
s= is;
}
boolean over()
{
if( overRect(x, y, size, size) ) {
over = true;
return true;
} else {
over = false;
return false;
}
}
void display()
{
stroke(255);
fill(currentcolor);
rect(x, y, size, size);
fill(0, 0, 0);
textAlign(LEFT, BASELINE);
text(s, x+20, y+(size/2));
}
}
boolean overRect(int x, int y, int width, int height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
the question is why does when i press up, the next rotation call would be error and if i continue press up the error will accumulate.. the goal is to create the circle to be controlled by key arrow. can anyone show me my mistakes?
i have this code and if I run the code, the result is static picture.. but according to my understanding it should move from right to left.. any silly mistakes that someone can find??
i`m new to processing and i`m trying some test to create a moving box with a path beside the box.. the box will move according to the mouse position and a line will follow the path that the mouse took. the moving box is done, but the line i created is also refreshed with the box.. is there any help with this?
i`m starting to use Processing for the 1st time, and wondering is there possible to yields 2 windows in 1 program? if it is possible how to do it then?