Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Creative Coding
- * Week 2 Off piste
- * by Karen Cropper
- * Licenced C-BY 4.0 https://creativecommons.org/licenses/by/4.0/
- * This program demonstrates coding with color.
- * Press 's' to save your drawing as an image to the file "color.jpg"
- * Press 'r' to erase your drawing and start with a blank screen
- *
- */
- // Setting up some variables to use further down
- int colorBack; //for background color initially and to clear
- float xVar; // to scale the colour in x
- float yVar; // to scale the colour in y
- // setup function -- called once when the program begins
- void setup() {
- // set the display window size
- size(1200, 675); // width and height relate to these two values
- // set the background colour to white
- colorBack = 255; // initialising background color also used in reset
- background(colorBack);
- }
- // draw function
- void draw() {
- if (mousePressed) {
- // strokeWeight(random(2)); // random thickness of line
- stroke(0); // set the stroke colour black
- xVar = mouseX*255/width;
- yVar = mouseY*255/height;
- // had this in to check what was being output by the variable calculation
- // print("x = "+xVar+", y = "+yVar+" : ");
- // This is varying the red and the green by position X and Y but with
- // blue fixed at a value. Some degree of transparency is nicer
- fill(xVar, yVar, 0, 150); // set the fill colour with transparency
- // draw a rectangle with a size variation in size
- rect(mouseX, mouseY, random(10,50), random(10,50));
- }
- // save your drawing when you press keyboard 's'
- if (keyPressed == true && key=='s') {
- saveFrame("color.jpg");
- }
- // erase your drawing when you press keyboard 'r'
- if (keyPressed == true && key == 'r') {
- background(colorBack);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment