I am working on a project where I use a keylogger to collect button input, let Processing read it and let it do certain actions when it goes over the specific letter. I need to make the program somewhat random, and I am tryin to get that effect if it comes to the directions of the drawing.
Posted someting about it before here and even got a comment to implement some sort of Shuffle-process, but it is yet something I have to investigate (mainly due lack of knowledge and a time crunch)
Anyway. Currently my code has somewhat specific values. The speed is slightly random, and so is the position. The issue is: The line always moves to the lower-right corner, and restarting the program (resetting its position on a random place from 0 to width and 0 to height) always results in a somewhat same-ish pattern. I want to try to break free from it.
TekenLine drawing;
String[] buttonLog;
char[] letters;
int charIndex;
//boolean isA = false;
void setup() {
size(600, 800);
background(255);
buttonLog = loadStrings("buttonLog.txt");
letters = buttonLog[0].toCharArray();
drawing = new TekenLine(int(random(0, width)), int(random(0, height)), int(random(1,3)),int(random(1,3)));
}
void draw() {
switch(letters[charIndex]) {
case 'a':
fill(#CC00CC);
//isA = true;
break;
case 'w':
fill(#404040);
//isA = false;
break;
case 's':
fill(#0000CC);
//isA = false;
break;
case 'd':
fill(#00CCCC);
//isA = false;
break;
}
charIndex = (charIndex + 1) % letters.length;
drawing.drawLine();
drawing.moveLine();
drawing.bounceLine();
}
Class :
class TekenLine {
float x;
float y;
float lineWidth;
float lineHeight;
float xSnelheid;
float ySnelheid;
TekenLine(int tempX, int tempY, int tempXSnelheid, int tempYSnelheid) {
//x = width / 2;
//y = height / 2;
x = tempX;
y = tempY;
xSnelheid = tempXSnelheid;
ySnelheid = tempYSnelheid;
lineWidth = 10;
lineHeight = 10;
//xSnelheid = 5;
//ySnelheid = 5;
}
void drawLine() {
noStroke();
rect(x, y, lineWidth, lineHeight, 20);
}
void moveLine() {
x += xSnelheid;
y += ySnelheid;
}
void bounceLine() {
//if(isA){
// xSnelheid = -xSnelheid;
//}
if (x >= width || x <= 0) {
xSnelheid = -xSnelheid;
//lineWidth = (random(10, 20));
}
if (y >= height || y <= 0) {
ySnelheid = -ySnelheid;
ySnelheid = ySnelheid*random(0.8,1.2);
//lineHeight = (random(10, 30));
}
}
}
Currently, as mentioned before, my code goes into the same direction, but each from a different height and width each restart, bouncing from the walls and changing colors assigned to āW. A. S. Dā from the buttonlog.text log.
I have a certain ideas, but do not know how to start or implement it. The ideas are:
- if letter = A (for instance), then slightly turn to the left/right
- if letter = W, then move to random direction.
Probably not the best examples that I can think of, but it is something that I need to make the movement of my drawing-line a bit more randomized so that each new re-start can be a little bit more unique.
Any ideas are welcome!