mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
removing applet folders from svn
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
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 CompositeObjects extends PApplet {
|
||||
|
||||
/**
|
||||
* Composite Objects
|
||||
*
|
||||
* An object can include several other objects. Creating such composite objects
|
||||
* is a good way to use the principles of modularity and build higher levels of
|
||||
* abstraction within a program.
|
||||
*/
|
||||
|
||||
EggRing er1, er2;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
er1 = new EggRing(66, 132, 0.1f, 66);
|
||||
er2 = new EggRing(132, 180, 0.05f, 132);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(0);
|
||||
er1.transmit();
|
||||
er2.transmit();
|
||||
}
|
||||
|
||||
class EggRing
|
||||
{
|
||||
Egg ovoid;
|
||||
Ring circle = new Ring();
|
||||
EggRing(int x, int y, float t, float sp) {
|
||||
ovoid = new Egg(x, y, t, sp);
|
||||
circle.start(x, y - sp/2);
|
||||
}
|
||||
public void transmit() {
|
||||
ovoid.wobble();
|
||||
ovoid.display();
|
||||
circle.grow();
|
||||
circle.display();
|
||||
if (circle.on == false) {
|
||||
circle.on = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Egg {
|
||||
float x, y; // X-coordinate, y-coordinate
|
||||
float tilt; // Left and right angle offset
|
||||
float angle; // Used to define the tilt
|
||||
float scalar; // Height of the egg
|
||||
// Constructor
|
||||
Egg(int xpos, int ypos, float t, float s) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
tilt = t;
|
||||
scalar = s / 100.0f;
|
||||
}
|
||||
public void wobble() {
|
||||
tilt = cos(angle) / 8;
|
||||
angle += 0.1f;
|
||||
}
|
||||
public void display() {
|
||||
noStroke();
|
||||
fill(255);
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
rotate(tilt);
|
||||
scale(scalar);
|
||||
beginShape();
|
||||
vertex(0, -100);
|
||||
bezierVertex(25, -100, 40, -65, 40, -40);
|
||||
bezierVertex(40, -15, 25, 0, 0, 0);
|
||||
bezierVertex(-25, 0, -40, -15, -40, -40);
|
||||
bezierVertex(-40, -65, -25, -100, 0, -100);
|
||||
endShape();
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
class Ring {
|
||||
float x, y; // X-coordinate, y-coordinate
|
||||
float diameter; // Diameter of the ring
|
||||
boolean on = false; // Turns the display on and off
|
||||
public void start(float xpos, float ypos) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
on = true;
|
||||
diameter = 1;
|
||||
}
|
||||
public void grow() {
|
||||
if (on == true) {
|
||||
diameter += 0.5f;
|
||||
if (diameter > width*2) {
|
||||
diameter = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void display() {
|
||||
if (on == true) {
|
||||
noFill();
|
||||
strokeWeight(4);
|
||||
stroke(155, 153);
|
||||
ellipse(x, y, diameter, diameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "CompositeObjects" });
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/**
|
||||
* Composite Objects
|
||||
*
|
||||
* An object can include several other objects. Creating such composite objects
|
||||
* is a good way to use the principles of modularity and build higher levels of
|
||||
* abstraction within a program.
|
||||
*/
|
||||
|
||||
EggRing er1, er2;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
er1 = new EggRing(66, 132, 0.1, 66);
|
||||
er2 = new EggRing(132, 180, 0.05, 132);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
er1.transmit();
|
||||
er2.transmit();
|
||||
}
|
||||
|
||||
class EggRing
|
||||
{
|
||||
Egg ovoid;
|
||||
Ring circle = new Ring();
|
||||
EggRing(int x, int y, float t, float sp) {
|
||||
ovoid = new Egg(x, y, t, sp);
|
||||
circle.start(x, y - sp/2);
|
||||
}
|
||||
void transmit() {
|
||||
ovoid.wobble();
|
||||
ovoid.display();
|
||||
circle.grow();
|
||||
circle.display();
|
||||
if (circle.on == false) {
|
||||
circle.on = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Egg {
|
||||
float x, y; // X-coordinate, y-coordinate
|
||||
float tilt; // Left and right angle offset
|
||||
float angle; // Used to define the tilt
|
||||
float scalar; // Height of the egg
|
||||
// Constructor
|
||||
Egg(int xpos, int ypos, float t, float s) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
tilt = t;
|
||||
scalar = s / 100.0;
|
||||
}
|
||||
void wobble() {
|
||||
tilt = cos(angle) / 8;
|
||||
angle += 0.1;
|
||||
}
|
||||
void display() {
|
||||
noStroke();
|
||||
fill(255);
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
rotate(tilt);
|
||||
scale(scalar);
|
||||
beginShape();
|
||||
vertex(0, -100);
|
||||
bezierVertex(25, -100, 40, -65, 40, -40);
|
||||
bezierVertex(40, -15, 25, 0, 0, 0);
|
||||
bezierVertex(-25, 0, -40, -15, -40, -40);
|
||||
bezierVertex(-40, -65, -25, -100, 0, -100);
|
||||
endShape();
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
class Ring {
|
||||
float x, y; // X-coordinate, y-coordinate
|
||||
float diameter; // Diameter of the ring
|
||||
boolean on = false; // Turns the display on and off
|
||||
void start(float xpos, float ypos) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
on = true;
|
||||
diameter = 1;
|
||||
}
|
||||
void grow() {
|
||||
if (on == true) {
|
||||
diameter += 0.5;
|
||||
if (diameter > width*2) {
|
||||
diameter = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
void display() {
|
||||
if (on == true) {
|
||||
noFill();
|
||||
strokeWeight(4);
|
||||
stroke(155, 153);
|
||||
ellipse(x, y, diameter, diameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
@@ -1,98 +0,0 @@
|
||||
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 Inheritance extends PApplet {
|
||||
|
||||
/**
|
||||
* Inheritance
|
||||
*
|
||||
* A class can be defined using another class as a foundation. In object-oriented
|
||||
* programming terminology, one class can inherit fi elds and methods from another.
|
||||
* An object that inherits from another is called a subclass, and the object it
|
||||
* inherits from is called a superclass. A subclass extends the superclass.
|
||||
*/
|
||||
|
||||
SpinSpots spots;
|
||||
SpinArm arm;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
arm = new SpinArm(width/2, height/2, 0.01f);
|
||||
spots = new SpinSpots(width/2, height/2, -0.02f, 33.0f);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(204);
|
||||
arm.update();
|
||||
arm.display();
|
||||
spots.update();
|
||||
spots.display();
|
||||
}
|
||||
|
||||
class Spin
|
||||
{
|
||||
float x, y, speed;
|
||||
float angle = 0.0f;
|
||||
Spin(float xpos, float ypos, float s) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
speed = s;
|
||||
}
|
||||
public void update() {
|
||||
angle += speed;
|
||||
}
|
||||
}
|
||||
|
||||
class SpinArm extends Spin
|
||||
{
|
||||
SpinArm(float x, float y, float s) {
|
||||
super(x, y, s);
|
||||
}
|
||||
public void display() {
|
||||
strokeWeight(1);
|
||||
stroke(0);
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
angle += speed;
|
||||
rotate(angle);
|
||||
line(0, 0, 66, 0);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
class SpinSpots extends Spin
|
||||
{
|
||||
float dim;
|
||||
SpinSpots(float x, float y, float s, float d) {
|
||||
super(x, y, s);
|
||||
dim = d;
|
||||
}
|
||||
public void display() {
|
||||
noStroke();
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
angle += speed;
|
||||
rotate(angle);
|
||||
ellipse(-dim/2, 0, dim, dim);
|
||||
ellipse(dim/2, 0, dim, dim);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Inheritance" });
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/**
|
||||
* Inheritance
|
||||
*
|
||||
* A class can be defined using another class as a foundation. In object-oriented
|
||||
* programming terminology, one class can inherit fi elds and methods from another.
|
||||
* An object that inherits from another is called a subclass, and the object it
|
||||
* inherits from is called a superclass. A subclass extends the superclass.
|
||||
*/
|
||||
|
||||
SpinSpots spots;
|
||||
SpinArm arm;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
arm = new SpinArm(width/2, height/2, 0.01);
|
||||
spots = new SpinSpots(width/2, height/2, -0.02, 33.0);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(204);
|
||||
arm.update();
|
||||
arm.display();
|
||||
spots.update();
|
||||
spots.display();
|
||||
}
|
||||
|
||||
class Spin
|
||||
{
|
||||
float x, y, speed;
|
||||
float angle = 0.0;
|
||||
Spin(float xpos, float ypos, float s) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
speed = s;
|
||||
}
|
||||
void update() {
|
||||
angle += speed;
|
||||
}
|
||||
}
|
||||
|
||||
class SpinArm extends Spin
|
||||
{
|
||||
SpinArm(float x, float y, float s) {
|
||||
super(x, y, s);
|
||||
}
|
||||
void display() {
|
||||
strokeWeight(1);
|
||||
stroke(0);
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
angle += speed;
|
||||
rotate(angle);
|
||||
line(0, 0, 66, 0);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
class SpinSpots extends Spin
|
||||
{
|
||||
float dim;
|
||||
SpinSpots(float x, float y, float s, float d) {
|
||||
super(x, y, s);
|
||||
dim = d;
|
||||
}
|
||||
void display() {
|
||||
noStroke();
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
angle += speed;
|
||||
rotate(angle);
|
||||
ellipse(-dim/2, 0, dim, dim);
|
||||
ellipse(dim/2, 0, dim, dim);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
@@ -1,67 +0,0 @@
|
||||
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 MultipleConstructors extends PApplet {
|
||||
|
||||
/**
|
||||
* Multiple constructors
|
||||
*
|
||||
* A class can have multiple constructors that assign the fields in different ways.
|
||||
* Sometimes it's beneficial to specify every aspect of an object's data by assigning
|
||||
* parameters to the fields, but other times it might be appropriate to define only
|
||||
* one or a few.
|
||||
*/
|
||||
|
||||
Spot sp1, sp2;
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
background(204);
|
||||
smooth();
|
||||
noLoop();
|
||||
// Run the constructor without parameters
|
||||
sp1 = new Spot();
|
||||
// Run the constructor with three parameters
|
||||
sp2 = new Spot(122, 100, 40);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
sp1.display();
|
||||
sp2.display();
|
||||
}
|
||||
|
||||
class Spot {
|
||||
float x, y, radius;
|
||||
// First version of the Spot constructor;
|
||||
// the fields are assigned default values
|
||||
Spot() {
|
||||
x = 66;
|
||||
y = 100;
|
||||
radius = 16;
|
||||
}
|
||||
// Second version of the Spot constructor;
|
||||
// the fields are assigned with parameters
|
||||
Spot(float xpos, float ypos, float r) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
radius = r;
|
||||
}
|
||||
public void display() {
|
||||
ellipse(x, y, radius*2, radius*2);
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "MultipleConstructors" });
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Multiple constructors
|
||||
*
|
||||
* A class can have multiple constructors that assign the fields in different ways.
|
||||
* Sometimes it's beneficial to specify every aspect of an object's data by assigning
|
||||
* parameters to the fields, but other times it might be appropriate to define only
|
||||
* one or a few.
|
||||
*/
|
||||
|
||||
Spot sp1, sp2;
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
background(204);
|
||||
smooth();
|
||||
noLoop();
|
||||
// Run the constructor without parameters
|
||||
sp1 = new Spot();
|
||||
// Run the constructor with three parameters
|
||||
sp2 = new Spot(122, 100, 40);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
sp1.display();
|
||||
sp2.display();
|
||||
}
|
||||
|
||||
class Spot {
|
||||
float x, y, radius;
|
||||
// First version of the Spot constructor;
|
||||
// the fields are assigned default values
|
||||
Spot() {
|
||||
x = 66;
|
||||
y = 100;
|
||||
radius = 16;
|
||||
}
|
||||
// Second version of the Spot constructor;
|
||||
// the fields are assigned with parameters
|
||||
Spot(float xpos, float ypos, float r) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
radius = r;
|
||||
}
|
||||
void display() {
|
||||
ellipse(x, y, radius*2, radius*2);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
@@ -1,323 +0,0 @@
|
||||
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 Neighborhood extends PApplet {
|
||||
|
||||
/**
|
||||
* Neighborhood (OOP Example)
|
||||
* By Ira Greenberg
|
||||
*
|
||||
* Draw a neighborhood of houses using
|
||||
* Door, Window, Roof and House classes.
|
||||
* Good example of class composition, with component
|
||||
* Door, Window, Roof class references encapsulated
|
||||
* within House class. This arrangement allows
|
||||
* House class to handle placement and sizing of
|
||||
* its components, while still allowing user
|
||||
* customization of the individual components.
|
||||
*/
|
||||
|
||||
public void setup(){
|
||||
size(200, 200);
|
||||
background(190);
|
||||
smooth();
|
||||
// Ground plane
|
||||
int groundHeight = 10;
|
||||
fill(0);
|
||||
rect(0, height-groundHeight, width, groundHeight);
|
||||
fill(255);
|
||||
|
||||
// Center the houses
|
||||
translate(12, 0);
|
||||
|
||||
// Houses
|
||||
Door door1 = new Door(20, 40);
|
||||
Window window1 = new Window(50, 62, false, Window.DOUBLE);
|
||||
Roof roof1 = new Roof(Roof.DOME);
|
||||
House house1 = new House(75, 75, door1, window1, roof1, House.MIDDLE_DOOR);
|
||||
house1.drawHouse(0, height-groundHeight-house1.h, true);
|
||||
|
||||
Door door2 = new Door(20, 40);
|
||||
Window window2 = new Window(50, 62, true, Window.QUAD);
|
||||
Roof roof2 = new Roof(Roof.GAMBREL);
|
||||
House house2 = new House(100, 60, door2, window2, roof2, House.LEFT_DOOR);
|
||||
house2.drawHouse(house1.x + house1.w, height-groundHeight-house2.h, true);
|
||||
}
|
||||
|
||||
class Door{
|
||||
//door properties
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
// for knob
|
||||
int knobLoc = 1;
|
||||
//constants
|
||||
final static int RT = 0;
|
||||
final static int LFT = 1;
|
||||
|
||||
// constructor
|
||||
Door(int w, int h){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
// draw the door
|
||||
public void drawDoor(int x, int y) {
|
||||
rect(x, y, w, h);
|
||||
int knobsize = w/10;
|
||||
if (knobLoc == 0){
|
||||
//right side
|
||||
ellipse(x+w-knobsize, y+h/2, knobsize, knobsize);
|
||||
}
|
||||
else {
|
||||
//left side
|
||||
ellipse(x+knobsize, y+h/2, knobsize, knobsize);
|
||||
}
|
||||
}
|
||||
|
||||
// set knob position
|
||||
public void setKnob(int knobLoc){
|
||||
this. knobLoc = knobLoc;
|
||||
}
|
||||
}
|
||||
|
||||
class Window{
|
||||
//window properties
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
// customized features
|
||||
boolean hasSash = false;
|
||||
|
||||
// single, double, quad pane
|
||||
int style = 0;
|
||||
//constants
|
||||
final static int SINGLE = 0;
|
||||
final static int DOUBLE = 1;
|
||||
final static int QUAD = 2;
|
||||
|
||||
// constructor 1
|
||||
Window(int w, int h){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
// constructor 2
|
||||
Window(int w, int h, int style){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.style = style;
|
||||
}
|
||||
// constructor 3
|
||||
Window(int w, int h, boolean hasSash, int style){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.hasSash = hasSash;
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
// draw the window
|
||||
public void drawWindow(int x, int y) {
|
||||
//local variables
|
||||
int margin = 0;
|
||||
int winHt = 0;
|
||||
int winWdth = 0;
|
||||
|
||||
if (hasSash){
|
||||
margin = w/15;
|
||||
}
|
||||
|
||||
switch(style){
|
||||
case 0:
|
||||
//outer window (sash)
|
||||
rect(x, y, w, h);
|
||||
//inner window
|
||||
rect(x+margin, y+margin, w-margin*2, h-margin*2);
|
||||
break;
|
||||
case 1:
|
||||
winHt = (h-margin*3)/2;
|
||||
//outer window (sash)
|
||||
rect(x, y, w, h);
|
||||
//inner window (top)
|
||||
rect(x+margin, y+margin, w-margin*2, winHt);
|
||||
//inner windows (bottom)
|
||||
rect(x+margin, y+winHt+margin*2, w-margin*2, winHt);
|
||||
break;
|
||||
case 2:
|
||||
winWdth = (w-margin*3)/2;
|
||||
winHt = (h-margin*3)/2;
|
||||
//outer window (sash)
|
||||
rect(x, y, w, h);
|
||||
//inner window (top-left)
|
||||
rect(x+margin, y+margin, winWdth, winHt);
|
||||
//inner window (top-right)
|
||||
rect(x+winWdth+margin*2, y+margin, winWdth, winHt);
|
||||
//inner windows (bottom-left)
|
||||
rect(x+margin, y+winHt+margin*2, winWdth, winHt);
|
||||
//inner windows (bottom-right)
|
||||
rect(x+winWdth+margin*2, y+winHt+margin*2, winWdth, winHt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// set window style (number of panes)
|
||||
public void setStyle(int style){
|
||||
this.style = style;
|
||||
}
|
||||
}
|
||||
|
||||
class Roof{
|
||||
//roof properties
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
// roof style
|
||||
int style = 0;
|
||||
//constants
|
||||
final static int CATHEDRAL = 0;
|
||||
final static int GAMBREL = 1;
|
||||
final static int DOME = 2;
|
||||
|
||||
// default constructor
|
||||
Roof(){
|
||||
}
|
||||
|
||||
// constructor 2
|
||||
Roof(int style){
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
// draw the roof
|
||||
public void drawRoof(int x, int y, int w, int h) {
|
||||
switch(style){
|
||||
case 0:
|
||||
beginShape();
|
||||
vertex(x, y);
|
||||
vertex(x+w/2, y-h/3);
|
||||
vertex(x+w, y);
|
||||
endShape(CLOSE);
|
||||
break;
|
||||
case 1:
|
||||
beginShape();
|
||||
vertex(x, y);
|
||||
vertex(x+w/7, y-h/4);
|
||||
vertex(x+w/2, y-h/2);
|
||||
vertex(x+(w-w/7), y-h/4);
|
||||
vertex(x+w, y);
|
||||
endShape(CLOSE);
|
||||
break;
|
||||
case 2:
|
||||
ellipseMode(CORNER);
|
||||
arc(x, y-h/2, w, h, PI, TWO_PI);
|
||||
line(x, y, x+w, y);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// set roof style
|
||||
public void setStyle(int style){
|
||||
this.style = style;
|
||||
}
|
||||
}
|
||||
|
||||
class House{
|
||||
//house properties
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
//component reference variables
|
||||
Door door;
|
||||
Window window;
|
||||
Roof roof;
|
||||
|
||||
//optional autosize variable
|
||||
boolean AutoSizeComponents = false;
|
||||
|
||||
//door placement
|
||||
int doorLoc = 0;
|
||||
//constants
|
||||
final static int MIDDLE_DOOR = 0;
|
||||
final static int LEFT_DOOR = 1;
|
||||
final static int RIGHT_DOOR = 2;
|
||||
|
||||
//constructor
|
||||
House(int w, int h, Door door, Window window, Roof roof, int doorLoc) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.door = door;
|
||||
this.window = window;
|
||||
this.roof = roof;
|
||||
this.doorLoc = doorLoc;
|
||||
}
|
||||
|
||||
public void drawHouse(int x, int y, boolean AutoSizeComponents) {
|
||||
this.x = x;
|
||||
this.y =y;
|
||||
this.AutoSizeComponents = AutoSizeComponents;
|
||||
|
||||
//automatically sizes doors and windows
|
||||
if(AutoSizeComponents){
|
||||
//autosize door
|
||||
door.h = h/4;
|
||||
door.w = door.h/2;
|
||||
|
||||
//autosize windows
|
||||
window.h = h/3;
|
||||
window.w = window.h/2;
|
||||
|
||||
}
|
||||
// draw bldg block
|
||||
rect(x, y, w, h);
|
||||
|
||||
// draw door
|
||||
switch(doorLoc){
|
||||
case 0:
|
||||
door.drawDoor(x+w/2-door.w/2, y+h-door.h);
|
||||
break;
|
||||
case 1:
|
||||
door.drawDoor(x+w/8, y+h-door.h);
|
||||
break;
|
||||
case 2:
|
||||
door.drawDoor(x+w-w/8-door.w, y+h-door.h);
|
||||
break;
|
||||
}
|
||||
|
||||
// draw windows
|
||||
int windowMargin = (w-window.w*2)/3;
|
||||
window.drawWindow(x+windowMargin, y+h/6);
|
||||
window.drawWindow(x+windowMargin*2+window.w, y+h/6);
|
||||
|
||||
// draw roof
|
||||
roof.drawRoof(x, y, w, h);
|
||||
}
|
||||
|
||||
// catch drawHouse method without boolean argument
|
||||
public void drawHouse(int x, int y){
|
||||
// recall with required 3rd argument
|
||||
drawHouse(x, y, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Neighborhood" });
|
||||
}
|
||||
}
|
||||
@@ -1,303 +0,0 @@
|
||||
/**
|
||||
* Neighborhood (OOP Example)
|
||||
* By Ira Greenberg
|
||||
*
|
||||
* Draw a neighborhood of houses using
|
||||
* Door, Window, Roof and House classes.
|
||||
* Good example of class composition, with component
|
||||
* Door, Window, Roof class references encapsulated
|
||||
* within House class. This arrangement allows
|
||||
* House class to handle placement and sizing of
|
||||
* its components, while still allowing user
|
||||
* customization of the individual components.
|
||||
*/
|
||||
|
||||
void setup(){
|
||||
size(200, 200);
|
||||
background(190);
|
||||
smooth();
|
||||
// Ground plane
|
||||
int groundHeight = 10;
|
||||
fill(0);
|
||||
rect(0, height-groundHeight, width, groundHeight);
|
||||
fill(255);
|
||||
|
||||
// Center the houses
|
||||
translate(12, 0);
|
||||
|
||||
// Houses
|
||||
Door door1 = new Door(20, 40);
|
||||
Window window1 = new Window(50, 62, false, Window.DOUBLE);
|
||||
Roof roof1 = new Roof(Roof.DOME);
|
||||
House house1 = new House(75, 75, door1, window1, roof1, House.MIDDLE_DOOR);
|
||||
house1.drawHouse(0, height-groundHeight-house1.h, true);
|
||||
|
||||
Door door2 = new Door(20, 40);
|
||||
Window window2 = new Window(50, 62, true, Window.QUAD);
|
||||
Roof roof2 = new Roof(Roof.GAMBREL);
|
||||
House house2 = new House(100, 60, door2, window2, roof2, House.LEFT_DOOR);
|
||||
house2.drawHouse(house1.x + house1.w, height-groundHeight-house2.h, true);
|
||||
}
|
||||
|
||||
class Door{
|
||||
//door properties
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
// for knob
|
||||
int knobLoc = 1;
|
||||
//constants
|
||||
final static int RT = 0;
|
||||
final static int LFT = 1;
|
||||
|
||||
// constructor
|
||||
Door(int w, int h){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
// draw the door
|
||||
void drawDoor(int x, int y) {
|
||||
rect(x, y, w, h);
|
||||
int knobsize = w/10;
|
||||
if (knobLoc == 0){
|
||||
//right side
|
||||
ellipse(x+w-knobsize, y+h/2, knobsize, knobsize);
|
||||
}
|
||||
else {
|
||||
//left side
|
||||
ellipse(x+knobsize, y+h/2, knobsize, knobsize);
|
||||
}
|
||||
}
|
||||
|
||||
// set knob position
|
||||
void setKnob(int knobLoc){
|
||||
this. knobLoc = knobLoc;
|
||||
}
|
||||
}
|
||||
|
||||
class Window{
|
||||
//window properties
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
// customized features
|
||||
boolean hasSash = false;
|
||||
|
||||
// single, double, quad pane
|
||||
int style = 0;
|
||||
//constants
|
||||
final static int SINGLE = 0;
|
||||
final static int DOUBLE = 1;
|
||||
final static int QUAD = 2;
|
||||
|
||||
// constructor 1
|
||||
Window(int w, int h){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
// constructor 2
|
||||
Window(int w, int h, int style){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.style = style;
|
||||
}
|
||||
// constructor 3
|
||||
Window(int w, int h, boolean hasSash, int style){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.hasSash = hasSash;
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
// draw the window
|
||||
void drawWindow(int x, int y) {
|
||||
//local variables
|
||||
int margin = 0;
|
||||
int winHt = 0;
|
||||
int winWdth = 0;
|
||||
|
||||
if (hasSash){
|
||||
margin = w/15;
|
||||
}
|
||||
|
||||
switch(style){
|
||||
case 0:
|
||||
//outer window (sash)
|
||||
rect(x, y, w, h);
|
||||
//inner window
|
||||
rect(x+margin, y+margin, w-margin*2, h-margin*2);
|
||||
break;
|
||||
case 1:
|
||||
winHt = (h-margin*3)/2;
|
||||
//outer window (sash)
|
||||
rect(x, y, w, h);
|
||||
//inner window (top)
|
||||
rect(x+margin, y+margin, w-margin*2, winHt);
|
||||
//inner windows (bottom)
|
||||
rect(x+margin, y+winHt+margin*2, w-margin*2, winHt);
|
||||
break;
|
||||
case 2:
|
||||
winWdth = (w-margin*3)/2;
|
||||
winHt = (h-margin*3)/2;
|
||||
//outer window (sash)
|
||||
rect(x, y, w, h);
|
||||
//inner window (top-left)
|
||||
rect(x+margin, y+margin, winWdth, winHt);
|
||||
//inner window (top-right)
|
||||
rect(x+winWdth+margin*2, y+margin, winWdth, winHt);
|
||||
//inner windows (bottom-left)
|
||||
rect(x+margin, y+winHt+margin*2, winWdth, winHt);
|
||||
//inner windows (bottom-right)
|
||||
rect(x+winWdth+margin*2, y+winHt+margin*2, winWdth, winHt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// set window style (number of panes)
|
||||
void setStyle(int style){
|
||||
this.style = style;
|
||||
}
|
||||
}
|
||||
|
||||
class Roof{
|
||||
//roof properties
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
// roof style
|
||||
int style = 0;
|
||||
//constants
|
||||
final static int CATHEDRAL = 0;
|
||||
final static int GAMBREL = 1;
|
||||
final static int DOME = 2;
|
||||
|
||||
// default constructor
|
||||
Roof(){
|
||||
}
|
||||
|
||||
// constructor 2
|
||||
Roof(int style){
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
// draw the roof
|
||||
void drawRoof(int x, int y, int w, int h) {
|
||||
switch(style){
|
||||
case 0:
|
||||
beginShape();
|
||||
vertex(x, y);
|
||||
vertex(x+w/2, y-h/3);
|
||||
vertex(x+w, y);
|
||||
endShape(CLOSE);
|
||||
break;
|
||||
case 1:
|
||||
beginShape();
|
||||
vertex(x, y);
|
||||
vertex(x+w/7, y-h/4);
|
||||
vertex(x+w/2, y-h/2);
|
||||
vertex(x+(w-w/7), y-h/4);
|
||||
vertex(x+w, y);
|
||||
endShape(CLOSE);
|
||||
break;
|
||||
case 2:
|
||||
ellipseMode(CORNER);
|
||||
arc(x, y-h/2, w, h, PI, TWO_PI);
|
||||
line(x, y, x+w, y);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// set roof style
|
||||
void setStyle(int style){
|
||||
this.style = style;
|
||||
}
|
||||
}
|
||||
|
||||
class House{
|
||||
//house properties
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
//component reference variables
|
||||
Door door;
|
||||
Window window;
|
||||
Roof roof;
|
||||
|
||||
//optional autosize variable
|
||||
boolean AutoSizeComponents = false;
|
||||
|
||||
//door placement
|
||||
int doorLoc = 0;
|
||||
//constants
|
||||
final static int MIDDLE_DOOR = 0;
|
||||
final static int LEFT_DOOR = 1;
|
||||
final static int RIGHT_DOOR = 2;
|
||||
|
||||
//constructor
|
||||
House(int w, int h, Door door, Window window, Roof roof, int doorLoc) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.door = door;
|
||||
this.window = window;
|
||||
this.roof = roof;
|
||||
this.doorLoc = doorLoc;
|
||||
}
|
||||
|
||||
void drawHouse(int x, int y, boolean AutoSizeComponents) {
|
||||
this.x = x;
|
||||
this.y =y;
|
||||
this.AutoSizeComponents = AutoSizeComponents;
|
||||
|
||||
//automatically sizes doors and windows
|
||||
if(AutoSizeComponents){
|
||||
//autosize door
|
||||
door.h = h/4;
|
||||
door.w = door.h/2;
|
||||
|
||||
//autosize windows
|
||||
window.h = h/3;
|
||||
window.w = window.h/2;
|
||||
|
||||
}
|
||||
// draw bldg block
|
||||
rect(x, y, w, h);
|
||||
|
||||
// draw door
|
||||
switch(doorLoc){
|
||||
case 0:
|
||||
door.drawDoor(x+w/2-door.w/2, y+h-door.h);
|
||||
break;
|
||||
case 1:
|
||||
door.drawDoor(x+w/8, y+h-door.h);
|
||||
break;
|
||||
case 2:
|
||||
door.drawDoor(x+w-w/8-door.w, y+h-door.h);
|
||||
break;
|
||||
}
|
||||
|
||||
// draw windows
|
||||
int windowMargin = (w-window.w*2)/3;
|
||||
window.drawWindow(x+windowMargin, y+h/6);
|
||||
window.drawWindow(x+windowMargin*2+window.w, y+h/6);
|
||||
|
||||
// draw roof
|
||||
roof.drawRoof(x, y, w, h);
|
||||
}
|
||||
|
||||
// catch drawHouse method without boolean argument
|
||||
void drawHouse(int x, int y){
|
||||
// recall with required 3rd argument
|
||||
drawHouse(x, y, false);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
@@ -1,91 +0,0 @@
|
||||
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 Objects extends PApplet {
|
||||
|
||||
/**
|
||||
* Objects
|
||||
* by hbarragan.
|
||||
*
|
||||
* Move the cursor across the image to change the speed and positions
|
||||
* of the geometry. The class MRect defines a group of lines.
|
||||
*/
|
||||
|
||||
MRect r1, r2, r3, r4;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
fill(255, 204);
|
||||
noStroke();
|
||||
r1 = new MRect(1, 134.0f, 0.532f, 0.083f*height, 10.0f, 60.0f);
|
||||
r2 = new MRect(2, 44.0f, 0.166f, 0.332f*height, 5.0f, 50.0f);
|
||||
r3 = new MRect(2, 58.0f, 0.332f, 0.4482f*height, 10.0f, 35.0f);
|
||||
r4 = new MRect(1, 120.0f, 0.0498f, 0.913f*height, 15.0f, 60.0f);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
r1.display();
|
||||
r2.display();
|
||||
r3.display();
|
||||
r4.display();
|
||||
|
||||
r1.move(mouseX-(width/2), mouseY+(height*0.1f), 30);
|
||||
r2.move((mouseX+(width*0.05f))%width, mouseY+(height*0.025f), 20);
|
||||
r3.move(mouseX/4, mouseY-(height*0.025f), 40);
|
||||
r4.move(mouseX-(width/2), (height-mouseY), 50);
|
||||
}
|
||||
|
||||
class MRect
|
||||
{
|
||||
int w; // single bar width
|
||||
float xpos; // rect xposition
|
||||
float h; // rect height
|
||||
float ypos ; // rect yposition
|
||||
float d; // single bar distance
|
||||
float t; // number of bars
|
||||
|
||||
MRect(int iw, float ixp, float ih, float iyp, float id, float it) {
|
||||
w = iw;
|
||||
xpos = ixp;
|
||||
h = ih;
|
||||
ypos = iyp;
|
||||
d = id;
|
||||
t = it;
|
||||
}
|
||||
|
||||
public void move (float posX, float posY, float damping) {
|
||||
float dif = ypos - posY;
|
||||
if (abs(dif) > 1) {
|
||||
ypos -= dif/damping;
|
||||
}
|
||||
dif = xpos - posX;
|
||||
if (abs(dif) > 1) {
|
||||
xpos -= dif/damping;
|
||||
}
|
||||
}
|
||||
|
||||
public void display() {
|
||||
for (int i=0; i<t; i++) {
|
||||
rect(xpos+(i*(d+w)), ypos, w, height*h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Objects" });
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/**
|
||||
* Objects
|
||||
* by hbarragan.
|
||||
*
|
||||
* Move the cursor across the image to change the speed and positions
|
||||
* of the geometry. The class MRect defines a group of lines.
|
||||
*/
|
||||
|
||||
MRect r1, r2, r3, r4;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
fill(255, 204);
|
||||
noStroke();
|
||||
r1 = new MRect(1, 134.0, 0.532, 0.083*height, 10.0, 60.0);
|
||||
r2 = new MRect(2, 44.0, 0.166, 0.332*height, 5.0, 50.0);
|
||||
r3 = new MRect(2, 58.0, 0.332, 0.4482*height, 10.0, 35.0);
|
||||
r4 = new MRect(1, 120.0, 0.0498, 0.913*height, 15.0, 60.0);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
r1.display();
|
||||
r2.display();
|
||||
r3.display();
|
||||
r4.display();
|
||||
|
||||
r1.move(mouseX-(width/2), mouseY+(height*0.1), 30);
|
||||
r2.move((mouseX+(width*0.05))%width, mouseY+(height*0.025), 20);
|
||||
r3.move(mouseX/4, mouseY-(height*0.025), 40);
|
||||
r4.move(mouseX-(width/2), (height-mouseY), 50);
|
||||
}
|
||||
|
||||
class MRect
|
||||
{
|
||||
int w; // single bar width
|
||||
float xpos; // rect xposition
|
||||
float h; // rect height
|
||||
float ypos ; // rect yposition
|
||||
float d; // single bar distance
|
||||
float t; // number of bars
|
||||
|
||||
MRect(int iw, float ixp, float ih, float iyp, float id, float it) {
|
||||
w = iw;
|
||||
xpos = ixp;
|
||||
h = ih;
|
||||
ypos = iyp;
|
||||
d = id;
|
||||
t = it;
|
||||
}
|
||||
|
||||
void move (float posX, float posY, float damping) {
|
||||
float dif = ypos - posY;
|
||||
if (abs(dif) > 1) {
|
||||
ypos -= dif/damping;
|
||||
}
|
||||
dif = xpos - posX;
|
||||
if (abs(dif) > 1) {
|
||||
xpos -= dif/damping;
|
||||
}
|
||||
}
|
||||
|
||||
void display() {
|
||||
for (int i=0; i<t; i++) {
|
||||
rect(xpos+(i*(d+w)), ypos, w, height*h);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
Reference in New Issue
Block a user