The shortest clock code in the world! Shorter, with wood?

Source: Internet
Author: User
I. Introduction

Processing. JS is written by John resig. This is his second masterpiece after jquery.

Processing. js provides a visual programming language and runtime environment for teaching. By writing a processing program, instructors can present the complex physical, chemical, and mathematical principles to students. For example, you can draw various curves, wave lines, particles, and molecular structures. Of course, you can also draw a group of dynamic figures like swimming in the physiological and health class.

Processing. JS is an open programming language that can be used to implement program images, animations, and interactions without using flash or Java applets.
Processing. js uses JavaScript to draw sharp shapes and operate HTML5 Canvas elements to generate image animations.
Processing. JS is lightweight, easy to understand, and provides an ideal tool to visualize data, create user interfaces, and develop web-based games.

 

 

2. Core Function view sourceprint?
01 // Global variables global variable
02 int radius = 50.0;
03 int X, Y;
04 int nX, nY;
05 int delay = 16;
06   
07 // Setup the processing canvas initialization settings
08 void setup(){
09   size( 200, 200 );
10   strokeWeight( 10 );
11   frameRate( 15 );
12   X = width / 2;
13   Y = width / 2;
14   nX = X;
15   nY = Y;  
16 }
17   
18 // Main draw loop main painting function
19 void draw(){
20     
21   radius = radius + sin( frameCount / 4 );
22     
23   // Track circle to new destination
24   X+=(nX-X)/delay;
25   Y+=(nY-Y)/delay;
26     
27   // Fill canvas grey
28   background( 100 );
29     
30   // Set fill-color to blue
31   fill( 0, 121, 184 );
32     
33   // Set stroke-color white
34   stroke(255); 
35     
36   // Draw circle
37   ellipse( X, Y, radius, radius );                  
38 }
39   
40   
41 // Set Circle's next destination action generated when the user moves the mouse over the canvas
42 void mouseMoved(){
43   nX = mouseX;
44   nY = mouseY;  
45 }

 

 

3. the world's shortest clock code was born view sourceprint?
1 void draw() {
2   size(200, 200);background(0); fill(80); noStroke(); ellipse(100, 100, 160, 160); stroke(255);
3   line(100, 100, cos( TWO_PI*second()/60- HALF_PI) * 70 + 100, sin(TWO_PI*second()/60- HALF_PI) * 70 + 100);
4   line(100, 100, cos( TWO_PI*minute()/60- HALF_PI) * 60 + 100, sin(TWO_PI*minute()/60- HALF_PI) * 60 + 100);
5   line(100, 100, cos(TWO_PI*(hour()%12)/12- HALF_PI) * 50 + 100, sin(TWO_PI*(hour()%12)/12- HALF_PI) * 50 + 100);
6 }

It can be seen that the Code semantics is very strong, with a circle and three lines. This is also one of the purposes of this framework.

 

 

4. Complete Code view sourceprint?
01 <!DOCTYPE html>
02 <html>
03 <head>
04     <body>
05      <script src="http://files.cnblogs.com/iamzhanglei/processing.js" type="text/javascript"></script>
06         <script type="application/processing">
07 void draw() {
08   size(200, 200);background(0); fill(80); noStroke(); ellipse(100, 100, 160, 160); stroke(255);
09   line(100, 100, cos( TWO_PI*second()/60- HALF_PI) * 70 + 100, sin(TWO_PI*second()/60- HALF_PI) * 70 + 100);
10   line(100, 100, cos( TWO_PI*minute()/60- HALF_PI) * 60 + 100, sin(TWO_PI*minute()/60- HALF_PI) * 60 + 100);
11   line(100, 100, cos(TWO_PI*(hour()%12)/12- HALF_PI) * 50 + 100, sin(TWO_PI*(hour()%12)/12- HALF_PI) * 50 + 100);
12 }
13         </script>
14         <canvas> Your browser does not support HTML5. Please use Google, ie9, or Firefox. </canvas>
15     </body>
16 </html>

 

 

 

5. Online demonstration

Your browser does not support HTML5. Please use Google, ie9 or Firefox ··

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.