Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package codopedia;
- import processing.core.*;
- import java.util.Calendar;
- import java.text.SimpleDateFormat;//getTimeInstance()
- public class MyPApplet extends PApplet{
- private String url = "http://i.imgur.com/ZZoY9Ni.jpg";
- private PImage backgroundImage;
- int hours, minutes, seconds = 0;
- public void setup(){
- size(200, 200);
- backgroundImage = loadImage(url, "jpg");
- }
- public void draw(){
- backgroundImage.resize(0, height);//height == height of the canvas and width == 0 means let java decide the width to keep the width and height ratio aspect
- image(backgroundImage, 0, 0);
- determineTime();
- /* //We can test if the Sun changes color using the seconds variable
- if(seconds >= 1 && seconds <= 20){
- fill(255, 209, 0);
- }else if(seconds > 20 && seconds <= 40){
- fill(209, 0, 0);
- }else{
- fill(0, 0, 255);
- }*/
- if(hours >= 9 && hours <= 16){
- fill(255, 209, 0);
- }else if(hours > 16 && hours <= 18){
- fill(209, 0, 0);
- }else{
- fill(0, 0, 255);
- }
- ellipse(width-width/6, height/5, width/5, height/5);
- }
- private void determineTime() {
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
- String hourMinuteSecond = sdf.format(cal.getTime());
- int colonBetweenMinutesAndSeconds = hourMinuteSecond.lastIndexOf(":");
- if(colonBetweenMinutesAndSeconds > 0){
- seconds = Integer.parseInt(hourMinuteSecond.substring(colonBetweenMinutesAndSeconds + 1));
- }
- int colonBetweenHoursAndMinutes = hourMinuteSecond.indexOf(":");
- if(colonBetweenHoursAndMinutes > 0){
- minutes = Integer.parseInt(hourMinuteSecond.substring(colonBetweenHoursAndMinutes + 1, colonBetweenMinutesAndSeconds));
- hours = Integer.parseInt(hourMinuteSecond.substring(0, colonBetweenHoursAndMinutes));
- }
- }//method determineTime ends here.
- }//class MyPApplet ends here.
Advertisement
Add Comment
Please, Sign In to add comment