but i cant draw network with out room, i can draw (myself :D ) but the main idea send information about room from my robot on arduino board buid room and count area of room
when i draw some figure i see legth of lines but i need area for example i drew rect and i need area of this rect but i have only legth of lines, i multiply big side on small side and get area of this figure
I am not proud on this code, but it works for your purpose....
// the states
// consts for states
final int NORMAL = 0; // normal state
final int ALERT = 1; // alert / shows the msgbox
// current
int state = NORMAL;
boolean locked=false;
// this is the object msgBox
MsgBox msgBox = new MsgBox();
boolean msgboxHasBeenCalled = false;
// cam
PVector camPos; // its vectors
PVector camLookAt;
PVector camUp;
// cam rotation
float camCurrentAngle; // for cam rot around center
float camRadius; // same situation
// Font
PFont font1 ;
// --------------------------------------------------------
// main funcs:
void setup() {
size(800, 800, OPENGL);
// set cams vectors
camPos = new PVector(width/2.0, height/2.0, 600);
camLookAt = new PVector(width/2.0, height/2.0, -210);
camUp = new PVector( 0, 1, 0 );
background(111);
font1 = createFont("Arial", 32);
textFont(font1);
//
} // func
void draw() {
background(111);
lookAtAngle();
camera (camPos.x, camPos.y, camPos.z,
camLookAt.x, camLookAt.y, camLookAt.z,
camUp.x, camUp.y, camUp.z);
lights();
fill(255);
// noStroke();
translate(width/2, height/2);
box (61);
// camera
if (state==NORMAL && !keyPressed)
camCurrentAngle++;
lookAtAngle();
// upper left corner
HUD_text("Hit return for MsgBox.");
// this is the msgbox
msgBox.msgBoxDisplay();
//
} // func draw()
// ----------------------------------------------------
// input funcs
void mousePressed() {
switch (state) {
case NORMAL:
// do nothing
break;
case ALERT:
msgBox.mousePressedForMsgbox();
break;
default:
// error
println ("Error 139");
break;
} // switch
} // func
void keyPressed () {
switch (state) {
case NORMAL:
if (key=='X') {
//
}
else if (key>='0' && key <= '9') {
//
}
else if (key == RETURN || key == ENTER) {
// start msgbox
msgBox.msgBox("Do you want to exit the program?", msgBox.tOB_YesNo);
}
else if (key==ESC) {
// key=0;
}
else {
//
}
break;
case ALERT:
msgBox.keyPressedForMsgbox();
break;
default:
// error
println ("Error 296");
break;
} // switch
} // func
// ----------------------------------------------------
// misc funcs
void lookAtAngle() {
// rotation in the plane : cam
camRadius = camLookAt.dist (camPos);
// camRadius = 100;
camPos.x = camRadius * cos (radians(camCurrentAngle)) + camLookAt.x;
camPos.z = camRadius * sin (radians(camCurrentAngle)) + camLookAt.z;
} // func
void HUD_text (String a1) {
// HUD text upper left corner
// this is a 2D HUD
camera();
hint(DISABLE_DEPTH_TEST);
noLights();
// ------------------
textSize(16);
text (a1, 20, 20);
// ------------------
// reset all parameters to defaults
textAlign(LEFT, BASELINE);
rectMode(CORNER);
textSize(32);
hint(ENABLE_DEPTH_TEST); // no HUD anymore
lights();
}
// =====================================================
class MsgBox {
// the string to display
String alertText = "";
// position and size and innerboder
int posX, posY;
final int msgboxW = 400;
final int msgboxH = 200;
final int innerBorder1=14;
// the ok box
final int innerBorder2 = 8;
final int okBoxAddY = 40;
final int okBoxW = 60;
final int okBoxH = 30;
RectButton[] rectButtons = new RectButton[3];
int btnLength = -1;
// colors
color col1=color(222);
color col2=color(255);
// typeOfButtons
final int tOB_OK = 0; // consts
final int tOB_YesNo = 1;
final int tOB_OKCancel = 2;
int typeOfButtons;
// type of return
final int OK = 0;
final int YES = 1;
final int NO = 2;
// no constructor here
void msgBox ( String a1 ) {
// this activates the message box
// simple OK, no return value
alertText = a1;
state = ALERT;
msgboxHasBeenCalled = true;
} // method
void msgBox ( String a1, int typeOfButtonsTemp ) {
// this activates the message box
alertText = a1;
state = ALERT;
msgboxHasBeenCalled = true;
typeOfButtons = typeOfButtonsTemp;
switch (typeOfButtons) {
case tOB_OK:
msgBox(a1);
break;
case tOB_YesNo:
//
break;
case tOB_OKCancel:
//
break;
default:
// error
break;
}//switch
} // method
void msgBoxDisplay() {
// Shows the msgbox (centered on the screen).
// Call this from draw() always (and at the end).
// It's active only when the state is ALERT.
if (state==ALERT && !alertText.equals("")) {
posX=width/2;
posY=height/2;
// this is a 2D HUD
camera();
hint(DISABLE_DEPTH_TEST);
noLights();
// the outer box / msgbox
noStroke();
fill(90);
rectMode(CENTER); // Set rectMode to CENTER
rect (posX, posY, msgboxW, msgboxH);
// a frame
strokeWeight(1);
noFill();
stroke(211);
rect (posX, posY, msgboxW-innerBorder1, msgboxH-innerBorder1);
// the X top left
textSize(16);
textAlign(CENTER, CENTER);
/*
fill(255, 0, 0); // red
text ("X", posX+msgboxW/2-innerBorder1-4, posY-msgboxH/2+innerBorder1+4);
*/
// the variable text
fill(244);
textAlign(LEFT, CENTER);
text (alertText, posX-msgboxW/2+innerBorder1, posY-msgboxH/2+2*innerBorder1);
// the OK box
textAlign(LEFT, BASELINE);
rectMode(CORNER);
switch (typeOfButtons) {
case tOB_OK:
setupButtonOK();
break;
case tOB_YesNo:
setupButtonsYesNo();
break;
case tOB_OKCancel:
break;
default:
// error
break;
}//switch
drawButtons();
// reset all parameters to defaults
textAlign(LEFT, BASELINE);
rectMode(CORNER);
textSize(32);
hint(ENABLE_DEPTH_TEST); // no HUD anymore
lights();
} // if
} // method
// inputs
//
void keyPressedForMsgbox() {
if (key==ESC||key==RETURN||key==ENTER||key==' ')
state=NORMAL;
// if (key==ESC)
key=0;
} // method
void mousePressedForMsgbox() {
switch (typeOfButtons) {
case tOB_OK:
if (rectButtons[0].Exists) {
if (rectButtons[0].over) {
state = NORMAL;
} // if
} // if
break;
case tOB_YesNo:
if (rectButtons[0].Exists) {
if (rectButtons[0].over) {
exit();
} // if
} // if
state = NORMAL;
break;
case tOB_OKCancel:
break;
default:
// error
break;
}//switch
} // method
void drawButtons () {
// List of Buttons
// draw buttons
for (int i=0; i<btnLength; i++) {
if (rectButtons[i].Exists) {
// set colors
rectButtons[i].update();
// display
rectButtons[i].display();
}
}
} // function
// command buttons on the screen
// Init Buttons
void setupButtonsYesNo () {
// for the command-buttons on the screen
// int CmdButtonsX = width-140;
// int CmdButtonsDistance = 40;
int j;
// Pre-Init: All Buttons OFF
for (int i=0; i<btnLength; i++) {
rectButtons[i] = new RectButton( 1, 1, 20, 20, col1, col2, false);
}
// Init Button2
j=0;
rectButtons[j] = new RectButton( posX-80-45, posY+okBoxAddY,
90, 28,
col1, col2, true);
rectButtons[j].Text ="Yes";
// Init Button
j++;
rectButtons[j] = new RectButton( posX+80-45, posY+okBoxAddY,
90, 28,
col1, col2, true);
rectButtons[j].Text ="No";
j++;
btnLength=j;
} // function
void setupButtonOK () {
// for the command-buttons
//int CmdButtonsX = width-140;
//int CmdButtonsDistance = 40;
int j;
// Pre-Init: All Buttons OFF
for (int i=0; i<btnLength; i++) {
rectButtons[i] = new RectButton( 1, 1, 20, 20,
col1, col2, false);
}
// Init Button
j=0;
rectButtons[j] = new RectButton( posX-45, posY+okBoxAddY,
90, 28,
col1, col2, true);
rectButtons[j].Text ="OK";
j++;
btnLength=j;
} // function
//
} // class
// ====================================================================================
// class Button and RectButton
class RectButton extends Button {
// constr
public RectButton(int ix, int iy,
int isizeX, int isizeY,
color icolor, color ihighlight,
boolean iExist) {
x = ix;
y = iy;
sizeX = isizeX;
sizeY = isizeY;
basecolor = icolor;
highlightcolor = ihighlight;
currentcolor = basecolor;
Exists = iExist;
Text = "";
}
boolean over() {
if ( overRect(x, y, sizeX, sizeY) ) {
over = true;
return true;
}
else {
over = false;
return false;
}
}
void display() {
if (Exists) {
if (Tag.equals("None")) {
//
}
else {
// command
stroke (ButtonStrokeColor);
strokeWeight(1);
fill(currentcolor);
rect(x, y, sizeX, sizeY);
if (Text != "") {
fill(0);
textAlign(CENTER);
textSize(16) ;
text(Text, (x + (sizeX / 2.0)), (y + (sizeY / 2.0))+5);
} // if (Text != "")
} // else
} // if exists
} // method display
//
} // class
// ===============================================================
class Button {
int x, y;
int sizeX;
int sizeY;
color basecolor, highlightcolor;
color currentcolor;
boolean over = false;
boolean pressed = false;
boolean Exists = false;
String Text = "";
String Tag = "";
// int Tag2 = 0;
// int TagMark = 0;
color ButtonStrokeColor = color (255, 255, 255);
void update() {
if (over()) {
// Mouse over
currentcolor = highlightcolor;
}
else {
// not Mouse over
currentcolor = basecolor;
}
} // update
boolean pressed() {
if ( over()) {
locked = true;
return true;
}
else {
locked = false;
return false;
}
} // pressed;
boolean over() {
return true;
} // over
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;
}
} // overRect
} // class
// =========================================================
if(button1[i])
{
float sum;
sum = currArea/6;
println(sum);
for(int m=1; m <= sum; m +=1)
{
if ( true)
{
if (mouseY > 120)
{
strokeWeight(4);
rect(mouseX-18,mouseY-14,36,28);
image(img1, mouseX-18,mouseY-14,36,28);
}
}
}
fill(0,255,0);
}
please look here, i want to dwar room and put in PC in this room, for example i have 120 m2 (room) i want to put in 20 pc ( 6 m2 for 1 PC) in this code i draw for(;;) but it dont count "m+=1" and because of this dont work
look a draw a room with line, in this room 120 meters squared, for 1 computer you need 6 meters squared i 120 divide 6 and get 20, i put in my room (rect which i draw with lines) only 20 computers not more
Answers
code
you have two totally different programs in this one thread?
here i draw room insade which i will make network
very impressive
you worked very hard
but i cant draw network with out room, i can draw (myself :D ) but the main idea send information about room from my robot on arduino board buid room and count area of room
can you help me with count?
here
you mean count result = 12 ?
yes look i draw a room inside which i make network and now i want to know area of black figure (walls or room which i make with line) i need AREA
square which write my program is wrong its cable length
I have no idea
make a new thread because it has nothing to do with the rest
may be side A ( big side) multiply B side (short) - side which we havent but i dont know how to do it(http://forum.processing.org/two/uploads/imageupload/079/NX74KAMZIB4A.jpg "file-4327")
please look this and i will start new thread in the morning
I dunno
how to count area of rect if i draw big rect
I made a flood fill once
remove all network
leave room walls
somebody could flood fill the room with red
count all red afterwards
but the room must be closed
I dunno
¯\ (°_o) /¯
??
you wrote
when you draw one rect, afterwards you click a button "measure area" and then you click inside the area. Then it could be done.
Is this what you want?
when i draw some figure i see legth of lines but i need area for example i drew rect and i need area of this rect but i have only legth of lines, i multiply big side on small side and get area of this figure
this works for the first two lines and multiplies them (like for a rect)
ArrayList<Float> distances = new ArrayList();
what is this?
When you dunno something, look for it in Processing's reference 1st! [..]
http://processing.org/reference/ArrayList.html
Although for ArrayList<Float>, I'd prefer FloatList. For it's both simpler & faster than the former! :D
processing.org/reference/FloatList.html
here is a little msgbox that pops up
just hit return
line 159 to 446 you can just copy and paste (without reading them)
then you need line 108
line 10 to 12
mainly
holy cow! i think now its difficult for me
line 159 to 446 you can just copy and paste (without reading them)
this is not enough i think
line 159 to 446 you can just copy and paste (without reading them)
then you need line 108
line 10 to 12
mainly
again: you fail to describe what you want
do you know how to "exite" from program and "roll up" program??
for exit / end program use command exit();
what means "roll up"? Restart?
first button-exit; second- i dont know (i dont need) AND THIRD BUTTON- ROLL UP (MAY BE =) )
what's roll up - return to program?
close the extra window?
:)
I am not proud on this code, but it works for your purpose....
another one question, for example i drew some figure and want to delete it ( back up) but i have no idea how to do it
I posted this already
when you hold q on the keyboard you delete canvas with the mouse (press mousebutton)
a more professional way would be to store that what you have drawn as data in your sketch (lines and rects)
then the sketch draws the data
then you can delete last line or last rect (or any of the lines)
but this is very advanced and we are not going to do it
please check this one, when i count area of figure i get i number, when i destroy this figure with
i get currArea=0; ( was for example 180) and when i "clear window" and draw figure againe i still have 0 ( after delete with background(250);)
your code is very hard to read
please use ctrl-t to format your code
please read about arrays and use them for your images
please read about arrays and use them for your buttons
please do the tutorial on OOP and use it for your buttons
your question
currArea only works for the first two lines
you need to reset it with distances.clear() every time
sorry but this part dont work( i draw image but cannot delete it
it works
press and hold q
delete stuff with mouse while still holding q
i wrote this but it dont work because of error "expecting colon found =" what it can be
you need to use ; not the ,
please look here, i want to dwar room and put in PC in this room, for example i have 120 m2 (room) i want to put in 20 pc ( 6 m2 for 1 PC) in this code i draw for(;;) but it dont count "m+=1" and because of this dont work
for (int m=1; m <= sum; m++)
and please use ctrl-t to format your code
and please don't write if (true), it is not necessary, since true is always true. You need to remove { and } as well when you remove this.
Sorry i cant formar code ( ctrl T open new windows in my browser) but i still draw more then 20 pc it dont count m +1 every time
you have to press ctrl-t in processing (in the IDE)
not in the browser
you want to draw 20 PCs at the mouse-position (-18,-14)? That makes no sense -
maybe the for-loop gets called more often than 1 time?
look a draw a room with line, in this room 120 meters squared, for 1 computer you need 6 meters squared i 120 divide 6 and get 20, i put in my room (rect which i draw with lines) only 20 computers not more