Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
danbwilder
danbwilder's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Rotating an image on Keyboard Input.
[3 Replies]
25-Sep-2013 02:57 AM
Forum:
Programming Questions
Hello, I am absolutely brand new to Processing. Brand new.
I am just playing around and Im wondering if someone can help me get the code correct so that my image rotates on key input.
/**
* Easing.
*
* Move the mouse across the screen and the symbol will follow.
* Between drawing each frame of the animation, the program
* calculates the difference between the position of the
* symbol and the cursor. If the distance is larger than
* 1 pixel, the symbol moves part of the distance (0.05) from its
* current position toward the cursor.
*/
int angle;
int rectWidth;
PImage marioj;
PImage mario;
PImage img;
PImage bg;
PImage goomba;
PImage luigi;
PImage luigij;
float x;
float y;
float x1 = -20;
float easing = 0.05;
void setup() {
size(1000, 938);
noStroke();
imageMode(CENTER);
bg = loadImage("bg.png");
mario = loadImage("mario.png");
marioj = loadImage("mariojump.png");
img = loadImage("nothing.png");
goomba = loadImage("goomba.png");
angle = 0;
}
void draw() {
background(bg);
rotate(radians(angle));
image(goomba, x1+= 1,790);
if (mousePressed) {
image(marioj,mouseX,mouseY);
} else {
image(mario, mouseX,mouseY);
}
float targetX = mouseX;
float dx = targetX - x;
if(abs(dx) > 1) {
x += dx * easing;
}
float targetY = mouseY;
float dy = targetY - y;
if(abs(dy) > 1) {
y += dy * easing;
}
//ellipse(x, y, 66, 66);
imageMode(CENTER);
image(img, x, y);
}
void keyPressed() {
// int keyIndex = -1;
// if (key >= 'A' && key <= 'Z') {
// keyIndex = key - 'A';
// } else if (key >= 'a' && key <= 'z') {
// keyIndex = key - 'a';
// }
// if (keyIndex == -1) {
// // If it's not a letter key, clear the screen
// background(0);
// } else {
// // It's a letter key, fill a rectangle
// fill(millis() % 255);
// float x = map(keyIndex, 0, 25, 0, width - rectWidth);
// rect(x, 0, rectWidth, height);
// }
//my try============
if(keyCode == 37){ //arrows are coded so you can't call "key"
rotate(mouseX*PI); //left arrow rotates one way
} else if(keyCode == 39){
rotate(mouseY/PI); //right arrow rotates the other way
}
}
«Prev
Next »
Moderate user : danbwilder
Forum