Created
February 5, 2012 22:46
-
-
Save tatsuro-ueda/1748263 to your computer and use it in GitHub Desktop.
Processing Examples Basic Web
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
size(200, 200); | |
PImage img1; | |
img1 = loadImage("http://processing.org/img/processing_cover.gif"); | |
if (img1 != null) { | |
image(img1, 0, 0); | |
} |
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
// 左のボタンは既存のブラウザウィンドウにURLのページを表示 | |
// 右のボタンは新規のブラウザウィンドウにURLのページを表示 | |
boolean overLeftButton = false; | |
boolean overRightButton = false; | |
void setup() { | |
size(200, 200); | |
} | |
void draw() { | |
background(204); | |
// 左のボタン | |
// マウスカーソルを重ねると白くなる | |
if (overLeftButton == true) { | |
fill(255); | |
} else { | |
noFill(); | |
} | |
rect(20, 60, 75, 75); | |
rect(50, 90, 15, 15); | |
// 右のボタン | |
// マウスカーソルを重ねると白くなる | |
if (overRightButton == true) { | |
fill(255); | |
} else { | |
noFill(); | |
} | |
rect(105, 60, 75, 75); | |
line(135, 105, 155, 85); | |
line(140, 85, 155, 85); | |
line(155, 85, 155, 100); | |
} | |
// ボタンが押されたら | |
void mousePressed() { | |
if (overLeftButton) { | |
// 既存のブラウザウィンドウにリンクを表示 | |
link("http://www.processing.org"); | |
} else if (overRightButton) { | |
// 新規のブラウザウィンドウにリンクを表示 | |
link("http://www.processing.org", "_new"); | |
} | |
} | |
// マウスカーソルが動いたら | |
void mouseMoved() { | |
checkButtons(); | |
} | |
// マウスカーソルがドラッグされたら | |
void mouseDragged() { | |
checkButtons(); | |
} | |
void checkButtons() { | |
if (mouseX > 20 && mouseX < 95 && mouseY > 60 && mouseY < 135) { | |
overLeftButton = true; | |
} else if (mouseX > 105 && mouseX < 180 && mouseY > 60 && mouseY <135) { | |
overRightButton = true; | |
} else { | |
overLeftButton = overRightButton = false; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment