Advertisement
Guest User

Untitled

a guest
Nov 7th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. //press UP and DOWN to change refreshrate
  2. Pixel[][] pixel;
  3.  
  4. int cols = 21, rows =21, scala =20;
  5. int cnt=0, size=1;
  6. int yCoor, xCoor;
  7. int refresh, r_size=20;
  8. int[][] coords = new int[8][];
  9.  
  10.  
  11. void setup() {
  12.  
  13.   size(400, 400);
  14.   frameRate(12);
  15.   pixel = new Pixel[cols][rows];
  16.   background(0);
  17.   for (int i = 0; i < cols; i ++ ) {
  18.     for (int j = 0; j < rows; j ++ ) {
  19.       pixel[i][j] = new Pixel(i*scala, j*scala);
  20.     }
  21.   }
  22.  
  23.   coords[0]=new int[] {1,0};
  24.   coords[1]=new int[] {1,1};
  25.   coords[2]=new int[] {0,1};
  26.   coords[3]=new int[] {-1,1};
  27.   coords[4]=new int[] {-1,0};
  28.   coords[5]=new int[] {-1,-1};
  29.   coords[6]=new int[] {0,-1};
  30.   coords[7]=new int[] {1,-1};
  31.  
  32. }
  33.  
  34. void draw() {
  35.   refresh++;
  36.   if (refresh>r_size) {
  37.     background(0);
  38.     refresh=0;
  39.   }
  40.  
  41.   if (size!=1) {    
  42.     cnt++;
  43.     if (cnt>7) {
  44.       int c1 = int(random(1, 7));
  45.       int c2 = int(random(1, 7));
  46.       if(refresh%2==1){
  47.       yCoor+=coords[c1][0];
  48.       xCoor-=coords[c2][0];
  49.       }else{
  50.       yCoor+=coords[c1][0];
  51.       xCoor+=coords[c2][0];
  52.       }
  53.     }
  54.     cnt%=8;
  55.   }
  56.   rotor();
  57. }
  58.  
  59. void mousePressed() {
  60.   xCoor = mouseX/scala;
  61.   yCoor = mouseY/scala;
  62.   size=8;
  63. }
  64.  
  65. void rotor() {
  66.  
  67.   if (size==1) {
  68.   } else if (xCoor>1 && xCoor<cols-1 && yCoor>1 && yCoor<rows-1) {
  69.    
  70.     translate(-scala, -scala);
  71.    
  72.     int xPoint=xCoor+coords[cnt][0];
  73.     int yPoint=yCoor+coords[cnt][1];
  74.  
  75.     pixel[xPoint][yPoint].display();
  76.     pixel[yPoint][xPoint].display();
  77.     pixel[cols-xPoint][rows-yPoint].display();
  78.     pixel[cols-yPoint][rows-xPoint].display();
  79.   } else {
  80.     xCoor=cols/2;
  81.     yCoor=rows/2;
  82.   }
  83. }
  84.  
  85.  
  86.  
  87. class Pixel {
  88.  
  89.   float x, y;  
  90.  
  91.   Pixel(float _x, float _y) {
  92.     x = _x;
  93.     y = _y;
  94.   }
  95.  
  96.   void display() {
  97.  
  98.     fill(255/(1+cnt));
  99.     stroke(0);
  100.     rect(x, y, scala, scala);
  101.   }
  102. }
  103.  
  104. void keyPressed(){
  105.   if (keyCode== UP && r_size<49) {
  106.     r_size+=1;
  107.     println("RefreshSize of " + r_size);
  108.   }
  109.  
  110.   if (keyCode== DOWN && r_size>0) {
  111.     r_size-=1;
  112.     println("RefreshSize of " + r_size);
  113.   }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement