SpriteFun Android Entertainer
in
Share your Work
•
4 months ago
Here is a fun little sprite entertainer, a sort of not-a-game where your finger motion launches a sprite travelling across the screen, creating interesting patterns. The sprite comes from an example on the tutorials, i believe the transformations tutorial but not sure. I am just learning how to write Android apps and thought I'd share this one. I'd publish it as a free app if I knew how (can't wait for that to get automated). Enjoy!
- // spriteFun
- // by Les Hall 6-14-2013
- int nextX, nextY, prevX, prevY;
- int velocityX, velocityY, stepX, stepY;
- int red, green, blue;
- color bg, fg;
- void setup() {
- bg = color(63, 31, 127);
- background(bg);
- randomSeed(0);
- noStroke();
- fg = color(255-red(bg), 255-green(bg), 255-blue(bg));
- fill(red(fg), green(fg), blue(fg));
- textAlign(CENTER, CENTER);
- textSize(128);
- text("SpriteFun", width/2, height/4);
- textSize(96);
- text("by Les Hall", width/2, height/2);
- textSize(64);
- text("Touch and drag to make sprite patterns", 0, 3*height/4, width, height/4);
- }
- void draw(){
- // draw sprite rectangle
- prevX = nextX;
- prevY = nextY;
- nextX = mouseX;
- nextY = mouseY;
- if (prevX == nextX) {
- stepX += velocityX;
- } else {
- velocityX = nextX - prevX;
- stepX = nextX;
- }
- if (prevY == nextY) {
- stepY += velocityY;
- } else {
- velocityY = nextY - prevY;
- stepY = nextY;
- }
- if (stepX > width) stepX = 0;
- if (stepX < 0) stepX = width;
- if (stepY > height) stepY = 0;
- if (stepY < 0) stepY = height;
- color c = getColor();
- sprite(stepX, stepY, c);
- }
- color getColor() {
- red = (red + 1) % 256;
- green = (green + 3) % 256;
- blue = (blue + 5) % 256;
- color c = color(red, green, blue);
- return c;
- }
- void sprite(int x, int y, color c) {
- fill(red(c), green(c), blue(c));
- pushMatrix();
- translate(x, y);
- rotate(radians(frameCount * 31 % 360));
- rect(0, 0, 80, 20);
- popMatrix();
- }