> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.6oV$FAVmZMb/rev.4991
 * 
 * authors: 
 *   Randati
 *   bildramer
 *   bildramer
 *   Randati
 *   tvc
 *   Marach

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



PFont arial;

class Snake {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    int prevRand;
    int grid; // At least 3
    Snake(int userGrid){
        x4 = x3 = x2 = x1 = width/2+floor(random(21))-10;
        y4 = y3 = y2 = y1 = height/2+floor(random(21))-10;
        prevRand = 4;
        grid = userGrid;
    }
    void updateAndDraw(){
        color c = #FF00FF; //gay
        stroke(c);
        strokeWeight(4);
        line(x1, y1, x2, y2);
        stroke(c, 200);
        strokeWeight(3);
        line(x2, y2, x3, y3);
        stroke(c, 128);
        strokeWeight(2.5);
        line(x3, y3, x4, y4);
        strokeWeight(1);
        if(frameCount%15 != 0) return;
        
        x4 = x3;
        y4 = y3;
        x3 = x2;
        y3 = y2;
        x2 = x1;
        y2 = y1;
        
        int running = 1, rand;
        while(running == 1){
            do {
                rand = floor(random(4));
            } while(rand+2 == prevRand || rand-2 == prevRand);
            switch(rand){
                case 0: if(x1 + width/grid < width-10){ x1 += width/grid; running = 0; } break;
                case 1: if(y1 + height/grid < height-10){ y1 += height/grid; running = 0; } break;
                case 2: if(x1 - width/grid >= 10){ x1 -= width/grid; running = 0; } break;
                case 3: if(y1 - height/grid >= 10){ y1 -= height/grid; running = 0; } break;
            }
        }
        prevRand = rand;
    }
}
int num_snakes =  8;
Snake[] snakes = new Snake[num_snakes];

PGraphics bg;
PGraphics bg_lines;
int font_size = 10;
void setup(){
    arial = loadFont("monospace");
    textFont(arial, font_size);
    //textMode(SCREEN);
    size(300, 300);
    //smooth();
    noStroke();
    back();
    for(int i = 0; i < num_snakes; ++i) snakes[i] = new Snake(i+5);
    
    bg_lines = createGraphics(width, height, P2D);
}

void draw(){
    background(51);
    image(bg, 0, 0);
    glitch();
    for(int i = 0; i < num_snakes; ++i) snakes[i].updateAndDraw();
    lines();
}

int lines_i = 0;
void lines() {
    bg_lines.beginDraw();
    bg_lines.smooth();
    
    if (frameCount%1 == 0) lines_i++;
    if (lines_i >= height*4) lines_i = 0;
    int side_i = lines_i % height;
    
    bg_lines.stroke(side_i/height*255, 20);
    
    if (lines_i >= 0 && lines_i < height)
        bg_lines.line(0, side_i, side_i, height-1);
    else if (lines_i >= height && lines_i < height*2)
        bg_lines.line(side_i, height-1, width-1, height-1-side_i);
    else if (lines_i >= height*2 && lines_i < height*3)
        bg_lines.line(width-1, height-1-side_i, width-1-side_i, 0);
    else if (lines_i >= height*3 && lines_i < height*4)
        bg_lines.line(width-1-side_i, 0, 0, side_i);
        
    bg_lines.endDraw();
    image(bg_lines, 0, 0);
}

void back() {
    int back_x = width/2, back_y = height/2;
    bg = createGraphics(width, height, P2D);
    bg.beginDraw();
    bg.smooth();
    //bg.background(51);
    bg.noStroke();
    for (int x = -10; x <= width+10; x += 20) {
        for (int y = -10; y <= height+10; y += 20) {
            float size = dist(back_x, back_y, x, y);
            size = size / sqrt(pow(width, 2)+pow(height, 2)) * 66; // Magic numbers!
    //I see none
    //IT ALL MAKES SENSE
    //i cannot stress enough how! important it is to stay in touch with reality
            bg.fill(70);
            float a = atan2(y - back_y, x - back_x);
            float x_dist = cos(a) * 15;
            float y_dist = sin(a) * 15;
            bg.ellipse(x+10+x_dist, y+10+y_dist, size, size);
        }
    }
    bg.endDraw();
}

String glitch_text = "left left right forwards backwards rightwards left is the way left is the way always look right always look right always look right left forwards backwards backwards remember to left right forwards down down up north is west sun rising west sun rising north north north north north will bring you the right side up as long as you up the right thinking otherwise you will be left left left with nothing but trouble which was send you downwards southwards i cannot stress enough how important it is to stay in touch with reality. i cannot stress enough how! important it is to stay in touch with reality reality reality down left left right attention sir. attention! if you will not live right, then you do not will be all \"reality is the way\" do not be swayed by escapism. smile and repeat \"they right just meddle\". left left right forwards backwards rightwards left is the way left is the way always look right always look right always look right left forwards backwards backwards remember to left- ...the weak mind is will be swayed by this new way of escapism. they need to find the right right right right right otherwise the downwards south down destination. so always always look right. think about what karma is left left left behind you project your [?] worth and downwards. right always we [?] to board board board board board thinking. then you will be free of feeling down feeling down feeling down feeling down feeling down.";
int rand_i = 0;
bool rand_add = true;
void glitch() {
    if (rand_add) {
        if (frameCount%1 == 0) rand_i++; // lolwut
        if (rand_i >= (width/font_size+6)*(height/font_size+6)) rand_add = false;
    }
    else {
        if (frameCount%1 == 0) rand_i--; // lolwut #2
        if (rand_i <= 0) rand_add = true;
    }
    fill(#40C0FF);
    text(glitch_text.substr(0, rand_i), 2, 2, width, height);
}