Java 8,321 + 42 = 363字节
import java.awt.*;import java.awt.image.*;
(w,h,a,b)->{BufferedImage i=new BufferedImage(w,h,1);Graphics2D g=(Graphics2D)i.getGraphics();g.setColor(new Color(a));g.fillRect(0,0,w,h);g.setColor(new Color(b));for(int j=h;j>0;g.drawLine(0,h-j,w,h-j--))g.setStroke(new BasicStroke(1,0,0,1,new float[]{j},j));javax.imageio.ImageIO.write(i,"png",new java.io.File("a"));}
输出到名为PNG的PNG文件 a
(无扩展名)。
用于运行lambda的周围代码:在线尝试!
不打高尔夫球
(w,h,a,b)->{
BufferedImage i=new BufferedImage(w,h,1);
Graphics2D g=(Graphics2D)i.getGraphics();
g.setColor(new Color(a));
g.fillRect(0,0,w,h);
g.setColor(new Color(b));
for(int j=h;j>0;g.drawLine(0,h-j,w,h-j--))
g.setStroke(new BasicStroke(1,0,0,1,new float[]{j},j));
javax.imageio.ImageIO.write(i,"png",new java.io.File("a"));
}
结果
输入:80, 50, 0xFF00FF, 0xFFFF00
。