Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-05-2007, 04:28 PM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
(Not GScript) A simple clock

I made this out of pure free time. It's Java so it won't work on Graal -- Sorry guys. You might be able to get some good ideas / good formulas off of this however.

Alert: This is an applet. You can use it on a webpage by compiling it and using this code:
HTML Code:
<APPLET CODE=Clock.class WIDTH=100 HEIGHT=100>
</APPLET>

PHP Code:
public class Clock extends javax.swing.JApplet
{
    public 
int clockX;
    public 
int clockY;
    public 
int clockW;
    public 
int clockR;
    public 
double sa;
    public 
double sda;
    public 
double mda;
    public 
double hda;
    public 
int sr;
    public 
int mr;
    public 
int hr;
    public 
int s;
    public 
int m;
    public 
int h;
    public 
int secondX;
    public 
int secondY;
    public 
int minuteX;
    public 
int minuteY;
    public 
int hourX;
    public 
int hourY;
    
    public 
void init()
    {
        
// Start the timer; Variables here don't matter
        // since they're in the Paint method.
        
        
javax.swing.Timer clock = new javax.swing.Timer(500updateClock);
        
clock.start();
    }
    
    public 
void paint(java.awt.Graphics g)
    {
        
clockX = (getWidth()/2);
        
clockY = (getHeight()/2);
        
        
clockW = (getWidth()-1);
        
clockR = ((getWidth()-1) / 2);
        
        
sa = (Math.PI 2);
        
sda = (Math.PI 30);
        
mda = (Math.PI 30);
        
hda = (Math.PI 6);
        
        
sr clockR;
        
mr = (int) (0.9 clockR);
        
hr = (int) (0.7 clockR);
        
        
g.fillRect(00getWidth(), getHeight());
        
g.setColor(new java.awt.Color(255255255));
        
        
java.util.Date d = new java.util.Date();
        
        
d.getSeconds();
        
d.getMinutes();
        
d.getHours();
        
        
secondX = (int) ((getWidth() / 2) + Math.cos((sda) - sa) * sr);
        
secondY = (int) ((getWidth() / 2) + Math.sin((sda) - sa) * sr);
        
        
minuteX = (int) ((getWidth() / 2) + Math.cos((mda) - sa) * mr);
        
minuteY = (int) ((getWidth() / 2) + Math.sin((mda) - sa) * mr);
        
        
hourX = (int) ((getWidth() / 2) + Math.cos((hda) - sa) * hr);
        
hourY = (int) ((getWidth() / 2) + Math.sin((hda) - sa) * hr);
        
        
g.drawLine( (getWidth() / 2), (getHeight() / 2), secondXsecondY );
        
g.drawLine( (getWidth() / 2), (getHeight() / 2), minuteXminuteY );
        
g.drawLine( (getWidth() / 2), (getHeight() / 2), hourXhourY );
        
        
g.drawOval(00, (getWidth()-1), getHeight()-1);
        
        
String stime = (12 ":" + (10 "0" m) + ":" + (10 "0" s) + " " + (11 "PM" "AM"));
        
showStatus("The time is now: " stime ".");
    }
    
    
java.awt.event.ActionListener updateClock = new java.awt.event.ActionListener()
    {
        public 
void actionPerformed(java.awt.event.ActionEvent evt)
        {
            
repaint();
        }
    };

Just in case nobody has compilers, Forum PM me and i'll give you the class file.

Enjoy.



Note: I KNOW THIS ISN'T A JAVA FORUM.
I just thought it would help someone >_>
__________________
What signature? I see no signature?

Last edited by godofwarares; 03-05-2007 at 04:29 PM.. Reason: Saw an array I had to get rid of.
Reply With Quote
  #2  
Old 03-05-2007, 04:32 PM
Zeta0 Zeta0 is offline
Registered User
Join Date: Jan 2007
Posts: 9
Zeta0 is on a distinguished road
gk hik repped
Reply With Quote
  #3  
Old 03-05-2007, 05:58 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
I'll let the thread stay since the formulae might help some people, but ideally you shouldn't post code in different languages here.
__________________
Skyld
Reply With Quote
  #4  
Old 03-05-2007, 07:09 PM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
Alright
__________________
What signature? I see no signature?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.