Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //press UP and DOWN to change refreshrate
- Pixel[][] pixel;
- int cols = 21, rows =21, scala =20;
- int cnt=0, size=1;
- int yCoor, xCoor;
- int refresh, r_size=20;
- int[][] coords = new int[8][];
- void setup() {
- size(400, 400);
- frameRate(12);
- pixel = new Pixel[cols][rows];
- background(0);
- for (int i = 0; i < cols; i ++ ) {
- for (int j = 0; j < rows; j ++ ) {
- pixel[i][j] = new Pixel(i*scala, j*scala);
- }
- }
- coords[0]=new int[] {1,0};
- coords[1]=new int[] {1,1};
- coords[2]=new int[] {0,1};
- coords[3]=new int[] {-1,1};
- coords[4]=new int[] {-1,0};
- coords[5]=new int[] {-1,-1};
- coords[6]=new int[] {0,-1};
- coords[7]=new int[] {1,-1};
- }
- void draw() {
- refresh++;
- if (refresh>r_size) {
- background(0);
- refresh=0;
- }
- if (size!=1) {
- cnt++;
- if (cnt>7) {
- int c1 = int(random(1, 7));
- int c2 = int(random(1, 7));
- if(refresh%2==1){
- yCoor+=coords[c1][0];
- xCoor-=coords[c2][0];
- }else{
- yCoor+=coords[c1][0];
- xCoor+=coords[c2][0];
- }
- }
- cnt%=8;
- }
- rotor();
- }
- void mousePressed() {
- xCoor = mouseX/scala;
- yCoor = mouseY/scala;
- size=8;
- }
- void rotor() {
- if (size==1) {
- } else if (xCoor>1 && xCoor<cols-1 && yCoor>1 && yCoor<rows-1) {
- translate(-scala, -scala);
- int xPoint=xCoor+coords[cnt][0];
- int yPoint=yCoor+coords[cnt][1];
- pixel[xPoint][yPoint].display();
- pixel[yPoint][xPoint].display();
- pixel[cols-xPoint][rows-yPoint].display();
- pixel[cols-yPoint][rows-xPoint].display();
- } else {
- xCoor=cols/2;
- yCoor=rows/2;
- }
- }
- class Pixel {
- float x, y;
- Pixel(float _x, float _y) {
- x = _x;
- y = _y;
- }
- void display() {
- fill(255/(1+cnt));
- stroke(0);
- rect(x, y, scala, scala);
- }
- }
- void keyPressed(){
- if (keyCode== UP && r_size<49) {
- r_size+=1;
- println("RefreshSize of " + r_size);
- }
- if (keyCode== DOWN && r_size>0) {
- r_size-=1;
- println("RefreshSize of " + r_size);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement