本文主要是介绍大家来画图,停不下来了,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在微信上看了一篇文章:有没有一段代码,让你觉得人类的智慧也可以璀璨无比?
http://www.kuqin.com/shuoit/20150805/347430.html然后自己写了段代码实现之,然后就玩起来了,完全停不下来,准备让你们也一起来玩,去吧,皮卡丘
package com.example.gsdfgds;import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Bundle;
import android.widget.ImageView;public class MainActivity extends Activity {private static final int BITMAP_HEIGHT = 1024;private static final int BITMAP_WIDTH = 1024;private static final int BITMAP_SIZE = BITMAP_WIDTH*BITMAP_HEIGHT;private ImageView imageView;private int[] colors = new int[BITMAP_SIZE];@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imageView = (ImageView) findViewById(R.id.imageView);initMap();setBitmap();}public void initMap(){for(int i=0;i<BITMAP_WIDTH;i++){for(int j=0;j<BITMAP_HEIGHT;j++){write(i,j);}}}private void write(int i, int j) {int rColor = RV(i, j)&255;int gColor = GV(i, j)&255;int bColor = BV(i, j)&255;colors[i*BITMAP_WIDTH+j] = Color.rgb(rColor, gColor, bColor);}private int RV(int i,int j){return i*i+j*j;}private int GV(int i,int j){return 1;}private int BV(int i,int j){int k = 0;for(int l=0;l<i;l++){k = k+i;}return k-j;}public void setBitmap(){Bitmap tmp = Bitmap.createBitmap(colors, 1024, 1024, Config.ARGB_8888);imageView.setImageBitmap(tmp);}}
只要改变RV(int i,int j),GV(int i,int j),BV(int i,int j)三个方法,你就能够造出各种图片
去吧,皮卡丘
这篇关于大家来画图,停不下来了的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!