summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netchasketch.pde25
-rw-r--r--test/netchasketch.pde25
2 files changed, 44 insertions, 6 deletions
diff --git a/netchasketch.pde b/netchasketch.pde
index 0a856c5..74089c0 100644
--- a/netchasketch.pde
+++ b/netchasketch.pde
@@ -7,7 +7,7 @@ void setup() {
size(300,300);
background(50,50,50);
stroke(0,0,0);
- fill(50,50,50,5);
+ fill(50,50,50);
x=width/2;
y=height/2;
shaking=false;
@@ -18,11 +18,27 @@ void draw() {
rect(0,0,width,height);
//println("SHAKEN");
}
+ if (mousePressed) {
+ int x1,y1,xo,yo;
+ dx=dy=0;
+ xo=mouseX-x;
+ yo=mouseY-y;
+ if (xo!=0) {
+ dx=xo/abs(xo);
+ if (yo/xo>2) dx=0;
+ }
+ if (yo!=0) {
+ dy=yo/abs(yo);
+ if (xo/yo>2) dy=0;
+ }
+ }
line(x,y,x+dx,y+dy);
x+=dx;
y+=dy;
- x=min(width,max(0,x));
- y=min(height,max(0,y));
+ x=x%width;
+ if (x<0) x+=width;
+ y=y%width;
+ if (y<0) y+=height;
}
void keyPressed() {
@@ -60,3 +76,6 @@ void keyReleased() {
break;
}
}
+void mouseReleased() {
+ dx=dy=0;
+}
diff --git a/test/netchasketch.pde b/test/netchasketch.pde
index 0a856c5..74089c0 100644
--- a/test/netchasketch.pde
+++ b/test/netchasketch.pde
@@ -7,7 +7,7 @@ void setup() {
size(300,300);
background(50,50,50);
stroke(0,0,0);
- fill(50,50,50,5);
+ fill(50,50,50);
x=width/2;
y=height/2;
shaking=false;
@@ -18,11 +18,27 @@ void draw() {
rect(0,0,width,height);
//println("SHAKEN");
}
+ if (mousePressed) {
+ int x1,y1,xo,yo;
+ dx=dy=0;
+ xo=mouseX-x;
+ yo=mouseY-y;
+ if (xo!=0) {
+ dx=xo/abs(xo);
+ if (yo/xo>2) dx=0;
+ }
+ if (yo!=0) {
+ dy=yo/abs(yo);
+ if (xo/yo>2) dy=0;
+ }
+ }
line(x,y,x+dx,y+dy);
x+=dx;
y+=dy;
- x=min(width,max(0,x));
- y=min(height,max(0,y));
+ x=x%width;
+ if (x<0) x+=width;
+ y=y%width;
+ if (y<0) y+=height;
}
void keyPressed() {
@@ -60,3 +76,6 @@ void keyReleased() {
break;
}
}
+void mouseReleased() {
+ dx=dy=0;
+}