The world's shortest clock code! Shorter, have the wood to have?

Source: Internet
Author: User

Label:

I. INTRODUCTION

processingjs author is John Resig, this is the second masterpiece following jquery.

processingJS provides a programming language and operating environment for teaching visualization. By writing the processing program, teachers can display the complex physical, chemical and mathematical principles of the image to the students. such as drawing a variety of graphs, wave lines, particles, drawing molecular structure, of course, in the physiological health class can also draw a group of small tadpoles in swimming and other dynamic graphics.

Processing.js is an open programming language that enables program images, animations, and interactive applications without the use of Flash or Java applets.
Processing.js uses JavaScript to draw shapes sharp and manipulate HTML5 canvas elements to produce image animations.
Processing.js is lightweight, easy to understand mastered, and presents an ideal tool for visualizing data, creating user interfaces and developing Web-based games.

Two. Core functions
1234567891011121314151617181920212223242526272829303132333435 // Global variables 全局变量int radius = 50.0;int X, Y;int nX, nY;int delay = 16;// Setup the Processing Canvas初始化设置void setup(){size( 200, 200 );strokeWeight( 10 );frameRate( 15 );X = width / 2;Y = width / 2;nX = X;nY = Y;}// Main draw loop 主要绘画函数功能void draw(){radius = radius + sin( frameCount / 4 );// Track circle to new destinationX+=(nX-X)/delay;Y+=(nY-Y)/delay;// Fill canvas greybackground( 100 );// Set fill-color to bluefill( 0, 121, 184 );// Set stroke-color whitestroke(255);// Draw circleellipse( X, Y, radius, radius );}// Set circle‘s next destination 当用户鼠标在 Canvas移动时产生的actionvoid mouseMoved(){nX = mouseX;nY = mouseY;}
Three. World's shortest clock code birth
123456 void draw() {size(200, 200);background(0); fill(80); noStroke(); ellipse(100, 100, 160, 160); stroke(255);line(100, 100, cos( TWO_PI*second()/60- HALF_PI) * 70 + 100, sin(TWO_PI*second()/60- HALF_PI) * 70 + 100);line(100, 100, cos( TWO_PI*minute()/60- HALF_PI) * 60 + 100, sin(TWO_PI*minute()/60- HALF_PI) * 60 + 100);line(100, 100, cos(TWO_PI*(hour()%12)/12- HALF_PI) * 50 + 100, sin(TWO_PI*(hour()%12)/12- HALF_PI) * 50 + 100);}

It can be seen that code semantics is very strong, a circle, three lines, which is the framework to achieve one of the purposes.

Four. Complete code
12345678910111213141516 <!DOCTYPEhtml><html><head><body><scriptsrc="http://files.cnblogs.com/iamzhanglei/processing.js" type="text/javascript"></script><scripttype="application/processing">void draw() {size(200, 200);background(0); fill(80); noStroke(); ellipse(100, 100, 160, 160); stroke(255);line(100, 100, cos( TWO_PI*second()/60- HALF_PI) * 70 + 100, sin(TWO_PI*second()/60- HALF_PI) * 70 + 100);line(100, 100, cos( TWO_PI*minute()/60- HALF_PI) * 60 + 100, sin(TWO_PI*minute()/60- HALF_PI) * 60 + 100);line(100, 100, cos(TWO_PI*(hour()%12)/12- HALF_PI) * 50 + 100, sin(TWO_PI*(hour()%12)/12- HALF_PI) * 50 + 100);}</script><canvas>你的浏览器不支持HTML5,请使用谷歌、IE9或者火狐浏览器··</canvas></body></html>
Five. Online Demo

The world's shortest clock code! Shorter, have the wood to have?

Related Article

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.

Tags Index: