mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
Removing Topics from SVN
This commit is contained in:
@@ -1,100 +0,0 @@
|
||||
/**
|
||||
* Button.
|
||||
*
|
||||
* Click on one of the colored squares in the
|
||||
* center of the image to change the color of
|
||||
* the background.
|
||||
*/
|
||||
|
||||
int rectX, rectY; // Position of square button
|
||||
int circleX, circleY; // Position of circle button
|
||||
int rectSize = 50; // Diameter of rect
|
||||
int circleSize = 53; // Diameter of circle
|
||||
color rectColor, circleColor, baseColor;
|
||||
color rectHighlight, circleHighlight;
|
||||
color currentColor;
|
||||
boolean rectOver = false;
|
||||
boolean circleOver = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
rectColor = color(0);
|
||||
rectHighlight = color(51);
|
||||
circleColor = color(255);
|
||||
circleHighlight = color(204);
|
||||
baseColor = color(102);
|
||||
currentColor = baseColor;
|
||||
circleX = width/2+circleSize/2+10;
|
||||
circleY = height/2;
|
||||
rectX = width/2-rectSize-10;
|
||||
rectY = height/2-rectSize/2;
|
||||
ellipseMode(CENTER);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
update(mouseX, mouseY);
|
||||
background(currentColor);
|
||||
|
||||
if(rectOver) {
|
||||
fill(rectHighlight);
|
||||
} else {
|
||||
fill(rectColor);
|
||||
}
|
||||
stroke(255);
|
||||
rect(rectX, rectY, rectSize, rectSize);
|
||||
|
||||
if(circleOver) {
|
||||
fill(circleHighlight);
|
||||
} else {
|
||||
fill(circleColor);
|
||||
}
|
||||
stroke(0);
|
||||
ellipse(circleX, circleY, circleSize, circleSize);
|
||||
}
|
||||
|
||||
void update(int x, int y)
|
||||
{
|
||||
if( overCircle(circleX, circleY, circleSize) ) {
|
||||
circleOver = true;
|
||||
rectOver = false;
|
||||
} else if ( overRect(rectX, rectY, rectSize, rectSize) ) {
|
||||
rectOver = true;
|
||||
circleOver = false;
|
||||
} else {
|
||||
circleOver = rectOver = false;
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressed()
|
||||
{
|
||||
if(circleOver) {
|
||||
currentColor = circleColor;
|
||||
}
|
||||
if(rectOver) {
|
||||
currentColor = rectColor;
|
||||
}
|
||||
}
|
||||
|
||||
boolean overRect(int x, int y, int width, int height)
|
||||
{
|
||||
if (mouseX >= x && mouseX <= x+width &&
|
||||
mouseY >= y && mouseY <= y+height) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean overCircle(int x, int y, int diameter)
|
||||
{
|
||||
float disX = x - mouseX;
|
||||
float disY = y - mouseY;
|
||||
if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
/**
|
||||
* Buttons.
|
||||
*
|
||||
* Click on one of the shapes to change
|
||||
* the background color. This example
|
||||
* demonstates a class for buttons.
|
||||
*/
|
||||
|
||||
color currentcolor;
|
||||
|
||||
CircleButton circle1, circle2, circle3;
|
||||
RectButton rect1, rect2;
|
||||
|
||||
boolean locked = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
|
||||
color baseColor = color(102);
|
||||
currentcolor = baseColor;
|
||||
|
||||
// Define and create circle button
|
||||
color buttoncolor = color(204);
|
||||
color highlight = color(153);
|
||||
ellipseMode(CENTER);
|
||||
circle1 = new CircleButton(30, 100, 100, buttoncolor, highlight);
|
||||
|
||||
// Define and create circle button
|
||||
buttoncolor = color(204);
|
||||
highlight = color(153);
|
||||
circle2 = new CircleButton(130, 110, 24, buttoncolor, highlight);
|
||||
|
||||
// Define and create circle button
|
||||
buttoncolor = color(153);
|
||||
highlight = color(102);
|
||||
circle3 = new CircleButton(130, 140, 24, buttoncolor, highlight);
|
||||
|
||||
// Define and create rectangle button
|
||||
buttoncolor = color(102);
|
||||
highlight = color(51);
|
||||
rect1 = new RectButton(150, 20, 100, buttoncolor, highlight);
|
||||
|
||||
// Define and create rectangle button
|
||||
buttoncolor = color(51);
|
||||
highlight = color(0);
|
||||
rect2 = new RectButton(90, 20, 50, buttoncolor, highlight);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(currentcolor);
|
||||
stroke(255);
|
||||
update(mouseX, mouseY);
|
||||
circle1.display();
|
||||
circle2.display();
|
||||
circle3.display();
|
||||
rect1.display();
|
||||
rect2.display();
|
||||
}
|
||||
|
||||
void update(int x, int y)
|
||||
{
|
||||
if(locked == false) {
|
||||
circle1.update();
|
||||
circle2.update();
|
||||
circle3.update();
|
||||
rect1.update();
|
||||
rect2.update();
|
||||
}
|
||||
else {
|
||||
locked = false;
|
||||
}
|
||||
|
||||
if(mousePressed) {
|
||||
if(circle1.pressed()) {
|
||||
currentcolor = circle1.basecolor;
|
||||
}
|
||||
else if(circle2.pressed()) {
|
||||
currentcolor = circle2.basecolor;
|
||||
}
|
||||
else if(circle3.pressed()) {
|
||||
currentcolor = circle3.basecolor;
|
||||
}
|
||||
else if(rect1.pressed()) {
|
||||
currentcolor = rect1.basecolor;
|
||||
}
|
||||
else if(rect2.pressed()) {
|
||||
currentcolor = rect2.basecolor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Button
|
||||
{
|
||||
int x, y;
|
||||
int size;
|
||||
color basecolor, highlightcolor;
|
||||
color currentcolor;
|
||||
boolean over = false;
|
||||
boolean pressed = false;
|
||||
|
||||
void update()
|
||||
{
|
||||
if(over()) {
|
||||
currentcolor = highlightcolor;
|
||||
}
|
||||
else {
|
||||
currentcolor = basecolor;
|
||||
}
|
||||
}
|
||||
|
||||
boolean pressed()
|
||||
{
|
||||
if(over) {
|
||||
locked = true;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
locked = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean over()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean overRect(int x, int y, int width, int height)
|
||||
{
|
||||
if (mouseX >= x && mouseX <= x+width &&
|
||||
mouseY >= y && mouseY <= y+height) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean overCircle(int x, int y, int diameter)
|
||||
{
|
||||
float disX = x - mouseX;
|
||||
float disY = y - mouseY;
|
||||
if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CircleButton extends Button
|
||||
{
|
||||
CircleButton(int ix, int iy, int isize, color icolor, color ihighlight)
|
||||
{
|
||||
x = ix;
|
||||
y = iy;
|
||||
size = isize;
|
||||
basecolor = icolor;
|
||||
highlightcolor = ihighlight;
|
||||
currentcolor = basecolor;
|
||||
}
|
||||
|
||||
boolean over()
|
||||
{
|
||||
if( overCircle(x, y, size) ) {
|
||||
over = true;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
over = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void display()
|
||||
{
|
||||
stroke(255);
|
||||
fill(currentcolor);
|
||||
ellipse(x, y, size, size);
|
||||
}
|
||||
}
|
||||
|
||||
class RectButton extends Button
|
||||
{
|
||||
RectButton(int ix, int iy, int isize, color icolor, color ihighlight)
|
||||
{
|
||||
x = ix;
|
||||
y = iy;
|
||||
size = isize;
|
||||
basecolor = icolor;
|
||||
highlightcolor = ihighlight;
|
||||
currentcolor = basecolor;
|
||||
}
|
||||
|
||||
boolean over()
|
||||
{
|
||||
if( overRect(x, y, size, size) ) {
|
||||
over = true;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
over = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void display()
|
||||
{
|
||||
stroke(255);
|
||||
fill(currentcolor);
|
||||
rect(x, y, size, size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
/**
|
||||
* Handles.
|
||||
*
|
||||
* Click and drag the white boxes to change their position.
|
||||
*/
|
||||
|
||||
Handle[] handles;
|
||||
int num;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
num = height/15;
|
||||
handles = new Handle[num];
|
||||
int hsize = 10;
|
||||
for(int i=0; i<num; i++) {
|
||||
handles[i] = new Handle(width/2, 10+i*15, 50-hsize/2, 10, handles);
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(153);
|
||||
|
||||
for(int i=0; i<num; i++) {
|
||||
handles[i].update();
|
||||
handles[i].display();
|
||||
}
|
||||
|
||||
fill(0);
|
||||
rect(0, 0, width/2, height);
|
||||
}
|
||||
|
||||
void mouseReleased()
|
||||
{
|
||||
for(int i=0; i<num; i++) {
|
||||
handles[i].release();
|
||||
}
|
||||
}
|
||||
|
||||
class Handle
|
||||
{
|
||||
int x, y;
|
||||
int boxx, boxy;
|
||||
int length;
|
||||
int size;
|
||||
boolean over;
|
||||
boolean press;
|
||||
boolean locked = false;
|
||||
boolean otherslocked = false;
|
||||
Handle[] others;
|
||||
|
||||
Handle(int ix, int iy, int il, int is, Handle[] o)
|
||||
{
|
||||
x = ix;
|
||||
y = iy;
|
||||
length = il;
|
||||
size = is;
|
||||
boxx = x+length - size/2;
|
||||
boxy = y - size/2;
|
||||
others = o;
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
boxx = x+length;
|
||||
boxy = y - size/2;
|
||||
|
||||
for(int i=0; i<others.length; i++) {
|
||||
if(others[i].locked == true) {
|
||||
otherslocked = true;
|
||||
break;
|
||||
} else {
|
||||
otherslocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(otherslocked == false) {
|
||||
over();
|
||||
press();
|
||||
}
|
||||
|
||||
if(press) {
|
||||
length = lock(mouseX-width/2-size/2, 0, width/2-size-1);
|
||||
}
|
||||
}
|
||||
|
||||
void over()
|
||||
{
|
||||
if(overRect(boxx, boxy, size, size)) {
|
||||
over = true;
|
||||
} else {
|
||||
over = false;
|
||||
}
|
||||
}
|
||||
|
||||
void press()
|
||||
{
|
||||
if(over && mousePressed || locked) {
|
||||
press = true;
|
||||
locked = true;
|
||||
} else {
|
||||
press = false;
|
||||
}
|
||||
}
|
||||
|
||||
void release()
|
||||
{
|
||||
locked = false;
|
||||
}
|
||||
|
||||
void display()
|
||||
{
|
||||
line(x, y, x+length, y);
|
||||
fill(255);
|
||||
stroke(0);
|
||||
rect(boxx, boxy, size, size);
|
||||
if(over || press) {
|
||||
line(boxx, boxy, boxx+size, boxy+size);
|
||||
line(boxx, boxy+size, boxx+size, boxy);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
boolean overRect(int x, int y, int width, int height)
|
||||
{
|
||||
if (mouseX >= x && mouseX <= x+width &&
|
||||
mouseY >= y && mouseY <= y+height) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int lock(int val, int minv, int maxv)
|
||||
{
|
||||
return min(max(val, minv), maxv);
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/**
|
||||
* Image button.
|
||||
*
|
||||
* Loading images and using them to create a button.
|
||||
*/
|
||||
|
||||
|
||||
ImageButtons button;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
background(102, 102, 102);
|
||||
|
||||
// Define and create image button
|
||||
PImage b = loadImage("base.gif");
|
||||
PImage r = loadImage("roll.gif");
|
||||
PImage d = loadImage("down.gif");
|
||||
int x = width/2 - b.width/2;
|
||||
int y = height/2 - b.height/2;
|
||||
int w = b.width;
|
||||
int h = b.height;
|
||||
button = new ImageButtons(x, y, w, h, b, r, d);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
button.update();
|
||||
button.display();
|
||||
}
|
||||
|
||||
class Button
|
||||
{
|
||||
int x, y;
|
||||
int w, h;
|
||||
color basecolor, highlightcolor;
|
||||
color currentcolor;
|
||||
boolean over = false;
|
||||
boolean pressed = false;
|
||||
|
||||
void pressed() {
|
||||
if(over && mousePressed) {
|
||||
pressed = true;
|
||||
} else {
|
||||
pressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean overRect(int x, int y, int width, int height) {
|
||||
if (mouseX >= x && mouseX <= x+width &&
|
||||
mouseY >= y && mouseY <= y+height) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ImageButtons extends Button
|
||||
{
|
||||
PImage base;
|
||||
PImage roll;
|
||||
PImage down;
|
||||
PImage currentimage;
|
||||
|
||||
ImageButtons(int ix, int iy, int iw, int ih, PImage ibase, PImage iroll, PImage idown)
|
||||
{
|
||||
x = ix;
|
||||
y = iy;
|
||||
w = iw;
|
||||
h = ih;
|
||||
base = ibase;
|
||||
roll = iroll;
|
||||
down = idown;
|
||||
currentimage = base;
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
over();
|
||||
pressed();
|
||||
if(pressed) {
|
||||
currentimage = down;
|
||||
} else if (over){
|
||||
currentimage = roll;
|
||||
} else {
|
||||
currentimage = base;
|
||||
}
|
||||
}
|
||||
|
||||
void over()
|
||||
{
|
||||
if( overRect(x, y, w, h) ) {
|
||||
over = true;
|
||||
} else {
|
||||
over = false;
|
||||
}
|
||||
}
|
||||
|
||||
void display()
|
||||
{
|
||||
image(currentimage, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 774 B |
Binary file not shown.
|
Before Width: | Height: | Size: 656 B |
Binary file not shown.
|
Before Width: | Height: | Size: 774 B |
@@ -1,88 +0,0 @@
|
||||
/**
|
||||
* Rollover.
|
||||
*
|
||||
* Roll over the colored squares in the center of the image
|
||||
* to change the color of the outside rectangle.
|
||||
*/
|
||||
|
||||
|
||||
int rectX, rectY; // Position of square button
|
||||
int circleX, circleY; // Position of circle button
|
||||
int rectSize = 50; // Diameter of rect
|
||||
int circleSize = 53; // Diameter of circle
|
||||
|
||||
color rectColor;
|
||||
color circleColor;
|
||||
color baseColor;
|
||||
|
||||
boolean rectOver = false;
|
||||
boolean circleOver = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
rectColor = color(0);
|
||||
circleColor = color(255);
|
||||
baseColor = color(102);
|
||||
circleX = width/2+circleSize/2+10;
|
||||
circleY = height/2;
|
||||
rectX = width/2-rectSize-10;
|
||||
rectY = height/2-rectSize/2;
|
||||
ellipseMode(CENTER);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
update(mouseX, mouseY);
|
||||
|
||||
noStroke();
|
||||
if (rectOver) {
|
||||
background(rectColor);
|
||||
} else if (circleOver) {
|
||||
background(circleColor);
|
||||
} else {
|
||||
background(baseColor);
|
||||
}
|
||||
|
||||
stroke(255);
|
||||
fill(rectColor);
|
||||
rect(rectX, rectY, rectSize, rectSize);
|
||||
stroke(0);
|
||||
fill(circleColor);
|
||||
ellipse(circleX, circleY, circleSize, circleSize);
|
||||
}
|
||||
|
||||
void update(int x, int y)
|
||||
{
|
||||
if( overCircle(circleX, circleY, circleSize) ) {
|
||||
circleOver = true;
|
||||
rectOver = false;
|
||||
} else if ( overRect(rectX, rectY, rectSize, rectSize) ) {
|
||||
rectOver = true;
|
||||
circleOver = false;
|
||||
} else {
|
||||
circleOver = rectOver = false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean overRect(int x, int y, int width, int height)
|
||||
{
|
||||
if (mouseX >= x && mouseX <= x+width &&
|
||||
mouseY >= y && mouseY <= y+height) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean overCircle(int x, int y, int diameter)
|
||||
{
|
||||
float disX = x - mouseX;
|
||||
float disY = y - mouseY;
|
||||
if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/**
|
||||
* Scrollbar.
|
||||
*
|
||||
* Move the scrollbars left and right to change the positions of the images.
|
||||
*/
|
||||
|
||||
HScrollbar hs1, hs2;
|
||||
|
||||
PImage top, bottom; // Two image to load
|
||||
int topWidth, bottomWidth; // The width of the top and bottom images
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
hs1 = new HScrollbar(0, 20, width, 10, 3*5+1);
|
||||
hs2 = new HScrollbar(0, height-20, width, 10, 3*5+1);
|
||||
top = loadImage("seedTop.jpg");
|
||||
topWidth = top.width;
|
||||
bottom = loadImage("seedBottom.jpg");
|
||||
bottomWidth = bottom.width;
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(255);
|
||||
|
||||
// Get the position of the top scrollbar
|
||||
// and convert to a value to display the top image
|
||||
float topPos = hs1.getPos()-width/2;
|
||||
fill(255);
|
||||
image(top, width/2-topWidth/2 + topPos*2, 0);
|
||||
|
||||
// Get the position of the bottom scrollbar
|
||||
// and convert to a value to display the bottom image
|
||||
float bottomPos = hs2.getPos()-width/2;
|
||||
fill(255);
|
||||
image(bottom, width/2-bottomWidth/2 + bottomPos*2, height/2);
|
||||
|
||||
hs1.update();
|
||||
hs2.update();
|
||||
hs1.display();
|
||||
hs2.display();
|
||||
}
|
||||
|
||||
|
||||
class HScrollbar
|
||||
{
|
||||
int swidth, sheight; // width and height of bar
|
||||
int xpos, ypos; // x and y position of bar
|
||||
float spos, newspos; // x position of slider
|
||||
int sposMin, sposMax; // max and min values of slider
|
||||
int loose; // how loose/heavy
|
||||
boolean over; // is the mouse over the slider?
|
||||
boolean locked;
|
||||
float ratio;
|
||||
|
||||
HScrollbar (int xp, int yp, int sw, int sh, int l) {
|
||||
swidth = sw;
|
||||
sheight = sh;
|
||||
int widthtoheight = sw - sh;
|
||||
ratio = (float)sw / (float)widthtoheight;
|
||||
xpos = xp;
|
||||
ypos = yp-sheight/2;
|
||||
spos = xpos + swidth/2 - sheight/2;
|
||||
newspos = spos;
|
||||
sposMin = xpos;
|
||||
sposMax = xpos + swidth - sheight;
|
||||
loose = l;
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(over()) {
|
||||
over = true;
|
||||
} else {
|
||||
over = false;
|
||||
}
|
||||
if(mousePressed && over) {
|
||||
locked = true;
|
||||
}
|
||||
if(!mousePressed) {
|
||||
locked = false;
|
||||
}
|
||||
if(locked) {
|
||||
newspos = constrain(mouseX-sheight/2, sposMin, sposMax);
|
||||
}
|
||||
if(abs(newspos - spos) > 1) {
|
||||
spos = spos + (newspos-spos)/loose;
|
||||
}
|
||||
}
|
||||
|
||||
int constrain(int val, int minv, int maxv) {
|
||||
return min(max(val, minv), maxv);
|
||||
}
|
||||
|
||||
boolean over() {
|
||||
if(mouseX > xpos && mouseX < xpos+swidth &&
|
||||
mouseY > ypos && mouseY < ypos+sheight) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void display() {
|
||||
fill(255);
|
||||
rect(xpos, ypos, swidth, sheight);
|
||||
if(over || locked) {
|
||||
fill(153, 102, 0);
|
||||
} else {
|
||||
fill(102, 102, 102);
|
||||
}
|
||||
rect(spos, ypos, sheight, sheight);
|
||||
}
|
||||
|
||||
float getPos() {
|
||||
// Convert spos to be values between
|
||||
// 0 and the total width of the scrollbar
|
||||
return spos * ratio;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user