This sketch will teach you how to design a wheel that reacts due to the mouse movements and an image that is saved due to a function you write.
Start using a void setup() to preface size and background color. Then using draw create conditions for Processing to draw on the screen.
void setup() {
size(600,600);
background(255);
}
In the code for if(mousePressed) the line starting position is defined as half the width and half the height of the sketch window and extends to the current mouseX and mouseY positions.
void draw() {
stroke(0,50);
if(mousePressed) {
line(width/2, height/2, mouseX, mouseY);
}
}
Using the void keyPressed(){} allows the keyboard to interact with the sketch. You can also print information to the console window below the code for the user to see while the sketch is running using the println(); command. This helps to make specific keys do specific actions in your code.
void keyPressed() {
println("Key was pressed!" + key);
if (key == 's') {
saveFrame("images/myImage-######.jpg");
println("Image was saved! Hazzah!");
}
}
//the hash marks are the frame numbers of the sketch project and are used so you do not overwrite the file on each save. The single ' is for a character in your code, whereas the double " is for a string of characters like a word in your code.
//the use of couched {} brackets make multiple liens of code behave as a single line.