mirror of
https://github.com/processing/processing4.git
synced 2026-04-19 10:49:28 +02:00
This commit is contained in:
39
java/examples/Basics/Transform/Arm/Arm.pde
Normal file
39
java/examples/Basics/Transform/Arm/Arm.pde
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Arm.
|
||||
*
|
||||
* The angle of each segment is controlled with the mouseX and
|
||||
* mouseY position. The transformations applied to the first segment
|
||||
* are also applied to the second segment because they are inside
|
||||
* the same pushMatrix() and popMatrix() group.
|
||||
*/
|
||||
|
||||
float x = 50;
|
||||
float y = 100;
|
||||
float angle1 = 0.0;
|
||||
float angle2 = 0.0;
|
||||
float segLength = 50;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
smooth();
|
||||
strokeWeight(20.0);
|
||||
stroke(0, 100);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(226);
|
||||
|
||||
angle1 = (mouseX/float(width) - 0.5) * -PI;
|
||||
angle2 = (mouseY/float(height) - 0.5) * PI;
|
||||
|
||||
pushMatrix();
|
||||
segment(x, y, angle1);
|
||||
segment(segLength, 0, angle2);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void segment(float x, float y, float a) {
|
||||
translate(x, y);
|
||||
rotate(a);
|
||||
line(0, 0, segLength, 0);
|
||||
}
|
||||
59
java/examples/Basics/Transform/Arm/applet/Arm.java
Normal file
59
java/examples/Basics/Transform/Arm/applet/Arm.java
Normal file
@@ -0,0 +1,59 @@
|
||||
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 Arm extends PApplet {
|
||||
|
||||
/**
|
||||
* Arm.
|
||||
*
|
||||
* The angle of each segment is controlled with the mouseX and
|
||||
* mouseY position. The transformations applied to the first segment
|
||||
* are also applied to the second segment because they are inside
|
||||
* the same pushMatrix() and popMatrix() group.
|
||||
*/
|
||||
|
||||
float x = 50;
|
||||
float y = 100;
|
||||
float angle1 = 0.0f;
|
||||
float angle2 = 0.0f;
|
||||
float segLength = 50;
|
||||
|
||||
public void setup() {
|
||||
size(200, 200);
|
||||
smooth();
|
||||
strokeWeight(20.0f);
|
||||
stroke(0, 100);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(226);
|
||||
|
||||
angle1 = (mouseX/PApplet.parseFloat(width) - 0.5f) * -PI;
|
||||
angle2 = (mouseY/PApplet.parseFloat(height) - 0.5f) * PI;
|
||||
|
||||
pushMatrix();
|
||||
segment(x, y, angle1);
|
||||
segment(segLength, 0, angle2);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
public void segment(float x, float y, float a) {
|
||||
translate(x, y);
|
||||
rotate(a);
|
||||
line(0, 0, segLength, 0);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Arm" });
|
||||
}
|
||||
}
|
||||
39
java/examples/Basics/Transform/Arm/applet/Arm.pde
Normal file
39
java/examples/Basics/Transform/Arm/applet/Arm.pde
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Arm.
|
||||
*
|
||||
* The angle of each segment is controlled with the mouseX and
|
||||
* mouseY position. The transformations applied to the first segment
|
||||
* are also applied to the second segment because they are inside
|
||||
* the same pushMatrix() and popMatrix() group.
|
||||
*/
|
||||
|
||||
float x = 50;
|
||||
float y = 100;
|
||||
float angle1 = 0.0;
|
||||
float angle2 = 0.0;
|
||||
float segLength = 50;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
smooth();
|
||||
strokeWeight(20.0);
|
||||
stroke(0, 100);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(226);
|
||||
|
||||
angle1 = (mouseX/float(width) - 0.5) * -PI;
|
||||
angle2 = (mouseY/float(height) - 0.5) * PI;
|
||||
|
||||
pushMatrix();
|
||||
segment(x, y, angle1);
|
||||
segment(segLength, 0, angle2);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void segment(float x, float y, float a) {
|
||||
translate(x, y);
|
||||
rotate(a);
|
||||
line(0, 0, segLength, 0);
|
||||
}
|
||||
BIN
java/examples/Basics/Transform/Arm/applet/loading.gif
Normal file
BIN
java/examples/Basics/Transform/Arm/applet/loading.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Reference in New Issue
Block a user