// Snake
float angle = 0.0; // The current angle passed to sin() to calculate the x
float speed = 3; // The angular speed (in degrees)
float shift = 45; // The shift between the phases of the circles (in degrees)
float radius = 13; // The radius of the circles to draw
float opacity = 20;
// Scrollbars
class Scrollbar {
int x, y; // The x- and y-coordinates
float sw, sh; // Width and height of scrollbar
float pos; // Position of thumb
float posMin, posMax; // Max and min values of thumb
boolean rollover; // True when the mouse is over
boolean locked; // True when its the active scrollbar
float minVal, maxVal; // Min and max values for the thumb
Scrollbar (int xp, int yp, int w, int h, float miv, float mav) {
x = xp;
y = yp;
sw = w;
sh = h;
minVal = miv;
maxVal = mav;
pos = x + sw/2 - sh/2;
posMin = x;
posMax = x + sw - sh;
}
// Updates the over boolean and the position of the thumb
void update(int mx, int my) {
if (over(mx, my) == true) {
rollover = true;
} else {
rollover = false;
}
if (locked == true) {
pos = constrain(mx-sh/2, posMin, posMax);
}
}
// Locks the thumb so the mouse can move off and still update
void press(int mx, int my) {
if (rollover == true) {
locked = true;
} else {
locked = false;
}
}
// Resets the scrollbar to neutral
void release() {
locked = false;
}
// Returns true if the cursor is over the scrollbar
boolean over(int mx, int my) {
if ((mx > x) && (mx < x+sw) && (my > y) && (my < y+sh)) {
return true;
} else {
return false;
}
}
void display() {
fill(255);
rect(x, y, sw, sh);
if ((rollover==true) || (locked==true)) {
fill(0);
} else {
fill(104);
}
rect(pos, y, sh, sh);
}
// Returns the current value of the thumb
float getPos() {
float scalar = sw/(sw-sh);
float ratio = (pos - x) * scalar;
float offset = minVal + (ratio/sw * (maxVal-minVal));
return offset;
}
//PGraphics for directions and GUI
control = createGraphics(width, height);
control.beginDraw();
control.background();
// "Colour Control" text
control.PFont font = createFont("/media/css/Chunkfive-webfont.ttf", 13);
control.textFont(font);
control.fill(0, 247, 198); // aqua
control.text("Colour Control", 7, 24);
// "Red" text
control.PFont font = createFont("/media/css/Chunkfive-webfont.ttf", 12);
control.textFont(font);
control.fill(255, 0, 0); // red
control.text("Red", 100, 44);
// "Green" text
control.PFont font = createFont("/media/css/Chunkfive-webfont.ttf", 12);
control.textFont(font);
control.fill(0, 255, 0); // Green
control.text("Green", 98, 64);
// "blue" text
control.PFont font = createFont("/media/css/Chunkfive-webfont.ttf", 14);
control.textFont(font);
control.fill(0, 0, 255); // Blue
control.text("Blue", 100, 85);
//box around "Press 'a' key for circles"
control.fill(255, 100);
control.rect(4, 546, 80, 50);
//box around "Press 'd' key for snake"
control.fill(255, 100);
control.rect(419, 546, 78, 50);
//box around "Press 'z' key for company logo"
control.fill(255, 100);
control.rect(5, 247, 79, 92);
//box around "right click to erase"
control.fill(255, 100);
control.rect(420, 247, 77, 70);
// "Press 'a' key for circles" text
offscreen.PFont font = createFont("/media/css/Chunkfive-webfont.ttf", 15);
offscreen.textFont(font);
offscreen.fill(0, 247, 198); // aqua
offscreen.String s = "Press the a key for Circles";
offscreen.text(s, 10, 550, 70, 400);
// "Press 'd' key for snake" text
offscreen.PFont font = createFont("/media/css/Chunkfive-webfont.ttf", 15);
offscreen.textFont(font);
offscreen.fill(0, 247, 198); // aqua
offscreen.String d = "Press the d key for Snake";
offscreen.text(d, 425, 550, 70, 400);
// "Press 'z' key for company logo" text
offscreen.PFont font = createFont("/media/css/Chunkfive-webfont.ttf", 15);
offscreen.textFont(font);
offscreen.fill(0, 247, 198); // aqua
offscreen.String z = "Press the z key and click for the company logo";
offscreen.text(z, 10, 250, 70, 400);
// "right click to erase" text
offscreen.PFont font = createFont("/media/css/Chunkfive-webfont.ttf", 15);
offscreen.textFont(font);
offscreen.fill(0, 247, 198); // aqua
offscreen.String r = "right click the mouse to erase";
offscreen.text(r, 425, 254, 70, 400);
offscreen.noStroke();
// Inputs: x, y, width, height, minVal, maxVal
control.bar1 = new Scrollbar(10, 35, 80, 10, 0.0, 255.0);
control.bar2 = new Scrollbar(10, 55, 80, 10, 0.0, 255.0);
control.bar3 = new Scrollbar(10, 75, 80, 10, 0.0, 255.0);