Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science I Adding a timing feature. Classwork/Homework: finish final project. Prepare for review for final. Post on programming topic.

Similar presentations


Presentation on theme: "Computer Science I Adding a timing feature. Classwork/Homework: finish final project. Prepare for review for final. Post on programming topic."— Presentation transcript:

1 Computer Science I Adding a timing feature. Classwork/Homework: finish final project. Prepare for review for final. Post on programming topic.

2 Objective Add to rotating cube of photos sketch the feature that cube rotates by itself if user does nothing. How to detect nothing happening????

3 How to detect the absence of an event? Answer in this case – keep track of time since last mouseDragged invocation. Use millis() and two global variables. int last; int interval = 6000; //time to wait Initialize last in setup function last = millis(); //time since program started Set (reset) last in mouseDragged – This will happen again and again while mouse is dragged. Check in draw

4 void mouseDragged() { float rate = 0.01; last = millis(); rotx += (pmouseY-mouseY) * rate; roty += (mouseX-pmouseX) * rate; }

5 void draw() { background(0); textSize(20); text("Drag using mouse anywhere on screen to rotate cube. If no action, cube will rotate by itself.",17,14); noStroke(); translate(width/2.0, height/2.0, -100); if ((millis()-last) > interval) { setRotation(); } rotateX(rotx); rotateY(roty); scale(200); TexturedCube(frog,flowers,makeup); }

6 Made a distinct function void setRotation() { rotx += PI/400; roty += PI/400; } Experimented with PI/400 to get speed what seemed appropriate.

7 How to allow viewer to add file(s) This is considered a security risk. – May not be able to do it in ProcessingJS Add code – Use an array, originally with 3 images – Program keyPressed Which calls selectInput, which sets up a callback: names a function to be called when user either selects a file or hits cancel

8 void keyPressed () { selectInput("Select an image file, or hit cancel.","fileSelected"); } void fileSelected(File selection) { PImage img; if (selection == null) { println("Window was closed or the user hit cancel."); } else { img = loadImage(selection.getAbsolutePath()); picfiles = (PImage[]) append(picfiles,img); selectInput("Select an image file, or hit cancel.","fileSelected"); }

9 Classwork/homework Work on final project: due 5/2. Prepare for final quiz 5/9. – Look at guide to final. Ask questions now or next class. One last posting: Think about Processing and doing Processing. Compare with using other computer tools. Compare with other programming languages, if you are familiar with other languages. Post to the appropriate forum.


Download ppt "Computer Science I Adding a timing feature. Classwork/Homework: finish final project. Prepare for review for final. Post on programming topic."

Similar presentations


Ads by Google