Guest User

Untitled

a guest
Jul 15th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. int r=0;
  2. int g=0;
  3. int b=0;
  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(800,800);
  14. background(255);
  15. frameRate(60000);
  16. xPos=width/2;
  17. yPos=height/2;
  18.  
  19. }
  20.  
  21.  
  22. void makePoint(){
  23. stroke(r,g,b);
  24. point(xPos,yPos);
  25. }
  26.  
  27.  
  28. void doPoint(){
  29. if (direction == 0){
  30. xPos = xPos + 1;
  31. yPos = yPos + 1;
  32. }
  33. if (direction == 1){
  34. xPos = xPos - 1;
  35. yPos = yPos + 1;
  36. }
  37. if (direction == 2){
  38. xPos = xPos - 1;
  39. yPos = yPos - 1;
  40. }
  41. if (direction == 3){
  42. xPos = xPos + 1;
  43. yPos = yPos - 1;
  44. }
  45. }
  46.  
  47. void updateVars(){
  48. counter++;
  49. r++;
  50. if (r > 255){
  51. r = 0;
  52. g++;
  53. }
  54. if (g > 255){
  55. g = 0;
  56. b++;
  57. }
  58. if (b > 255){
  59. b = 0;
  60. }
  61. if (counter >= drawLength){
  62. //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
  63. counter = 0;
  64. direction++;
  65. }
  66. if (direction == 2 && xPos == (width/2)){
  67. drawLength++;
  68. }
  69. if (direction == 4){
  70. direction = 0;
  71. drawLength++;
  72. }
  73. }
  74.  
  75.  
  76. void doPointOffset(){
  77. xPos++;
  78. yPos++;
  79. offset++;
  80. }
  81. void doPointOffset2(){
  82. xPos--;
  83. yPos++;
  84. offset++;
  85. }
  86.  
  87. void colorChange(){
  88. if (r<255){
  89. r++;
  90. r=r%255;
  91. }
  92.  
  93. if ((r%255)==0){
  94. g=g+1;
  95. }
  96.  
  97. if ((g%255==0)){
  98. b=b+1;
  99. println(b);
  100. }
  101. }
  102.  
  103. void directionChange(){
  104. if ((xPos <= width) || (yPos>=height)){
  105. makePoint();
  106. if (direction == 2 && drawLength == 2 && offset == 0){
  107. doPointOffset();
  108. }
  109. else if (direction == 2 && drawLength == 2 && offset == 1){
  110. doPointOffset2();
  111. }
  112. else{
  113. doPoint();
  114. updateVars();
  115. }
  116. }}
  117.  
  118. void draw(){
  119. directionChange();
  120. //colorChange();
  121. }
Add Comment
Please, Sign In to add comment