Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int r=1;
- int g=1;
- int b=1;
- int direction = 2;
- int drawLength = 2;
- int counter = 0;
- int offset = 0;
- int xPos;
- int yPos;
- void setup(){
- size(400,400);
- background(255);
- xPos=width/2;
- yPos=height/2;
- }
- void makePoint(){
- stroke(r,g,b);
- point(xPos,yPos);
- }
- void doPoint(){
- if (direction == 0){
- xPos = xPos + 1;
- yPos = yPos + 1;
- }
- if (direction == 1){
- xPos = xPos - 1;
- yPos = yPos + 1;
- }
- if (direction == 2){
- xPos = xPos - 1;
- yPos = yPos - 1;
- }
- if (direction == 3){
- xPos = xPos + 1;
- yPos = yPos - 1;
- }
- }
- void updateVars(){
- counter++;
- if (counter >= drawLength){
- //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
- counter = 0;
- direction++;
- }
- if (direction == 2 && xPos == (width/2)){
- drawLength++;
- }
- if (direction == 4){
- direction = 0;
- drawLength++;
- }
- }
- void doPointOffset(){
- xPos++;
- yPos++;
- offset++;
- }
- void doPointOffset2(){
- xPos--;
- yPos++;
- offset++;
- }
- void colorChange(){
- if (r<256){
- r++;
- r=r%256;
- }
- if ((r%256)==0){
- g=g+1;
- }
- if ((g%256==0)){
- b=b+1;
- println(b);
- }
- }
- void directionChange(){
- if ((xPos <= width) || (yPos>=height)){
- makePoint();
- if (direction == 2 && drawLength == 2 && offset == 0){
- doPointOffset();
- }
- else if (direction == 2 && drawLength == 2 && offset == 1){
- doPointOffset2();
- }
- else{
- doPoint();
- updateVars();
- }
- }}
- void draw(){
- directionChange();
- colorChange();
- }
- //drawLength=how many pixels to be drawn, when counter = drawLength, counter resets and direction is changed (++)
Add Comment
Please, Sign In to add comment