|
Button b1; |
|
Button b2; |
|
Button b3; |
|
void setup() { |
|
background(0); |
|
size(1600, 1600); |
|
b1= new Button("タイトル1", "リンク1"); |
|
b2= new Button("タイトル2", "リンク2"); |
|
b3= new Button("タイトル3", "リンク3"); |
|
} |
|
void draw() { |
|
b1.open(); |
|
b2.open(); |
|
b3.open(); |
|
b1.render(); |
|
b2.render(); |
|
b3.render(); |
|
} |
|
|
|
class Button { |
|
float x, y, vX, vY, r; |
|
color c; |
|
String title, web; |
|
Button(String title, String web) { |
|
x = random(width/4, width*3/4); |
|
y= random(height/4, height*3/4); |
|
r = random(width / 3, width/2); |
|
c = color(random(100, 200), random(100, 200), 10); |
|
this.title = title; |
|
this.web = web; |
|
} |
|
void open() { |
|
if (dist(x, y, mouseX, mouseY) < r/2) { |
|
if (mousePressed) { |
|
link(web); |
|
x = 0; |
|
y = 0; |
|
r = 0; |
|
} |
|
|
|
vX = (mouseX - x)/dist(x, y, mouseX, mouseY)*2; |
|
vY = (mouseY - y)/dist(x, y, mouseX, mouseY)*2; |
|
|
|
if (r >10) { |
|
r -= 3; |
|
} |
|
} else { |
|
vX = 0; |
|
vY = 0; |
|
if (mousePressed) { |
|
x = random(width/4, width*3/4); |
|
y = random(height/4, height*3/4); |
|
r = random(width/3, width*2/3); |
|
} |
|
} |
|
} |
|
void render() { |
|
x += vX; |
|
y += vY; |
|
fill(red(c), green(c), blue(c), 10); |
|
ellipse(x, y, r, r); |
|
fill(255-red(c), 255-green(c), 255-blue(c)); |
|
textSize(r/4); |
|
text(title, x - title.length()*r/8, y); |
|
} |
|
} |