dear PhilLho,
thanks for giving a "starting point". it really helped me.
i tried to put your script together with my script and now get some trouble while running.
actually my script has to do:
- drawing rects (20x20) when pressing a.
- by clicking one sets the starting point.
- when pressing Return the same sort of rect - line has to appear right under the previous line of rects.
- when clicking to another point, it has to start again.
- when pressing TAB the grid (your grid
appears.
my problem:
when pressing TAB the grid does not appear in the upper left corner (the inital defaut 0,0), but at the position of the mouse. which is no surprise, as i set everything at the position of mouseX, mouseY. But I just want my rectangles to appear at the position of the mouse. the grid has to be always at (0,0) (to give the user a sort of orientation where to set the rectangles).
i hope you know a way to get out of this
thanks a lot.
static final int GRID_SIZE = 50;
boolean bShowingGrid;
PGraphics drawing;
int breite = 40;
int hoehe = 60;
int wertX, wertY;
int x1, x2 = 40;
int count;
void setup() {
size (500,500);
background (0);
drawing = createGraphics (width, height, JAVA2D);
drawing.beginDraw();
drawing.background (0);
drawing.endDraw();
}
void draw() {
}
void mouseClicked() {
wertX = 0;
wertY = 0;
count = 0;
}
void keyReleased() {
translate (mouseX,mouseY);
x1 = breite/4;
x2 = hoehe/4;
wertX += x1;
wertY -= x2/5;
tastatur (wertX, wertY);
}
void DrawGrid()
{
stroke(#005588);
strokeWeight(1);
for (int i = 0; i < width; i += GRID_SIZE)
{
line(i, 0, i, height);
line(0, i, width, i);
}
}
void tastatur (float typeX, float typeY) {
switch (key) {
case ENTER:
count ++;
wertX = -count*x1/3;
wertY = count*x2;
break;
case 'a':
rect (typeX,typeY,20,20);
drawing.beginDraw();
drawing.rect (typeX, typeY, 20,20);
drawing.endDraw();
break;
case TAB:
{
bShowingGrid = !bShowingGrid;
if (bShowingGrid)
{
DrawGrid();
}
else
{
image(drawing, 0, 0);
}
}
break;
}
}