Guest User

Untitled

a guest
Jul 15th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. int r=1;
  2. int g=1;
  3. int b=1;
  4. int direction = 2;
  5. int drawLength = 2;
  6. int counter = 0;
  7. int offset = 0;
  8. int xPos;
  9. int yPos;
  10.      
  11.      
  12. void setup(){
  13.   size(400,400);
  14.   background(255);
  15.   xPos=width/2;
  16.   yPos=height/2;
  17.  
  18. }
  19.      
  20.      
  21. void makePoint(){
  22.   stroke(r,g,b);
  23.   point(xPos,yPos);
  24. }
  25.      
  26.      
  27. void doPoint(){
  28.   if (direction == 0){
  29.     xPos = xPos + 1;
  30.     yPos = yPos + 1;
  31.   }
  32.   if (direction == 1){
  33.     xPos = xPos - 1;
  34.     yPos = yPos + 1;
  35.     }
  36.   if (direction == 2){
  37.     xPos = xPos - 1;
  38.     yPos = yPos - 1;
  39.     }
  40.   if (direction == 3){
  41.     xPos = xPos + 1;
  42.     yPos = yPos - 1;
  43.   }
  44. }
  45.  
  46. void updateVars(){
  47.       counter++;
  48.   if (counter >= drawLength){
  49.     //drawLength starts at 2, counter starts at 0, after drawing 2 points, it will change directions, and build upon that, increasing drawLength with every new direction
  50.      counter = 0;
  51.      direction++;
  52.    }
  53.   if (direction == 2 && xPos == (width/2)){
  54.      drawLength++;
  55.     }
  56.   if (direction == 4){
  57.     direction = 0;
  58.     drawLength++;
  59.   }
  60. }
  61.      
  62.      
  63. void doPointOffset(){
  64.     xPos++;
  65.     yPos++;
  66.     offset++;
  67.   }
  68. void doPointOffset2(){
  69.     xPos--;
  70.     yPos++;
  71.     offset++;
  72.   }
  73.  
  74. void colorChange(){
  75.   if (r<256){
  76.   r++;
  77.   r=r%256;
  78. }
  79.  
  80. if ((r%256)==0){
  81.   g=g+1;
  82. }
  83.  
  84. if ((g%256==0)){
  85.   b=b+1;
  86.   println(b);
  87. }
  88. }
  89.  
  90. void directionChange(){
  91.   if ((xPos <= width) || (yPos>=height)){
  92.       makePoint();
  93.   if (direction == 2 && drawLength == 2 && offset == 0){
  94.       doPointOffset();
  95.     }
  96.   else if (direction == 2 && drawLength == 2 && offset == 1){
  97.       doPointOffset2();
  98.     }
  99.   else{
  100.       doPoint();
  101.       updateVars();
  102.   }
  103. }}  
  104.      
  105. void draw(){
  106. directionChange();
  107. colorChange();
  108. }    
  109.  
  110.     //drawLength=how many pixels to be drawn, when counter = drawLength, counter resets and direction is changed (++)
Add Comment
Please, Sign In to add comment