| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,43 +3,49 @@ | |||
| 3 | 3 | * | |
| 4 | 4 | * Move the scrollbars left and right to change the positions of the images. | |
| 5 | 5 | */ | |
| 6 | - | ||
| 7 | - HScrollbar hs1, hs2; | ||
| 8 | 6 | ||
| 9 | - PImage top, bottom; // Two image to load | ||
| 10 | - int topWidth, bottomWidth; // The width of the top and bottom images | ||
| 11 | 7 | ||
| 8 | + // The next line is needed if running in JavaScript Mode with Processing.js | ||
| 9 | + /* @pjs preload="seedTop.jpg,seedBottom.jpg"; */ | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + HScrollbar hs1, hs2; // Two scrollbars | ||
| 13 | + PImage img1, img2; // Two image to load | ||
| 12 | 14 | ||
| 13 | 15 | void setup() { | |
| 14 | 16 | size(640, 360); | |
| 15 | 17 | noStroke(); | |
| 16 | - hs1 = new HScrollbar(0, height*0.33, width, 20, 3*5+1); | ||
| 17 | - hs2 = new HScrollbar(0, height*0.66, width, 20, 3*5+1); | ||
| 18 | - top = loadImage("seedTop.jpg"); | ||
| 19 | - topWidth = top.width; | ||
| 20 | - bottom = loadImage("seedBottom.jpg"); | ||
| 21 | - bottomWidth = bottom.width; | ||
| 18 | + | ||
| 19 | + hs1 = new HScrollbar(0, height/2-8, width, 16, 16); | ||
| 20 | + hs2 = new HScrollbar(0, height/2+8, width, 16, 16); | ||
| 21 | + | ||
| 22 | + // Load images | ||
| 23 | + img1 = loadImage("seedTop.jpg"); | ||
| 24 | + img2 = loadImage("seedBottom.jpg"); | ||
| 22 | 25 | } | |
| 23 | 26 | ||
| 24 | 27 | void draw() { | |
| 25 | 28 | background(255); | |
| 26 | 29 | ||
| 27 | - // Get the position of the top scrollbar | ||
| 28 | - // and convert to a value to display the top image | ||
| 29 | - float topPos = hs1.getPos()-width/2; | ||
| 30 | + // Get the position of the img1 scrollbar | ||
| 31 | + // and convert to a value to display the img1 image | ||
| 32 | + float img1Pos = hs1.getPos()-width/2; | ||
| 30 | 33 | fill(255); | |
| 31 | - image(top, width/2-topWidth/2 + topPos*2, 0); | ||
| 34 | + image(img1, width/2-img1.width/2 + img1Pos*1.5, 0); | ||
| 32 | 35 | ||
| 33 | - // Get the position of the bottom scrollbar | ||
| 34 | - // and convert to a value to display the bottom image | ||
| 35 | - float bottomPos = hs2.getPos()-width/2; | ||
| 36 | + // Get the position of the img2 scrollbar | ||
| 37 | + // and convert to a value to display the img2 image | ||
| 38 | + float img2Pos = hs2.getPos()-width/2; | ||
| 36 | 39 | fill(255); | |
| 37 | - image(bottom, width/2-bottomWidth/2 + bottomPos*2, height/2); | ||
| 40 | + image(img2, width/2-img2.width/2 + img2Pos*1.5, height/2); | ||
| 38 | 41 | ||
| 39 | 42 | hs1.update(); | |
| 40 | 43 | hs2.update(); | |
| 41 | 44 | hs1.display(); | |
| 42 | 45 | hs2.display(); | |
| 46 | + | ||
| 47 | + stroke(0); | ||
| 48 | + line(0, height/2, width, height/2); | ||
| 43 | 49 | } | |
| 44 | 50 | ||
| 45 | 51 | ||
@@ -93,14 +99,15 @@ class HScrollbar { | |||
| 93 | 99 | ||
| 94 | 100 | boolean overEvent() { | |
| 95 | 101 | if(mouseX > xpos && mouseX < xpos+swidth && | |
| 96 | - mouseY > ypos && mouseY < ypos+sheight) { | ||
| 102 | + mouseY > ypos && mouseY < ypos+sheight) { | ||
| 97 | 103 | return true; | |
| 98 | 104 | } else { | |
| 99 | 105 | return false; | |
| 100 | 106 | } | |
| 101 | 107 | } | |
| 102 | 108 | ||
| 103 | 109 | void display() { | |
| 110 | + noStroke(); | ||
| 104 | 111 | fill(204); | |
| 105 | 112 | rect(xpos, ypos, swidth, sheight); | |
| 106 | 113 | if(over || locked) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments