SHARE
TWEET

Untitled

a guest Dec 11th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Controlling Elli
  2.  
  3. //Elli body segment variables
  4. int[] elliX = new int[7];
  5. int[] elliY = new int[7];
  6. color[] elliC = new color[7];
  7.  
  8. //Elli movement values
  9. boolean up = false;
  10. boolean down = false;
  11. int udmod = 0;
  12. boolean right = true;
  13. boolean left = false;
  14. int rlmod = 1;
  15.  
  16. void setup(){
  17.   background(255);
  18.   //Variables to be modified on program initialition
  19.   int initX = 20;
  20.   int initY = 20;
  21.   color initC = color(100, 0, 0);
  22.   float initCR = red(initC);
  23.   //Setting the size and framerate of the program window
  24.   size(800, 800);
  25.   frameRate(8);
  26.   //Setup for each of Elli's X values
  27.   for(int i = 0; i < elliX.length; ++i){
  28.     elliX[i] = initX;
  29.     initX += 20;
  30.   }
  31.   //Setup for each of Elli's Y values
  32.   for(int i = 0; i < elliY.length; ++i){
  33.     elliY[i] = initY;
  34.   }
  35.   //Setup for each of Elli's color values
  36.   for(int i = 0; i < elliC.length; ++i){
  37.     elliC[i] = initC;
  38.     initCR += 30;
  39.     initC = color(initCR, 0, 0);
  40.   }
  41. }
  42.  
  43. void draw(){
  44.   if(keyPressed && keyCode == UP && !up && !down){
  45.     down = false;
  46.     right = false;
  47.     left = false;
  48.     up = true;
  49.     rlmod = 0;
  50.     udmod = -1;
  51.   }
  52.   if(keyPressed && keyCode == DOWN && !down && !up){
  53.     up = false;
  54.     right = false;
  55.     left = false;
  56.     down = true;
  57.     rlmod = 0;
  58.     udmod = 1;
  59.   }
  60.   if(keyPressed && keyCode == RIGHT && !right && !left){
  61.     left = false;
  62.     up = false;
  63.     down = false;
  64.     right = true;
  65.     udmod = 0;
  66.     rlmod = 1;
  67.   }
  68.   if(keyPressed && keyCode == LEFT && !left && !right){
  69.     right = false;
  70.     up = false;
  71.     down = false;
  72.     left = true;
  73.     udmod = 0;
  74.     rlmod = -1;
  75.   }
  76.   //Redrawing background every frame
  77.   background(255);
  78.   //Drawing Elli every frame
  79.   elli();
  80.   //Modifying Elli's X position for next frame
  81.   for(int i = 0; i < elliX.length; ++i){
  82.     if(i != elliX.length-1){
  83.       elliX[i] = elliX[i+1];
  84.     }
  85.     else if(i == elliX.length-1){
  86.       elliX[i] += 20*rlmod;
  87.     }
  88.   }
  89.   //Modifying Elli's Y position for next frame
  90.   for(int i = 0; i <elliY.length; ++i){
  91.     if(i != elliY.length-1){
  92.       elliY[i] = elliY[i+1];
  93.     }
  94.       else if(i == elliY.length-1){
  95.       elliY[i] += 20*udmod;
  96.     }
  97.   }
  98. }
  99.  
  100. void elli(){
  101.   //Preventing index out of bounds error
  102.   int count = min(elliX.length, elliY.length);
  103.   //Drawing each of Elli's segments
  104.   for(int i = 0; i < count; ++i){
  105.     fill(elliC[i]);
  106.     //Drawing Elli's basic segments
  107.     if(i != count-1){
  108.       circle(elliX[i], elliY[i], 30);
  109.     }
  110.     //Drawing Elli's face segment
  111.     else if(i == count-1){
  112.       circle(elliX[i], elliY[i], 30);
  113.       fill(0);
  114.       circle(elliX[i]-5, elliY[i], 5);
  115.       circle(elliX[i]+5, elliY[i], 5);
  116.     }
  117.   }
  118. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top