-
-
Save JeffersGlass/460b0f6c282c25e2d26dbf067f33a2ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SLIDER | |
float slider_width = 50; | |
float slider_height = 10; | |
float posx, posy; | |
boolean over = false; | |
boolean locked = false; | |
float xoff; | |
float fundo; | |
int WIDTH = 1000; | |
int HEIGHT = 500; | |
void setup() { | |
size(1000, 500, P2D); | |
posx = 0;//width/2; | |
posy = height/2; | |
rectMode(CENTER); | |
line (posx, posy, posx+100, posy); | |
} | |
void draw() { | |
fundo = posx; | |
background(200); | |
line (0, posy, WIDTH, posy); | |
println (posx); | |
if (dist(mouseX, mouseY, posx, posy) < slider_height) { | |
fill(200); | |
over = true; | |
} | |
else { | |
fill(255); | |
over = false; | |
} | |
rect(posx, posy, slider_width, slider_height); | |
textSize(100); | |
fill(255, 0, 0); | |
text(posx, 10, 100); | |
fill(0,255,0); | |
text(decToHexa(int(posx)), 10, 340); | |
text(decToBin(int(posx)), 10, 440); | |
} | |
void mousePressed() { | |
if (over) { | |
locked = true; | |
xoff = mouseX-posx; | |
} | |
} | |
void mouseDragged() { | |
if (locked) { | |
posx = mouseX-xoff; | |
} | |
} | |
void mouseReleased() { | |
locked = false; | |
} | |
void keyPressed() { | |
if (key == CODED) { | |
if (keyCode == RIGHT) { | |
posx += 1; | |
} else if (keyCode == LEFT) { | |
posx -= 1; | |
} | |
} | |
} | |
String decToHexa(int n) | |
{ | |
// char array to store hexadecimal number | |
char[] hexaDeciNum = new char[100]; | |
// counter for hexadecimal number array | |
int i = 0; | |
while(n!=0) | |
{ | |
// temporary variable to store remainder | |
int temp = 0; | |
// storing remainder in temp variable. | |
temp = n % 16; | |
// check if temp < 10 | |
if(temp < 10) | |
{ | |
hexaDeciNum[i] = char(temp + 48); | |
i++; | |
} | |
else | |
{ | |
hexaDeciNum[i] = char(temp + 55); | |
i++; | |
} | |
n = n/16; | |
} | |
String returnString = "0x"; | |
// printing hexadecimal number array in reverse order | |
for(int j=i-1; j>=0; j--) { | |
returnString = returnString + hexaDeciNum[j]; | |
} | |
return returnString; | |
} | |
String decToBin(int n) | |
{ | |
// char array to store hexadecimal number | |
char[] hexaDeciNum = new char[100]; | |
// counter for hexadecimal number array | |
int i = 0; | |
while(n!=0) | |
{ | |
// temporary variable to store remainder | |
int temp = 0; | |
// storing remainder in temp variable. | |
temp = n % 2; | |
// check if temp < 10 | |
if(temp < 2) | |
{ | |
hexaDeciNum[i] = char(temp + 48); | |
i++; | |
} | |
else | |
{ | |
hexaDeciNum[i] = char(temp + 55); | |
i++; | |
} | |
n = n/2; | |
} | |
String returnString = "b"; | |
// printing hexadecimal number array in reverse order | |
for(int j=i-1; j>=0; j--) { | |
returnString = returnString + hexaDeciNum[j]; | |
} | |
return returnString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment