Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean colorA = false;
- boolean colorB = false;
- PFont f;
- char a = 'R';
- float ax = 80;
- float ay = 80;
- char b = 'P';
- float bx = 180;
- float by = 80;
- void setup() {
- size(640, 360);
- f = createFont("Arial",20,true);
- }
- void draw() {
- background(0);
- textFont(f);
- float cwA = textWidth(a);
- float cwB = textWidth(b);
- // Text A
- if (colorA == true) {
- fill(204, 102, 0);
- if (mouseX > ax-cwA/2.0 && mouseX < ax+cwA/2.0 &&
- mouseY > ay-2*cwA && mouseY < ay) {
- fill(204, 102, 0);
- colorA = false;
- }
- } else {
- if (mouseX > ax-cwA/2.0 && mouseX < ax+cwA/2.0 &&
- mouseY > ay-2*cwA && mouseY < ay) {
- fill(204, 102, 0);
- } else {
- fill(255);
- }
- }
- text(a, ax-cwA/2.0, ay-cwA/2.0);
- // Text B
- if (colorB == true) {
- fill(204, 102, 0);
- } else {
- fill(255);
- }
- text(b, bx-cwB/2.0, by-cwB/2.0);
- }
- void keyPressed() {
- if (key >= 'P' && key <= 'p') {
- if (colorB == true) {
- colorB = false;
- } else {
- colorB = true;
- }
- }
- if (key == CODED) {
- if (keyCode == LEFT || keyCode == RIGHT) {
- if (colorB == true) {
- colorA = true;
- colorB = false;
- } else {
- colorA = false;
- colorB = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement