mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Examples mods for 2.0
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* TexturedCube
|
||||
* Texture Cube
|
||||
* by Dave Bollinger.
|
||||
*
|
||||
* Drag mouse to rotate cube. Demonstrates use of u/v coords in
|
||||
@@ -7,13 +7,15 @@
|
||||
* the P3D renderer as you can see, but they look great using OPENGL.
|
||||
*/
|
||||
|
||||
// @pjs preload must be used to preload media if the program is
|
||||
// running with Processing.js
|
||||
/* @pjs preload="berlin-1.jpg"; */
|
||||
|
||||
PImage tex;
|
||||
float rotx = PI/4;
|
||||
float roty = PI/4;
|
||||
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
tex = loadImage("berlin-1.jpg");
|
||||
textureMode(NORMALIZED);
|
||||
@@ -21,8 +23,7 @@ void setup()
|
||||
stroke(color(44,48,32));
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
void draw() {
|
||||
background(0);
|
||||
noStroke();
|
||||
translate(width/2.0, height/2.0, -100);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
/**
|
||||
* Texture 3.
|
||||
* Texture Cylinder.
|
||||
*
|
||||
* Load an image and draw it onto a cylinder and a quad.
|
||||
*/
|
||||
|
||||
// @pjs preload must be used to preload media if the program is
|
||||
// running with Processing.js
|
||||
/* @pjs preload="berlin-1.jpg"; */
|
||||
|
||||
int tubeRes = 32;
|
||||
float[] tubeX = new float[tubeRes];
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
/**
|
||||
* Texture 1.
|
||||
* Texture Quad.
|
||||
*
|
||||
* Load an image and draw it onto a quad. The texture() function sets
|
||||
* the texture image. The vertex() function maps the image to the geometry.
|
||||
*/
|
||||
|
||||
// @pjs preload must be used to preload media if the program is
|
||||
// running with Processing.js
|
||||
/* @pjs preload="berlin-1.jpg"; */
|
||||
|
||||
PImage img;
|
||||
|
||||
void setup() {
|
||||
@@ -21,8 +25,8 @@ void draw() {
|
||||
beginShape();
|
||||
texture(img);
|
||||
vertex(-100, -100, 0, 0, 0);
|
||||
vertex(100, -100, 0, 400, 0);
|
||||
vertex(100, 100, 0, 400, 400);
|
||||
vertex(-100, 100, 0, 0, 400);
|
||||
vertex(100, -100, 0, 300, 0);
|
||||
vertex(100, 100, 0, 300, 300);
|
||||
vertex(-100, 100, 0, 0, 300);
|
||||
endShape();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
/**
|
||||
* Texture 2.
|
||||
* Texture Triangle.
|
||||
*
|
||||
* Using a rectangular image to map a texture onto a triangle.
|
||||
*/
|
||||
|
||||
// @pjs preload must be used to preload media if the program is
|
||||
// running with Processing.js
|
||||
/* @pjs preload="berlin-1.jpg"; */
|
||||
|
||||
PImage img;
|
||||
|
||||
void setup() {
|
||||
@@ -14,12 +18,12 @@ void setup() {
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
translate(width/2, height/2, 0);
|
||||
rotateY(map(mouseX, 0, width, -PI, PI));
|
||||
beginShape();
|
||||
texture(img);
|
||||
vertex(-100, -100, 0, 0, 0);
|
||||
vertex(100, -40, 0, 400, 120);
|
||||
vertex(100, -40, 0, 300, 120);
|
||||
vertex(0, 100, 0, 200, 400);
|
||||
endShape();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user