Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package guimodule;
- import processing.core.PApplet;
- import processing.core.PImage;
- public class MyPApplet2 extends PApplet{
- private String url = "http://i.imgur.com/ZZoY9Ni.jpg";
- private PImage backgroundPic;
- public void setup(){
- size(400, 400);//(w,h)
- background(255);//set canvas color R=255, G=255, B= 255
- stroke(0);//set pen color R=0; G=0; B=0
- backgroundPic = loadImage(url);
- backgroundPic.resize(0, height);//resizing the pic to the full height of canvas
- image(backgroundPic, 0, 0);//x = 0; y = 0;
- }
- public void draw(){
- int[] color = sunColorSec(second());//Det finns hour() och minute() metoder också.
- fill(color[0], color[1], color[2]);//passing R, G and B
- ellipse(width-width/6, height/6, width/4, height/5);
- }
- private int[] sunColorSec(int s) {
- int[] rgb = new int[3];//We want to return R, G and B colors
- //Scale the brightness of the yellow color of the Sun based on seconds.
- //0 seconds is black. 30 seconds is bright yellow
- float diffFrom30 = Math.abs(30 - s);
- float ratio = diffFrom30/30;//gives a number between 0 and 1
- rgb[0] = (int)(255 * ratio);
- rgb[1] = (int) (255 * ratio);
- rgb[2] = 0; //The blue color is not needed to make different shades of yellow.
- //System.out.println("R: " + rgb[0] + " G: " + rgb[1] + " B: " + rgb[2]);
- return rgb;
- }
- }//class MyApplet2 ends here.
Advertisement
Add Comment
Please, Sign In to add comment