mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Constrain.
|
||||
*
|
||||
* Move the mouse across the screen to move the circle.
|
||||
* The program constrains the circle to its box.
|
||||
*
|
||||
* Updated 27 February 2010 to handle changes in size().
|
||||
*/
|
||||
|
||||
float mx;
|
||||
float my;
|
||||
float easing = 0.05;
|
||||
int radius = 24;
|
||||
int edge = 56;
|
||||
int inner = edge + radius;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
smooth();
|
||||
ellipseMode(RADIUS);
|
||||
rectMode(CORNERS);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(51);
|
||||
|
||||
if (abs(mouseX - mx) > 0.1) {
|
||||
mx = mx + (mouseX - mx) * easing;
|
||||
}
|
||||
if (abs(mouseY - my) > 0.1) {
|
||||
my = my + (mouseY- my) * easing;
|
||||
}
|
||||
|
||||
mx = constrain(mx, inner, width - inner);
|
||||
my = constrain(my, inner, height - inner);
|
||||
fill(76);
|
||||
rect(edge, edge, width-edge, height-edge);
|
||||
fill(255);
|
||||
ellipse(mx, my, radius, radius);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import processing.core.*;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Constrain extends PApplet {
|
||||
|
||||
/**
|
||||
* Constrain.
|
||||
*
|
||||
* Move the mouse across the screen to move the circle.
|
||||
* The program constrains the circle to its box.
|
||||
*/
|
||||
|
||||
float mx;
|
||||
float my;
|
||||
float easing = 0.05f;
|
||||
float esize = 25.0f;
|
||||
int box = 30;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
smooth();
|
||||
ellipseMode(CENTER_RADIUS);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(51);
|
||||
|
||||
if(abs(mouseX - mx) > 0.1f) {
|
||||
mx = mx + (mouseX - mx) * easing;
|
||||
}
|
||||
if(abs(mouseY - my) > 0.1f) {
|
||||
my = my + (mouseY- my) * easing;
|
||||
}
|
||||
|
||||
float distance = esize * 2;
|
||||
mx = constrain(mx, box+distance, width-box-distance);
|
||||
my = constrain(my, box+distance, height-box-distance);
|
||||
fill(76);
|
||||
rect(box+esize, box+esize, box*3, box*3);
|
||||
fill(255);
|
||||
ellipse(mx, my, esize, esize);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Constrain" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Constrain.
|
||||
*
|
||||
* Move the mouse across the screen to move the circle.
|
||||
* The program constrains the circle to its box.
|
||||
*/
|
||||
|
||||
float mx;
|
||||
float my;
|
||||
float easing = 0.05;
|
||||
float esize = 25.0;
|
||||
int box = 30;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
smooth();
|
||||
ellipseMode(CENTER_RADIUS);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(51);
|
||||
|
||||
if(abs(mouseX - mx) > 0.1) {
|
||||
mx = mx + (mouseX - mx) * easing;
|
||||
}
|
||||
if(abs(mouseY - my) > 0.1) {
|
||||
my = my + (mouseY- my) * easing;
|
||||
}
|
||||
|
||||
float distance = esize * 2;
|
||||
mx = constrain(mx, box+distance, width-box-distance);
|
||||
my = constrain(my, box+distance, height-box-distance);
|
||||
fill(76);
|
||||
rect(box+esize, box+esize, box*3, box*3);
|
||||
fill(255);
|
||||
ellipse(mx, my, esize, esize);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Reference in New Issue
Block a user