Having issues with the key function
in
Programming Questions
•
7 months ago
I started working on a project. It was inspired by someone else's work. I used part of the code and planned on integrating more to it and change it around. The code so far looks like this:
PImage image;
//////////////////////////
void setup ()
{
size (900, 650);
smooth();
image = loadImage("view.png");
noStroke();
}
//////////////////////////
void draw () {
background(image);
noCursor();
noStroke();
background(0, 0, 0);
for ( int x =0; x <= width; x+=9) {
for (int y=0; y <= height; y+=9) {
float diameter = 130-dist(mouseX, mouseY, x, y);
if (diameter > 0) {
fill(image.pixels[(x + image.width*y)]);
ellipse(x, y, diameter/7, diameter/7);
}
}
}
}
//////////////////////////
void keyPressed () {
if (key == UP){
}
if (key == DOWN){
}
You get an image with a floating circle that you can move around with your mouse. When you hover around
can see an image behind it. I want to change the size and shape of the circle by manipulating certain
values using the arrow keys. Here's an example:
for ( int x =0; x <= width; x+=9) {
for (int y=0; y <= height; y+=9)
if I change the 9 value to a 3 or to 6, the circle becomes more or less pixelated. Is there a
way that I can use the arrow keys to change that?
This is what I tried.
int aa = 3;
for ( int x =0; x <= width; x+=aa) {
for (int y=0; y <= height; y+=aa)
if (key == UP){
aa++;}
else {
aa = aa;
}
hoping this all makes sense...or that It is possible for me to be able to make the idea work.
1