Advertisement
bethdps

Relógio

Jan 25th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. int raio;
  2. int currentSeconds = 0;
  3.  
  4. class Ponto{
  5.   int x;
  6.   int y;
  7.  
  8.   Ponto(int x, int y){
  9.     this.x = x;
  10.     this.y = y;
  11.   }
  12. }
  13.  
  14. void setup(){
  15.   size(500,500);
  16.   raio = (width-100)/2 - 20;
  17.  
  18. }
  19.  
  20. void draw(){
  21.   background(125);
  22.   drawClock();
  23.   movePointer();
  24. }
  25.  
  26. Ponto polares(float angulo, int raio){
  27.   return new Ponto(
  28.             round(cos(angulo) * raio),
  29.             round(sin(angulo) * raio)
  30.          );
  31. }
  32.  
  33. void drawClock(){
  34.   strokeWeight(5);
  35.   stroke(0);
  36.   ellipse(width/2,height/2,width-100,width-100);
  37.  
  38. }
  39.  
  40. void movePointer(){
  41.   if(millis()/1000.0 > currentSeconds+1){
  42.     currentSeconds++;
  43.   }
  44.    
  45.   Ponto p = polares((2*PI/60.0)*currentSeconds - PI/2,raio);
  46.  
  47.   strokeWeight(6);
  48.   stroke(255,0,0);
  49.   line(width/2,height/2, width/2 + p.x, height/2 + p.y);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement