Removing some examples

This commit is contained in:
Casey Reas
2011-09-06 03:51:23 +00:00
parent 5e0e9eaedc
commit 68c460be7d
30 changed files with 76 additions and 1215 deletions
@@ -8,18 +8,16 @@
Eye e1, e2, e3;
void setup()
{
void setup() {
size(640, 360);
smooth();
noStroke();
e1 = new Eye( 190, 16, 120);
e1 = new Eye( 250, 16, 120);
e2 = new Eye( 164, 185, 80);
e3 = new Eye( 390, 200, 220);
e3 = new Eye( 420, 230, 220);
}
void draw()
{
void draw() {
background(102);
e1.update(mouseX, mouseY);
@@ -31,8 +29,7 @@ void draw()
e3.display();
}
class Eye
{
class Eye {
int x, y;
int size;
float angle = 0.0;
@@ -1,31 +0,0 @@
/**
* Modulo.
*
* The modulo operator (%) returns the remainder of a number
* divided by another. As in this example, it is often used
* to keep numerical values within a set range.
*/
int num = 20;
float c;
void setup()
{
size(200,200);
fill(255);
frameRate(30);
}
void draw()
{
background(0);
c+=0.1;
for(int i=1; i<height/num; i++) {
float x = (c%i)*i*i;
stroke(102);
line(0, i*num, x, i*num);
noStroke();
rect(x, i*num-num/2, 8, num);
}
}
+2 -3
View File
@@ -16,9 +16,8 @@ void setup() {
void draw() {
for (int i = 0; i < width; i++) {
float r = random(255);
float x = random(0, width);
stroke(r, 100);
line(i, 0, x, height);
stroke(r);
line(i, 0, i, height);
}
}
@@ -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);
}
}
@@ -10,10 +10,9 @@ int numFrames = 12; // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[numFrames];
void setup()
{
size(200, 200);
frameRate(30);
void setup() {
size(640, 360);
frameRate(24);
images[0] = loadImage("PT_anim0000.gif");
images[1] = loadImage("PT_anim0001.gif");
@@ -39,8 +38,9 @@ void setup()
//}
}
void draw()
{
void draw() {
frame = (frame+1) % numFrames; // Use % to cycle through frames
image(images[frame], 50, 50);
image(images[frame], 10, 70);
image(images[(frame + 3) % numFrames], 220, 70);
image(images[(frame + 6) % numFrames], 430, 70);
}
@@ -16,7 +16,7 @@ int lastTime = 0;
void setup()
{
size(640, 200);
size(640, 360);
strokeWeight(12);
smooth();
background(204);
@@ -4,14 +4,18 @@
* Click and drag the mouse to draw a line.
*/
int px, py;
void setup() {
size(640, 200);
size(640, 360);
background(102);
}
void draw() {
stroke(255);
if(mousePressed) {
line(mouseX, mouseY, pmouseX, pmouseY);
line(mouseX, mouseY, px, py);
}
px = mouseX;
py = mouseY;
}
@@ -19,8 +19,8 @@ void setup() {
void draw() {
// Draw only when mouse is pressed
if (mousePressed == true) {
angle += 10;
float val = cos(radians(angle)) * 6.0;
angle += 5;
float val = cos(radians(angle)) * 12.0;
for (int a = 0; a < 360; a += 75) {
float xoff = cos(radians(a)) * val;
float yoff = sin(radians(a)) * val;
+3 -3
View File
@@ -8,8 +8,8 @@
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
int rectSize = 90; // Diameter of rect
int circleSize = 93; // Diameter of circle
color rectColor, circleColor, baseColor;
color rectHighlight, circleHighlight;
color currentColor;
@@ -18,7 +18,7 @@ boolean circleOver = false;
void setup()
{
size(200, 200);
size(640, 360);
smooth();
rectColor = color(0);
rectHighlight = color(51);
+1 -1
View File
@@ -15,7 +15,7 @@ boolean locked = false;
void setup()
{
size(200, 200);
size(640, 360);
smooth();
color baseColor = color(102);
+14 -25
View File
@@ -7,9 +7,8 @@
Handle[] handles;
int num;
void setup()
{
size(200, 200);
void setup() {
size(640, 360);
num = height/15;
handles = new Handle[num];
int hsize = 10;
@@ -18,8 +17,7 @@ void setup()
}
}
void draw()
{
void draw() {
background(153);
for(int i=0; i<num; i++) {
@@ -31,15 +29,14 @@ void draw()
rect(0, 0, width/2, height);
}
void mouseReleased()
{
void mouseReleased() {
for(int i=0; i<num; i++) {
handles[i].release();
}
}
class Handle
{
class Handle {
int x, y;
int boxx, boxy;
int length;
@@ -50,8 +47,7 @@ class Handle
boolean otherslocked = false;
Handle[] others;
Handle(int ix, int iy, int il, int is, Handle[] o)
{
Handle(int ix, int iy, int il, int is, Handle[] o) {
x = ix;
y = iy;
length = il;
@@ -61,8 +57,7 @@ class Handle
others = o;
}
void update()
{
void update() {
boxx = x+length;
boxy = y - size/2;
@@ -85,8 +80,7 @@ class Handle
}
}
void over()
{
void over() {
if(overRect(boxx, boxy, size, size)) {
over = true;
} else {
@@ -94,8 +88,7 @@ class Handle
}
}
void press()
{
void press() {
if(over && mousePressed || locked) {
press = true;
locked = true;
@@ -104,13 +97,11 @@ class Handle
}
}
void release()
{
void release() {
locked = false;
}
void display()
{
void display() {
line(x, y, x+length, y);
fill(255);
stroke(0);
@@ -123,8 +114,7 @@ class Handle
}
}
boolean overRect(int x, int y, int width, int height)
{
boolean overRect(int x, int y, int width, int height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
@@ -133,7 +123,6 @@ boolean overRect(int x, int y, int width, int height)
}
}
int lock(int val, int minv, int maxv)
{
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

+8 -13
View File
@@ -8,8 +8,8 @@
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
int rectSize = 90; // Diameter of rect
int circleSize = 93; // Diameter of circle
color rectColor;
color circleColor;
@@ -18,9 +18,8 @@ color baseColor;
boolean rectOver = false;
boolean circleOver = false;
void setup()
{
size(200, 200);
void setup() {
size(640, 360);
smooth();
rectColor = color(0);
circleColor = color(255);
@@ -32,8 +31,7 @@ void setup()
ellipseMode(CENTER);
}
void draw()
{
void draw() {
update(mouseX, mouseY);
noStroke();
@@ -53,8 +51,7 @@ void draw()
ellipse(circleX, circleY, circleSize, circleSize);
}
void update(int x, int y)
{
void update(int x, int y) {
if( overCircle(circleX, circleY, circleSize) ) {
circleOver = true;
rectOver = false;
@@ -66,8 +63,7 @@ void update(int x, int y)
}
}
boolean overRect(int x, int y, int width, int height)
{
boolean overRect(int x, int y, int width, int height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
@@ -76,8 +72,7 @@ boolean overRect(int x, int y, int width, int height)
}
}
boolean overCircle(int x, int y, int diameter)
{
boolean overCircle(int x, int y, int diameter) {
float disX = x - mouseX;
float disY = y - mouseY;
if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
@@ -10,20 +10,18 @@ PImage top, bottom; // Two image to load
int topWidth, bottomWidth; // The width of the top and bottom images
void setup()
{
size(200, 200);
void setup() {
size(640, 360);
noStroke();
hs1 = new HScrollbar(0, 20, width, 10, 3*5+1);
hs2 = new HScrollbar(0, height-20, width, 10, 3*5+1);
hs1 = new HScrollbar(0, 20, width, 20, 3*5+1);
hs2 = new HScrollbar(0, height-20, width, 20, 3*5+1);
top = loadImage("seedTop.jpg");
topWidth = top.width;
bottom = loadImage("seedBottom.jpg");
bottomWidth = bottom.width;
}
void draw()
{
void draw() {
background(255);
// Get the position of the top scrollbar
@@ -45,8 +43,7 @@ void draw()
}
class HScrollbar
{
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
@@ -1,59 +0,0 @@
/**
* Brick Tower
* by Ira Greenberg.
*
* 3D castle tower constructed out of individual bricks.
* Uses the PVector and Cube classes.
*/
float bricksPerLayer = 16.0;
float brickLayers = 18.0;
Cube brick;
float brickWidth = 60, brickHeight = 25, brickDepth = 25;
float radius = 175.0;
float angle = 0;
void setup(){
size(640, 360, P3D);
brick = new Cube(brickWidth, brickHeight, brickDepth);
}
void draw(){
background(0);
float tempX = 0, tempY = 0, tempZ = 0;
fill(182, 62, 29);
noStroke();
// Add basic light setup
lights();
translate(width/2, height*1.2, -380);
// Tip tower to see inside
rotateX(radians(-45));
// Slowly rotate tower
rotateY(frameCount * PI/600);
for (int i = 0; i < brickLayers; i++){
// Increment rows
tempY-=brickHeight;
// Alternate brick seams
angle = 360.0 / bricksPerLayer * i/2;
for (int j = 0; j < bricksPerLayer; j++){
tempZ = cos(radians(angle))*radius;
tempX = sin(radians(angle))*radius;
pushMatrix();
translate(tempX, tempY, tempZ);
rotateY(radians(angle));
// Add crenelation
if (i==brickLayers-1){
if (j%2 == 0){
brick.create();
}
}
// Create main tower
else {
brick.create();
}
popMatrix();
angle += 360.0/bricksPerLayer;
}
}
}
@@ -1,60 +0,0 @@
class Cube {
PVector[] vertices = new PVector[24];
float w, h, d;
Cube(){ }
Cube(float w, float h, float d){
this.w = w;
this.h = h;
this.d = d;
// Cube composed of 6 quads
// Front
vertices[0] = new PVector(-w/2, -h/2, d/2);
vertices[1] = new PVector(w/2, -h/2, d/2);
vertices[2] = new PVector(w/2, h/2, d/2);
vertices[3] = new PVector(-w/2, h/2, d/2);
// Left
vertices[4] = new PVector(-w/2, -h/2, d/2);
vertices[5] = new PVector(-w/2, -h/2, -d/2);
vertices[6] = new PVector(-w/2, h/2, -d/2);
vertices[7] = new PVector(-w/2, h/2, d/2);
// Right
vertices[8] = new PVector(w/2, -h/2, d/2);
vertices[9] = new PVector(w/2, -h/2, -d/2);
vertices[10] = new PVector(w/2, h/2, -d/2);
vertices[11] = new PVector(w/2, h/2, d/2);
// Back
vertices[12] = new PVector(-w/2, -h/2, -d/2);
vertices[13] = new PVector(w/2, -h/2, -d/2);
vertices[14] = new PVector(w/2, h/2, -d/2);
vertices[15] = new PVector(-w/2, h/2, -d/2);
// Top
vertices[16] = new PVector(-w/2, -h/2, d/2);
vertices[17] = new PVector(-w/2, -h/2, -d/2);
vertices[18] = new PVector(w/2, -h/2, -d/2);
vertices[19] = new PVector(w/2, -h/2, d/2);
// Bottom
vertices[20] = new PVector(-w/2, h/2, d/2);
vertices[21] = new PVector(-w/2, h/2, -d/2);
vertices[22] = new PVector(w/2, h/2, -d/2);
vertices[23] = new PVector(w/2, h/2, d/2);
}
void create(){
for (int i=0; i<6; i++){
beginShape(QUADS);
for (int j = 0; j < 4; j++){
vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z);
}
endShape();
}
}
}
@@ -5,8 +5,7 @@
* A histogram is the frequency distribution
* of the gray levels with the number of pure black values
* displayed on the left and number of pure white values on the right.
*
* Updated 28 February, 2010.
*
* Note that this sketch will behave differently on Android,
* since most images will no longer be full 24-bit color.
*/
@@ -5,8 +5,6 @@
* press and hold any key to see the current pixel being read.
* This program sequentially reads the color of every pixel of an image
* and displays this color to fill the window.
*
* Updated 28 February 2010.
*/
PImage img;
@@ -6,13 +6,14 @@
*/
String message = "tickle";
PFont f;
float x, y; // X and Y coordinates of text
float hr, vr; // horizontal and vertical radius of the text
void setup() {
size(200, 200);
PFont font = loadFont("AmericanTypewriter-24.vlw");
textFont(font);
size(640, 360);
f = createFont("Courier New", 36);
textFont(f);
textAlign(CENTER, CENTER);
hr = textWidth(message) / 2;
vr = (textAscent() + textDescent()) / 2;
@@ -4,7 +4,7 @@
* When the shape hits the edge of the window, it reverses its direction.
*/
int size = 60; // Width of the shape
int rad = 60; // Width of the shape
float xpos, ypos; // Starting position of shape
float xspeed = 2.8; // Speed of the shape
@@ -16,9 +16,10 @@ int ydirection = 1; // Top to Bottom
void setup()
{
size(640, 200);
size(640, 360);
noStroke();
frameRate(30);
ellipseMode(RADIUS);
smooth();
// Set the starting position of the shape
xpos = width/2;
@@ -35,13 +36,13 @@ void draw()
// Test to see if the shape exceeds the boundaries of the screen
// If it does, reverse its direction by multiplying by -1
if (xpos > width-size || xpos < 0) {
if (xpos > width-rad || xpos < rad) {
xdirection *= -1;
}
if (ypos > height-size || ypos < 0) {
if (ypos > height-rad || ypos < rad) {
ydirection *= -1;
}
// Draw the shape
ellipse(xpos+size/2, ypos+size/2, size, size);
ellipse(xpos, ypos, rad, rad);
}
@@ -14,11 +14,11 @@ Ball[] balls = new Ball[numBalls];
void setup()
{
size(640, 200);
size(640, 360);
noStroke();
smooth();
for (int i = 0; i < numBalls; i++) {
balls[i] = new Ball(random(width), random(height), random(20, 40), i, balls);
balls[i] = new Ball(random(width), random(height), random(30, 70), i, balls);
}
}
@@ -1,85 +0,0 @@
/**
* Collision (Pong).
*
* Move the mouse up and down to move the paddle.
*/
// Global variables for the ball
float ball_x;
float ball_y;
float ball_dir = 1;
float ball_size = 15; // Radius
float dy = 0; // Direction
// Global variables for the paddle
int paddle_width = 10;
int paddle_height = 60;
int dist_wall = 15;
void setup()
{
size(640, 360);
rectMode(RADIUS);
ellipseMode(RADIUS);
noStroke();
smooth();
ball_y = height/2;
ball_x = 1;
}
void draw()
{
background(51);
ball_x += ball_dir * 1.0;
ball_y += dy;
if(ball_x > width+ball_size) {
ball_x = -width/2 - ball_size;
ball_y = random(0, height);
dy = 0;
}
// Constrain paddle to screen
float paddle_y = constrain(mouseY, paddle_height, height-paddle_height);
// Test to see if the ball is touching the paddle
float py = width-dist_wall-paddle_width-ball_size;
if(ball_x == py
&& ball_y > paddle_y - paddle_height - ball_size
&& ball_y < paddle_y + paddle_height + ball_size) {
ball_dir *= -1;
if(mouseY != pmouseY) {
dy = (mouseY-pmouseY)/2.0;
if(dy > 5) { dy = 5; }
if(dy < -5) { dy = -5; }
}
}
// If ball hits paddle or back wall, reverse direction
if(ball_x < ball_size && ball_dir == -1) {
ball_dir *= -1;
}
// If the ball is touching top or bottom edge, reverse direction
if(ball_y > height-ball_size) {
dy = dy * -1;
}
if(ball_y < ball_size) {
dy = dy * -1;
}
// Draw ball
fill(255);
ellipse(ball_x, ball_y, ball_size, ball_size);
// Draw the paddle
fill(153);
rect(width-dist_wall, paddle_y, paddle_width, paddle_height);
}
@@ -7,20 +7,19 @@
* back at the bottom of the screen.
*/
float a = 100;
float a;
void setup()
{
size(640, 200);
void setup() {
size(640, 360);
stroke(255);
a = height/2;
}
void draw()
{
void draw() {
background(51);
line(0, a, width, a);
a = a - 0.5;
if (a < 0) {
a = height;
}
line(0, a, width, a);
}
@@ -16,7 +16,7 @@ float ellipseSpeed = 3.5;
float velocityX, velocityY;
void setup(){
size(640, 240);
size(640, 360);
frameRate(30);
fill(128);
smooth();
@@ -14,7 +14,7 @@ Ground[] ground = new Ground[segments];
float[] peakHeights = new float[segments+1];
void setup(){
size(640, 200);
size(640, 360);
smooth();
orb = new Orb(50, 50, 3);
velocity = new PVector(.5, 0);
@@ -1,208 +0,0 @@
/**
* Fluid
* by Glen Murphy.
*
* Click and drag the mouse to move the simulated fluid.
* Adjust the "res" variable below to change resolution.
* Code has not been optimised, and will run fairly slowly.
*/
int res = 2;
int penSize = 30;
int lwidth;
int lheight;
int pnum = 30000;
vsquare[][] v;
vbuffer[][] vbuf;
particle[] p = new particle[pnum];
int pcount = 0;
int mouseXvel = 0;
int mouseYvel = 0;
void setup()
{
size(200, 200);
noStroke();
frameRate(30);
lwidth = width/res;
lheight = height/res;
v = new vsquare[lwidth+1][lheight+1];
vbuf = new vbuffer[lwidth+1][lheight+1];
for (int i = 0; i < pnum; i++) {
p[i] = new particle(random(res,width-res),random(res,height-res));
}
for (int i = 0; i <= lwidth; i++) {
for (int u = 0; u <= lheight; u++) {
v[i][u] = new vsquare(i*res,u*res);
vbuf[i][u] = new vbuffer(i*res,u*res);
}
}
}
void draw()
{
background(#666666);
int axvel = mouseX-pmouseX;
int ayvel = mouseY-pmouseY;
mouseXvel = (axvel != mouseXvel) ? axvel : 0;
mouseYvel = (ayvel != mouseYvel) ? ayvel : 0;
for (int i = 0; i < lwidth; i++) {
for (int u = 0; u < lheight; u++) {
vbuf[i][u].updatebuf(i,u);
v[i][u].col = 32;
}
}
for (int i = 0; i < pnum-1; i++) {
p[i].updatepos();
}
for (int i = 0; i < lwidth; i++) {
for (int u = 0; u < lheight; u++) {
v[i][u].addbuffer(i, u);
v[i][u].updatevels(mouseXvel, mouseYvel);
v[i][u].display(i, u);
}
}
}
class particle {
float x;
float y;
float xvel;
float yvel;
int pos;
particle(float xIn, float yIn) {
x = xIn;
y = yIn;
}
void updatepos() {
float col1;
if (x > 0 && x < width && y > 0 && y < height) {
int vi = (int)(x/res);
int vu = (int)(y/res);
vsquare o = v[vi][vu];
float ax = (x%res)/res;
float ay = (y%res)/res;
xvel += (1-ax)*v[vi][vu].xvel*0.05;
yvel += (1-ay)*v[vi][vu].yvel*0.05;
xvel += ax*v[vi+1][vu].xvel*0.05;
yvel += ax*v[vi+1][vu].yvel*0.05;
xvel += ay*v[vi][vu+1].xvel*0.05;
yvel += ay*v[vi][vu+1].yvel*0.05;
o.col += 4;
x += xvel;
y += yvel;
}
else {
x = random(0,width);
y = random(0,height);
xvel = 0;
yvel = 0;
}
xvel *= 0.5;
yvel *= 0.5;
}
}
class vbuffer {
int x;
int y;
float xvel;
float yvel;
float pressurex = 0;
float pressurey = 0;
float pressure = 0;
vbuffer(int xIn,int yIn) {
x = xIn;
y = yIn;
pressurex = 0;
pressurey = 0;
}
void updatebuf(int i, int u) {
if (i>0 && i<lwidth && u>0 && u<lheight) {
pressurex = (v[i-1][u-1].xvel*0.5 + v[i-1][u].xvel + v[i-1][u+1].xvel*0.5 - v[i+1][u-1].xvel*0.5 - v[i+1][u].xvel - v[i+1][u+1].xvel*0.5);
pressurey = (v[i-1][u-1].yvel*0.5 + v[i][u-1].yvel + v[i+1][u-1].yvel*0.5 - v[i-1][u+1].yvel*0.5 - v[i][u+1].yvel - v[i+1][u+1].yvel*0.5);
pressure = (pressurex + pressurey)*0.25;
}
}
}
class vsquare {
int x;
int y;
float xvel;
float yvel;
float col;
vsquare(int xIn,int yIn) {
x = xIn;
y = yIn;
}
void addbuffer(int i, int u) {
if (i>0 && i<lwidth && u>0 && u<lheight) {
xvel += (vbuf[i-1][u-1].pressure*0.5
+vbuf[i-1][u].pressure
+vbuf[i-1][u+1].pressure*0.5
-vbuf[i+1][u-1].pressure*0.5
-vbuf[i+1][u].pressure
-vbuf[i+1][u+1].pressure*0.5
)*0.25;
yvel += (vbuf[i-1][u-1].pressure*0.5
+vbuf[i][u-1].pressure
+vbuf[i+1][u-1].pressure*0.5
-vbuf[i-1][u+1].pressure*0.5
-vbuf[i][u+1].pressure
-vbuf[i+1][u+1].pressure*0.5
)*0.25;
}
}
void updatevels(int mvelX, int mvelY) {
if (mousePressed) {
float adj = x - mouseX;
float opp = y - mouseY;
float dist = sqrt(opp*opp + adj*adj);
if (dist < penSize) {
if (dist < 4) dist = penSize;
float mod = penSize/dist;
xvel += mvelX*mod;
yvel += mvelY*mod;
}
}
xvel *= 0.99;
yvel *= 0.99;
}
void display(int i, int u) {
float tcol = 0;
if (col > 255) col = 255;
if (i>0 && i<lwidth-1 && u>0 && u<lheight-1) {
tcol = (+ v[i][u+1].col
+ v[i+1][u].col
+ v[i+1][u+1].col*0.5
)*0.4;
tcol = (int)(tcol+col*0.5);
}
else {
tcol = (int)col;
}
fill(tcol, tcol, tcol);
rect(x,y,res,res);
}
}
@@ -1,264 +0,0 @@
/**
* Smoke
* by Glen Murphy.
*
* Drag the mouse across the image to move the particles.
* Code has not been optimised and will run fairly slowly.
*/
int res = 2;
int penSize = 30;
int lwidth;
int lheight;
int pnum = 30000;
vsquare[][] v;
vbuffer[][] vbuf;
particle[] p;
int pcount = 0;
int mouseXvel = 0;
int mouseYvel = 0;
int randomGust = 0;
int randomGustMax;
float randomGustX;
float randomGustY;
float randomGustSize;
float randomGustXvel;
float randomGustYvel;
void setup()
{
size(200, 200);
lwidth = width/res;
lheight = height/res;
v = new vsquare[lwidth+1][lheight+1];
vbuf = new vbuffer[lwidth+1][lheight+1];
p = new particle[pnum];
noStroke();
for(int i = 0; i < pnum; i++) {
p[i] = new particle(random(width/2-20,width/2+20),random(height-20,height));
}
for(int i = 0; i <= lwidth; i++) {
for(int u = 0; u <= lheight; u++) {
v[i][u] = new vsquare(i*res,u*res);
vbuf[i][u] = new vbuffer(i*res,u*res);
}
}
}
void draw()
{
background(#cccccc);
int axvel = mouseX-pmouseX;
int ayvel = mouseY-pmouseY;
mouseXvel = (axvel != mouseXvel) ? axvel : 0;
mouseYvel = (ayvel != mouseYvel) ? ayvel : 0;
if(randomGust <= 0) {
if(random(0,10)<1) {
randomGustMax = (int)random(5,12);
randomGust = randomGustMax;
randomGustX = random(0,width);
randomGustY = random(0,height-10);
randomGustSize = random(0,50);
if(randomGustX > width/2) {
randomGustXvel = random(-8,0);
} else {
randomGustXvel = random(0,8);
}
randomGustYvel = random(-2,1);
}
randomGust--;
}
for(int i = 0; i < lwidth; i++) {
for(int u = 0; u < lheight; u++) {
vbuf[i][u].updatebuf(i,u);
v[i][u].col = 0;
}
}
for(int i = 0; i < pnum-1; i++) {
p[i].updatepos();
}
for(int i = 0; i < lwidth; i++) {
for(int u = 0; u < lheight; u++) {
v[i][u].addbuffer(i, u);
v[i][u].updatevels(mouseXvel, mouseYvel);
v[i][u].display(i, u);
}
}
randomGust = 0;
}
class particle
{
float x;
float y;
float xvel;
float yvel;
float temp;
int pos;
particle(float xIn, float yIn) {
x = xIn;
y = yIn;
}
void reposition() {
x = width/2+random(-20,20);
y = random(height-10,height);
xvel = random(-1,1);
yvel = random(-1,1);
}
void updatepos() {
int vi = (int)(x/res);
int vu = (int)(y/res);
if(vi > 0 && vi < lwidth && vu > 0 && vu < lheight) {
v[vi][vu].addcolour(2);
float ax = (x%res)/res;
float ay = (y%res)/res;
xvel += (1-ax)*v[vi][vu].xvel*0.05;
yvel += (1-ay)*v[vi][vu].yvel*0.05;
xvel += ax*v[vi+1][vu].xvel*0.05;
yvel += ax*v[vi+1][vu].yvel*0.05;
xvel += ay*v[vi][vu+1].xvel*0.05;
yvel += ay*v[vi][vu+1].yvel*0.05;
v[vi][vu].yvel -= (1-ay)*0.003;
v[vi+1][vu].yvel -= ax*0.003;
if(v[vi][vu].yvel < 0) v[vi][vu].yvel *= 1.00025;
x += xvel;
y += yvel;
}
else {
reposition();
}
if(random(0,400) < 1) {
reposition();
}
xvel *= 0.6;
yvel *= 0.6;
}
}
class vbuffer
{
int x;
int y;
float xvel;
float yvel;
float pressurex = 0;
float pressurey = 0;
float pressure = 0;
vbuffer(int xIn,int yIn) {
x = xIn;
y = yIn;
pressurex = 0;
pressurey = 0;
}
void updatebuf(int i, int u) {
if(i>0 && i<lwidth && u>0 && u<lheight) {
pressurex = (v[i-1][u-1].xvel*0.5 + v[i-1][u].xvel + v[i-1][u+1].xvel*0.5 - v[i+1][u-1].xvel*0.5 - v[i+1][u].xvel - v[i+1][u+1].xvel*0.5);
pressurey = (v[i-1][u-1].yvel*0.5 + v[i][u-1].yvel + v[i+1][u-1].yvel*0.5 - v[i-1][u+1].yvel*0.5 - v[i][u+1].yvel - v[i+1][u+1].yvel*0.5);
pressure = (pressurex + pressurey)*0.25;
}
}
}
class vsquare {
int x;
int y;
float xvel;
float yvel;
float col;
vsquare(int xIn,int yIn) {
x = xIn;
y = yIn;
}
void addbuffer(int i, int u) {
if(i>0 && i<lwidth && u>0 && u<lheight) {
xvel += (vbuf[i-1][u-1].pressure*0.5
+vbuf[i-1][u].pressure
+vbuf[i-1][u+1].pressure*0.5
-vbuf[i+1][u-1].pressure*0.5
-vbuf[i+1][u].pressure
-vbuf[i+1][u+1].pressure*0.5
)*0.49;
yvel += (vbuf[i-1][u-1].pressure*0.5
+vbuf[i][u-1].pressure
+vbuf[i+1][u-1].pressure*0.5
-vbuf[i-1][u+1].pressure*0.5
-vbuf[i][u+1].pressure
-vbuf[i+1][u+1].pressure*0.5
)*0.49;
}
}
void updatevels(int mvelX, int mvelY) {
float adj;
float opp;
float dist;
float mod;
if(mousePressed) {
adj = x - mouseX;
opp = y - mouseY;
dist = sqrt(opp*opp + adj*adj);
if(dist < penSize) {
if(dist < 4) dist = penSize;
mod = penSize/dist;
xvel += mvelX*mod;
yvel += mvelY*mod;
}
}
if(randomGust > 0) {
adj = x - randomGustX;
opp = y - randomGustY;
dist = sqrt(opp*opp + adj*adj);
if(dist < randomGustSize) {
if(dist < res*2) dist = randomGustSize;
mod = randomGustSize/dist;
xvel += (randomGustMax-randomGust)*randomGustXvel*mod;
yvel += (randomGustMax-randomGust)*randomGustYvel*mod;
}
}
xvel *= 0.99;
yvel *= 0.98;
}
void addcolour(int amt) {
col += amt;
if(col > 196) col = 196;
}
void display(int i, int u) {
float tcol = 0;
if(i>0 && i<lwidth-1 && u>0 && u<lheight-1) {
tcol = (+ v[i][u+1].col
+ v[i+1][u].col
+ v[i+1][u+1].col*0.5
)*0.3;
tcol = (int)(tcol+col*0.5);
}
fill(255-tcol, 255-tcol, 255-tcol);
rect(x,y,res,res);
col = 0;
}
}