Monday, October 18, 2010

2D Etch-a-Sketch by Legendary Gaming

// ... original by Coventry University
// it just seems that frameRate is not
// supported. Also special characters
// like # don't seem to work, I replaced
// that one

int[] xc = new int[91000];/* These variables */
int[] yc = new int[91000];
int[] ss = new int[91000]; /* are used to declare the arrays */
float[] lc1 = new float[91000];
float[] lc2 = new float[91000]; /* to restore the current lines drawn by the user */
float[] lc3 = new float[91000];
int justdeleted=0;

// Setup variables
int i=1;
int j;
int x=0, y=0;
int lastx=0, lasty=0;
int t=0;
int rain=0;
int cc=0;
float a=0, a1=0, a2=0;
float b=255, b1=255, b2=255;
int frame=250;
int precision=0;
int ff=0;
int linesize=2;
// end of setup variables

void setup(){
  size(400,400);
  xc[0]=1;
  yc[0]=1;
  strokeWeight(2);
  background(255,255,255);
  smooth();
  fill(0,0,0);
  fill(255,0,0);
}

void draw(){
  if(t>=120){
  a=random(256);a1=random(256);a2=random(256);
  stroke(random(a),random(a1),random(a2));
  t=0;
  }
  lastx=x;
  lasty=y;
  if(keyPressed){
  if(key=='s'){
    if(y<399){
      if(justdeleted==1){
        justdeleted=0; i=0;
      }
      stroke(a,a1,a2);
      y=y+1;
      yc[i]=y; lc1[i]=a;
      lc2[i]=a1;
      lc3[i]=a2; xc[i]=x; ss[i]=linesize ;i=i+1; if(rain==1){ t++; }
    }
  }
  if(key=='a'){
    if(x>0){
      if(justdeleted==1){
        justdeleted=0; i=0;
      }
      stroke(a,a1,a2);
      x=x-1; lc1[i]=a;
      lc2[i]=a1;
      lc3[i]=a2; yc[i]=y; xc[i]=x; ss[i]=linesize; i=i+1; if(rain==1){ t++; }
    }
  }
  if(key=='d'){
    if(x<399){
      if(justdeleted==1){
        justdeleted=0; i=0;
      }
      stroke(a,a1,a2);
      x=x+1;
      lc1[i]=a;
      lc2[i]=a1;
      lc3[i]=a2; yc[i]=y; xc[i]=x; ss[i]=linesize; i=i+1; if(rain==1){ t++; }
    }
  }
  if(key=='w'){
    if(y>0){
      if(justdeleted==1){
        justdeleted=0; i=0;
      }
      stroke(a,a1,a2);
      y=y-1;
      lc1[i]=a;
      lc2[i]=a1;
      lc3[i]=a2; yc[i]=y; xc[i]=x; ss[i]=linesize; i=i+1; if(rain==1){ t++; }
    }
  }
  if(key=='-'){
    justdeleted=1;
    background(b,b1,b2);
  }
  if(key=='p' || key=='P'){
    ff=frame;
    precision=1;
    frameRate(10);
  }
  }
  line(lastx,lasty,x,y);
}

void keyReleased(){
  if(key=='x'){
  print("rain" + rain);
  if(rain==0){
    rain=1;
  }
  else{
    rain=0; a=0; a1=0; a2=0; stroke(0,0,0);
  }
  }
  if(key=='z'){
  if(rain==0){
    if(cc==0){
      a=255; a1=255; a2=0;
      stroke(a,a1,a2); cc=1;
    }
    else if(cc==1){
      a=0; a1=255; a2=0;
      stroke(a,a1,a2);
      cc=2;
    }
    else if(cc==2){
      a=0; a1=0; a2=255;
      stroke(a,a1,a2);
      cc=3;
    }
    else if(cc==3){
      a=0; a1=0; a2=0;
      stroke(a,a1,a2);
      cc=0;
    }
  }
  else if(rain==1){
    a=random(256);a1=random(256);a2=random(256);
    stroke(a,a1,a2);t=0;
  }
  }
  if(key=='k'){
  b=random(256); b1=random(256); b2=random(256);
  background(b,b1,b2);if(justdeleted==0){ trace(i);}
  }
  if(key=='r' || key=='R'){
  b=255; b1=255; b2=255; background(b,b1,b2);
  stroke(0,0,0); trace(i);
  }
  if(key=='s' || key =='S'){
  if(linesize==1){
    linesize=2; strokeWeight(2);
  }
  else if(linesize==2){
    linesize=3; strokeWeight(3);
  }
  else if(linesize==3){
    linesize=4; strokeWeight(4);
  }
  else if(linesize==4){
    linesize=1; strokeWeight(1);
  }
  }
  if(key=='r' || key=='R'){
  justdeleted=0;
  trace(i);
  }
}

void trace(int i){
  for(j=1;j<i;j=j+1){
  strokeWeight(ss[j]);
  stroke(lc1[j],lc2[j],lc3[j]);
  line(xc[j-1],yc[j-1],xc[j],yc[j]);
  }
}

info info

submitted by: DARYL_Gamma
views: 78
A 2D version of an etch-a-sketch, but without the look of one :P Multiple features. All instructions explained when the program is run ^_^

treeThis sketch has a parent
Tags: 2D, etch, a, sketch, legendary, gaming, coventry, university, cool, awesome

comments comment

loading loading...

 

Add a comment: