Draw an octal diagram with 12 lines of javascript code and 12 lines of javascript

Source: Internet
Author: User

Draw an octal diagram with 12 lines of javascript code and 12 lines of javascript

One statement: Build a 1024*1024 color matrix with limited code to show you the beauty of programming and art.

It originated from a problem on stackexchange. Here we made a slight extension to support more programming languages and relaxed the code length restrictions.
Rules

Objectives:
Implement a function get_color_at (x, y) in the template and draw as interesting as possible on a canvas of 1024*1024.

Parameters:
Int x, int y, all values are 0-1023, corresponding to the coordinate point on the canvas, the upper left corner is the starting point (0, 0)

Return Value:
Int r, int g, int B, int alpha, The RGBA component of the corresponding color, all 0-255.

Note:
The definition of alpha components in different languages may be different. The template is converted to 0-255 in a unified manner, and the larger the value, the more transparent.

Requirements:
You can only edit the code in the body of the get_color_at (x, y) function in the template // {code start }}- // {code end;
The total number of characters in the Code cannot exceed 1024, and the code is readable.

if(typeof f_c=="undefined"){  f_c=function(x,y,px,py,r){    return Math.sqrt(Math.pow(x-px,2)+Math.pow(y-py,2))<=r;  };}var x0=x-512,y0=y-512;r=g=b=128;if(f_c(x0,y0,0,0,512)) r=g=b=(x0>0)?255:0;if(f_c(x0,y0,0,256,256)&&x0<=0) r=g=b=255;if(f_c(x0,y0,0,-256,256)&&x0>0) r=g=b=0;if(f_c(x0,y0,0,256,64)) r=g=b=0;if(f_c(x0,y0,0,-256,64)) r=g=b=255;

The above is all the content of this article. I hope you will like it.

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.

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.