Advertisement
tomte55

RGB Blender

Aug 14th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var line_r = {
  2.   xs: 100,
  3.   xe: 300,
  4.   y: 250
  5. };
  6. var line_g = {
  7.   xs: 100,
  8.   xe: 300,
  9.   y: 300
  10. };
  11. var line_b = {
  12.   xs: 100,
  13.   xe: 300,
  14.   y: 350
  15. };
  16. var line_a = {
  17.   xs: 100,
  18.   xe: 300,
  19.   y: 200
  20. };
  21.  
  22. var box_r = {
  23.   x: 200,
  24.   y: 250,
  25.   xs: 15,
  26.   ys: 10
  27. };
  28. var box_g = {
  29.   x: 200,
  30.   y: 300,
  31.   xs: 15,
  32.   ys: 10
  33. };
  34. var box_b = {
  35.   x: 200,
  36.   y: 350,
  37.   xs: 15,
  38.   ys: 10
  39. };
  40. var box_a = {
  41.   x: 300,
  42.   y: 200,
  43.   xs: 15,
  44.   ys: 10
  45. };
  46.  
  47. var selected = {
  48.   r: false,
  49.   g: false,
  50.   b: false,
  51.   a: false
  52. };
  53.  
  54. function setup() {
  55.     createCanvas(400, 400);
  56.     rectMode(CENTER);
  57. }
  58.  
  59. function draw() {
  60.     background(150);
  61.     var r = map(box_r.x, line_r.xs, line_r.xe, 0, 255);
  62.     var g = map(box_g.x, line_g.xs, line_g.xe, 0, 255);
  63.     var b = map(box_b.x, line_b.xs, line_b.xe, 0, 255);
  64.     var a = map(box_a.x, line_a.xs, line_a.xe, 0, 255);
  65.  
  66.     noStroke();
  67.     fill(0, 0, 0, 100);
  68.     rect(100+5, 100+5, 50, 25)
  69.  
  70.     //Picture
  71.     noStroke();
  72.     fill(0, 0, 0, 100);
  73.     rect(200+5, 100+5, 150, 150);
  74.     fill(150);
  75.     rect(200, 100, 150, 150);
  76.     fill(r, g, b, a);
  77.     stroke(255);
  78.     rect(200, 100, 150, 150);
  79.     fill(255);
  80.  
  81.     //RGB Box
  82.     //Red
  83.     noStroke();
  84.     fill(0, 0, 0, 100);
  85.     rect(300+5, 50+5, 50, 25)
  86.     stroke(255);
  87.     fill(255, 0, 0);
  88.     rect(300, 50, 50, 25);
  89.  
  90.     //Green
  91.     noStroke();
  92.     fill(0, 0, 0, 100);
  93.     rect(300+5, 100+5, 50, 25)
  94.     stroke(255);
  95.     fill(0, 255, 0);
  96.     rect(300, 100, 50, 25);
  97.  
  98.     //Blue
  99.     noStroke();
  100.     fill(0, 0, 0, 100);
  101.     rect(300+5, 150+5, 50, 25)
  102.     stroke(255);
  103.     fill(0, 0, 255);
  104.     rect(300, 150, 50, 25);
  105.  
  106.     //Alpha
  107.     stroke(255);
  108.     fill(0);
  109.     rect(100, 100, 50, 25);
  110.  
  111.  
  112.     fill(255);
  113.     stroke(0);
  114.     textSize(14);
  115.     //Red
  116.     text("R:", 278, 55);
  117.     text(int(r),295, 55);
  118.     //Green
  119.     text("G:", 278, 105);
  120.     text(int(g),295, 105);
  121.     //Blue
  122.     text("B:", 278, 155);
  123.     text(int(b),295, 155);
  124.     //Alpha
  125.     text("A:", 78, 105);
  126.     text(int(a),95, 105);
  127.  
  128.     //Alpha Slider
  129.     line(line_a.xs, line_a.y, line_a.xe, line_a.y);
  130.     if (mouseX >= box_a.x-box_a.xs/2 && mouseX <= box_a.x+box_a.xs/2 && mouseY >= box_a.y-box_a.ys/2 && mouseY <= box_a.y+box_a.ys/2 || selected.a) {
  131.       fill(200);
  132.     } else {
  133.       fill(255);
  134.     }
  135.     rect(box_a.x, box_a.y, box_a.xs, box_a.ys);
  136.     //Red Slider
  137.     line(line_r.xs, line_r.y, line_r.xe, line_r.y);
  138.     //Shadow
  139.     fill(0, 0, 0, 100);
  140.     noStroke();
  141.     rect(box_r.x+2, box_r.y+2, box_r.xs, box_r.ys);
  142.     stroke(0);
  143.     if (mouseX >= box_r.x-box_r.xs/2 && mouseX <= box_r.x+box_r.xs/2 && mouseY >= box_r.y-box_r.ys/2 && mouseY <= box_r.y+box_r.ys/2 || selected.r) {
  144.       fill(200, 0, 0);
  145.     } else {
  146.       fill(255, 0, 0);
  147.     }
  148.     rect(box_r.x, box_r.y, box_r.xs, box_r.ys);
  149.  
  150.     //Green Slider
  151.     line(line_g.xs, line_g.y, line_g.xe, line_g.y);
  152.     //Shadow
  153.     fill(0, 0, 0, 100);
  154.     noStroke();
  155.     rect(box_g.x+2, box_g.y+2, box_g.xs, box_g.ys);
  156.     stroke(0);
  157.     if (mouseX >= box_g.x-box_g.xs/2 && mouseX <= box_g.x+box_g.xs/2 && mouseY >= box_g.y-box_g.ys/2 && mouseY <= box_g.y+box_g.ys/2 || selected.g) {
  158.       fill(0, 200, 0);
  159.     } else {
  160.       fill(0, 255, 0);
  161.     }
  162.     rect(box_g.x, box_g.y, box_g.xs, box_g.ys);
  163.  
  164.     //Blue Slider
  165.     line(line_b.xs, line_b.y, line_b.xe, line_b.y);
  166.     //Shadow
  167.     fill(0, 0, 0, 100);
  168.     noStroke();
  169.     rect(box_b.x+2, box_b.y+2, box_b.xs, box_b.ys);
  170.     stroke(0);
  171.     if (mouseX >= box_b.x-box_b.xs/2 && mouseX <= box_b.x+box_b.xs/2 && mouseY >= box_b.y-box_b.ys/2 && mouseY <= box_b.y+box_b.ys/2 || selected.b) {
  172.       fill(0, 0, 200);
  173.     } else {
  174.       fill(0, 0, 255);
  175.     }
  176.     rect(box_b.x, box_b.y, box_b.xs, box_b.ys);
  177.     fill(255);
  178.  
  179.     if (mouseX < line_r.xs && selected.r) {
  180.       box_r.x = line_r.xs;
  181.     }
  182.     if (mouseX > line_r.xe && selected.r) {
  183.       box_r.x = line_r.xe;
  184.     }
  185.     if (mouseX < line_g.xs && selected.g) {
  186.       box_g.x = line_g.xs;
  187.     }
  188.     if (mouseX > line_g.xe && selected.g) {
  189.       box_g.x = line_g.xe;
  190.     }
  191.     if (mouseX < line_b.xs && selected.b) {
  192.       box_b.x = line_b.xs;
  193.     }
  194.     if (mouseX > line_b.xe && selected.b) {
  195.       box_b.x = line_b.xe;
  196.     }
  197.     if (mouseX < line_a.xs && selected.a) {
  198.       box_a.x = line_a.xs;
  199.     }
  200.     if (mouseX > line_a.xe && selected.a) {
  201.       box_a.x = line_a.xe;
  202.     }
  203. }
  204.  
  205. function mouseDragged() {
  206.   if (selected.r && box_r.x >= line_r.xs) {
  207.     if (mouseX >= line_r.xs && mouseX <= line_r.xe) {
  208.       box_r.x = mouseX;
  209.     }
  210.   }
  211.   if (selected.g && box_g.x >= line_g.xs) {
  212.     if (mouseX >= line_g.xs && mouseX <= line_g.xe) {
  213.       box_g.x = mouseX;
  214.     }
  215.   }
  216.   if (selected.b && box_b.x >= line_b.xs) {
  217.     if (mouseX >= line_b.xs && mouseX <= line_b.xe) {
  218.       box_b.x = mouseX;
  219.     }
  220.   }
  221.   if (selected.a && box_a.x >= line_a.xs) {
  222.     if (mouseX >= line_a.xs && mouseX <= line_a.xe) {
  223.       box_a.x = mouseX;
  224.     }
  225.   }
  226. }
  227.  
  228. function mousePressed() {
  229.   if (mouseX >= box_r.x-box_r.xs/2 && mouseX <= box_r.x+box_r.xs/2 && mouseY >= box_r.y-box_r.ys/2 && mouseY <= box_r.y+box_r.ys/2) {
  230.     selected.r = true;
  231.   }
  232.   if (mouseX >= box_g.x-box_g.xs/2 && mouseX <= box_g.x+box_g.xs/2 && mouseY >= box_g.y-box_g.ys/2 && mouseY <= box_g.y+box_g.ys/2) {
  233.     selected.g = true;
  234.   }
  235.   if (mouseX >= box_b.x-box_b.xs/2 && mouseX <= box_b.x+box_b.xs/2 && mouseY >= box_b.y-box_b.ys/2 && mouseY <= box_b.y+box_b.ys/2) {
  236.     selected.b = true;
  237.   }
  238.   if (mouseX >= box_a.x-box_a.xs/2 && mouseX <= box_a.x+box_a.xs/2 && mouseY >= box_a.y-box_a.ys/2 && mouseY <= box_a.y+box_a.ys/2) {
  239.     selected.a = true;
  240.   }
  241. }
  242.  
  243. function mouseReleased() {
  244.   selected.r = false;
  245.   selected.g = false;
  246.   selected.b = false;
  247.   selected.a = false;
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement