//Jeremy Turner (JOT) Assignment 4 = #200024742 //I have added 2 slider widgets from the ControlP5 library... //One adjusts the strokeWeight and the other... //Special thanks to Johnny Rodgers for preparing a demo/tutorial... //..on this subject... import controlP5.*; //entire library imported. //initialize controls ControlP5 controller; Slider exampleSlider, anotherSlider; controlP5.Button testButton; //This is the ControlP5's reset button for setting values back to 0. MultiList mode; //sets up the drop-down menu. //initialize variables...They are public to make them appear online. public int exampleSliderVal = 10; int exampleSliderDefaultVal = 0; public float anotherSliderVal = 10; float anotherSliderDefaultVal = 0; PFont font; PImage b; //this global variable indicates there will be an image downloaded //to the Assignment's folder called "b"...I will use this for the picture of Moses. PImage c; //Here I am calling up each tablet in the global variable section //to make sure they exist and are drawn. MyTablet t1; MyTablet t2; MyTablet t3; MyTablet t4; MyTablet t5; MyTablet t6; MyTablet t7; MyTablet t8; int preview_stroke_weight=0; int carving_stroke_weight=0; void setup () { size (400, 666); background(255); t1 = new MyTablet (10, 425); t2 = new MyTablet (100, 425); t3 = new MyTablet (200, 425); t4 = new MyTablet (300, 425); t5 = new MyTablet (10, 550); t6 = new MyTablet (100, 550); t7 = new MyTablet (200, 550); t8 = new MyTablet (300, 550); b = loadImage("moses460.jpg"); //the image assigned to the variable "b" is being told to upload within setup instead of a background. image(b,0,0); font = loadFont ("JuiceITC-Regular-28.vlw"); font = loadFont ("JuiceITC-Regular-36.vlw"); //this uploads the chosen font. font = loadFont ("JuiceITC-Regular-48.vlw"); //instantiate control object controller = new ControlP5(this); //set parameters for all control objects controller.setColorLabel(0); //add controls to canvas with labels (default label will be name of variable) exampleSlider = controller.addSlider("exampleSliderVal", 0, 10.0, exampleSliderDefaultVal, 320, 75, 60, 200); exampleSlider.setLabel("Carving Stroke"); anotherSlider = controller.addSlider("anotherSliderVal", 0, 10.0, anotherSliderDefaultVal, 83, 75, 60, 200); anotherSlider.setLabel("Preview Stroke"); testButton = controller.addButton("reset", 0, 205, 256, 66, 20); mode = controller.addMultiList("myList", 198, 225, 85, 15); MultiListButton a; a= mode.add("Quick Stroke Size", 0); a.add("Tiny Stroke", 1); a.add("Medium Stroke", 2); a.add("Large Stroke", 3); } void draw () { background(255); changeCursor(); createText(); makeTablets(); // strokeWeight(stroke_weight); image(b, 0, 0); } // prints out current value of exampleSliderVal variable void exampleSliderVal() { println("sliderVal set to " + exampleSlider.value()); exampleSliderVal = int(exampleSlider.value()); carving_stroke_weight=exampleSliderVal; } void controlEvent(ControlEvent theEvent) { int menValue=int(theEvent.value()); switch (menValue){ case 1: preview_stroke_weight=1; anotherSlider.setValue(preview_stroke_weight); break; case 2: preview_stroke_weight=5; anotherSlider.setValue(preview_stroke_weight); break; case 3: preview_stroke_weight=10; anotherSlider.setValue(preview_stroke_weight); break; default: } } //reset sets sliders to their original values void reset(float theValue) { println("reset called"); preview_stroke_weight=int(anotherSliderDefaultVal); carving_stroke_weight=int(exampleSliderDefaultVal); exampleSlider.setValue(carving_stroke_weight); anotherSlider.setValue(preview_stroke_weight); } void mousePressed(){ if((t1.IsMouseOnTablet())||(t2.IsMouseOnTablet())||(t3.IsMouseOnTablet())||(t4.IsMouseOnTablet())||(t5.IsMouseOnTablet())||(t6.IsMouseOnTablet())||(t7.IsMouseOnTablet())||(t8.IsMouseOnTablet())) { stroke(0); strokeWeight(carving_stroke_weight);//have assigned the strokeWeight //to carving stroke size bar. line(mouseX, mouseY, pmouseX, pmouseY); } } void mouseMoved() { if((t1.IsMouseOnTablet())||(t2.IsMouseOnTablet())||(t3.IsMouseOnTablet())||(t4.IsMouseOnTablet())||(t5.IsMouseOnTablet())||(t6.IsMouseOnTablet())||(t7.IsMouseOnTablet())||(t8.IsMouseOnTablet())) { stroke (255); strokeWeight(preview_stroke_weight); //have assigned the strokeWeight //to the preview stroke slider bar. line (pmouseX, pmouseY, mouseX, mouseY); smooth(); } } void mouseDragged() { if((t1.IsMouseOnTablet())||(t2.IsMouseOnTablet())||(t3.IsMouseOnTablet())||(t4.IsMouseOnTablet())||(t5.IsMouseOnTablet())||(t6.IsMouseOnTablet())||(t7.IsMouseOnTablet())||(t8.IsMouseOnTablet())) { stroke(0); strokeWeight(carving_stroke_weight);//have assigned the strokeWeight line (mouseX, mouseY, pmouseX, pmouseY); } } void createText(){ textFont(font, 48); text("WRITTEN IN STONE...", 80,330); fill(0); textFont(font, 28); text("Preview Sketch = float mouse over a tablet", 30, 375); // text("Erase Preview = press left mouse button", 30, 385); text("Etch onto stone = drag mouse over a tablet", 30, 405); fill(255, 0, 0); } void makeTablets(){ t1.maketablet(); t2.maketablet(); t3.maketablet(); t4.maketablet(); t5.maketablet(); t6.maketablet(); t7.maketablet(); t8.maketablet(); } void changeCursor () { if((t1.IsMouseOnTablet())||(t2.IsMouseOnTablet())||(t3.IsMouseOnTablet())||(t4.IsMouseOnTablet())||(t5.IsMouseOnTablet())||(t6.IsMouseOnTablet())||(t7.IsMouseOnTablet())||(t8.IsMouseOnTablet())) { cursor(CROSS); } else { cursor(ARROW); } } class MyTablet { //the class of tablets has now been created... float xPos; float yPos; PImage c; // I have assigned this global variable for the picture of the stone tablet. int tabletWidth; int tabletHeight; MyTablet (float x, float y) { xPos = x; yPos = y; //Pooya: I added this line in constructor to make it run only once loadtablet(); } boolean IsMouseOnTablet(){ if (mouseX>xPos && mouseXyPos && mouseY