In this article, we will share with you how to use limited code to draw an octal diagram, which is an assessment of your understanding of javascript. We recommend it to you here for your reference. 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.