Answers:
8tE2$r&S1=3YG
示例(在MATLAB上运行MATL编译器):
或在MATL Online上尝试!(如果它不是第一次运行,请再次按“运行”或刷新页面)。请注意,图像由在线解释器缩放以实现更好的可视化。
这是我的Octave / MATLAB答案的端口(请参阅此处的说明)。以下是等效的语句:
MATL Octave / MATLAB
---- ---------------
8tE 8,16
2$r rand(...)
&S [~,out]=sort(...)
1= ...==1
3YG imshow(...)
[~,z]=sort(rand(8,16));imshow(z==1)
示例(在八度音阶上):
rand(8,16) % 8×16 matrix of random values with uniform
% distribution in (0,1)
[~,z]=sort( ); % Sort each column, and for each output the
% indices of the sorting. This gives an 8×16
% matrix where each column contains a random
% permutation of the values 1,2,...,8
z==1 % Test equality with 1. This makes all values
% except 1 equal to 0
imshow( ) % Show image, with grey colormap
main(c){char a[138]="P5 16 8 1 ";for(srand(time(0)),c=17;--c;a[9+c+(rand()&112)]=1);write(1,a,138);}
将PGM图像文件写入stdout(使用调用prog >out.pgm
)。
脱节并解释:
main(c) {
// A buffer large enough to contain the whole image,
// pre-filled with the PGM header.
// This is a binary greyscale (P5) image with only two levels (1),
// Because a binary bitmap would require pixel packing.
char a[138] = "P5 16 8 1 ";
// c iterates from 16 to 1 over the columns
for(
srand(time(0)), c = 17;
--c;
// (rand() % 8) * 16 is equivalent to (rand() & 7) << 4
// Since all bits are equally random, this is equivalent
// to rand() & (7 << 4), that is rand() & 112.
// This picks a pixel from the first column, which is then
// offset to the correct column by c - 1 + 10
// (10 is the length of the header).
a[9 + c + (rand() & 112)] = 1
)
; // Empty for body
// Write the whole buffer to stdout
write(1,a,138);
}
更新:
srand(time(0))
(:(
)fill(0);rect(0,0,15,7);stroke(-1);for(int i=0;i<16;)point(i++,random(8));
样本输出:
fill(0); //sets the fill colour to black
rect(0,0,15,7); //draws a 16*8 black rectangle
stroke(-1); //set stroke colour to white
for(int i=0;i<16;) // for-loop with 16 iterations
point(i++,random(8)); // draw a point at x-coordinate i and a random y coordinate
// the colour of the point is white since that is the stroke colour
puts'P116 8';puts Array.new(16){[*[1]*7,0].shuffle}.transpose
这是一个完整程序,将netpbm格式的图像输出到stdout。
样本输出:
puts'P116 8'; # output the netpbm header (P1 for black and white, 16x8)
puts # then output the data as follows:
Array.new(16){ # make a 16-element array and for each element,
[*[1]*7,0] # generate the array [1,1,1,1,1,1,1,0] (1=black 0=white)
.shuffle} # shuffle the array
.transpose # transpose the rows/columns of the 2d array (so that each column
# has one white pixel)
Image[{RandomInteger@7+1,#}->1&~Array~16~SparseArray~{8,16}]
样本输出
说明
{RandomInteger@7+1,#}->1&~Array~16
为每列制定替换规则;将随机选择的职位替换为1。
... ~SparseArray~{8,16}
SparseArray
根据替换规则创建尺寸为8x16的。0
默认情况下是背景。(8x16,因为Mathematica首先计算行数)
Image[ ... ]
将转换SparseArray
为Image
对象。
77字节版本
ReplacePixelValue[Image@(a=Array)[0&~a~16&,8],{#,RandomInteger@7+1}->1&~a~16]
import java.awt.*;static void l(){new Frame(){public void paint(Graphics g){int x=50;int i=16;g.setColor(Color.BLACK);g.fillRect(x,x,16,8);g.setColor(Color.WHITE);for(;i>0;i--){int y=(int)(Math.random()*8);g.drawLine(x+i,x+y,x+i,x+y);setVisible(1>0);}}}.show();}
因为坐标系统包括框架窗口窗格而x=50
显得有些呆滞...因此,您需要缓冲至少26个字节,否则将不显示任何内容,因此该位就不会出现。
import java.awt.*;v->{new Frame(){public void paint(Graphics g){int x=50,i=16,y;g.setColor(Color.BLACK);g.fillRect(x,x,i,8);for(g.setColor(Color.WHITE);i>0;g.drawLine(x+i,x+y,x+i--,x+y),setVisible(1>0))y=(int)(Math.random()*8);}}.show();}
所做的更改:静态删除; Java 8 lambda;int
删除了一些;i=16
重用;将内容放入for循环中以删除括号和;
)
0xA201 'Load sprite at address 201 (which is the second byte of this instruction)
0xC007 'Set register 0 to a random number from 0 to 7 (rnd & 0x7)
0xD101 'Draw sprite. x = register 1, y = register 0, height = 1
0x7101 'Add 1 to register 1
0x3110 'If register 1 is not 16...
0x1202 'Jump to second instruction
在屏幕上绘制图像。
两种不同的方法呈现相同的字节范围:
grid [canvas .c -w 16 -he 8 -bg #000 -highlightt 0]
.c cr i 8 4 -i [set p [image c photo -w 16 -h 8]]
set x 0
time {$p p #FFF -t $x [expr int(rand()*8)];incr x} 16
grid [canvas .c -w 16 -he 8 -bg #000 -highlightt 0]
.c cr i 8 4 -i [set p [image c photo -w 16 -h 8]]
time {$p p #FFF -t [expr [incr x]-1] [expr int(rand()*8)]} 16
VBA Excel,86105字节
使用即时窗口
Cells.RowHeight=42:[a1:p8].interior.color=0:for x=0to 15:[a1].offset(rnd*7,x).interior.color=vbwhite:next
Cells.RowHeight=42:[A1:P8].Interior.Color=0:For x=0To 15:[A1].Offset(Rnd*7,x).Interior.Color=-1:Next