Skip to content
This repository has been archived by the owner on Jun 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #7 from jbuck/basic
Browse files Browse the repository at this point in the history
Add basic examples
  • Loading branch information
jbuck committed Oct 27, 2011
2 parents 4193a28 + 81edf0e commit ba33cc3
Show file tree
Hide file tree
Showing 55 changed files with 1,035 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
*~
.DS_Store
30 changes: 30 additions & 0 deletions examples/basic/arm.pde
@@ -0,0 +1,30 @@
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);
}
95 changes: 95 additions & 0 deletions examples/basic/arraylist.pde
@@ -0,0 +1,95 @@
ArrayList balls;
int ballWidth = 48;

void setup() {
size(200, 200);
smooth();
noStroke();

// Create an empty ArrayList
balls = new ArrayList();

// Start by adding one element
balls.add(new Ball(width/2, 0, ballWidth));
}

void draw() {
background(255);

// With an array, we say balls.length, with an ArrayList, we say balls.size()
// The length of an ArrayList is dynamic
// Notice how we are looping through the ArrayList backwards
// This is because we are deleting elements from the list
for (int i = balls.size()-1; i >= 0; i--) {
// An ArrayList doesn't know what it is storing so we have to cast the object coming out
Ball ball = (Ball) balls.get(i);
ball.move();
ball.display();
if (ball.finished()) {
// Items can be deleted with remove()
balls.remove(i);
}

}

}

void mousePressed() {
// A new ball object is added to the ArrayList (by default to the end)
balls.add(new Ball(mouseX, mouseY, ballWidth));
}




// Simple bouncing ball class

class Ball {

float x;
float y;
float speed;
float gravity;
float w;
float life = 255;

Ball(float tempX, float tempY, float tempW) {
x = tempX;
y = tempY;
w = tempW;
speed = 0;
gravity = 0.1;
}

void move() {
// Add gravity to speed
speed = speed + gravity;
// Add speed to y location
y = y + speed;
// If square reaches the bottom
// Reverse speed
if (y > height) {
// Dampening
speed = speed * -0.8;
y = height;
}
}

boolean finished() {
// Balls fade out
life--;
if (life < 0) {
return true;
} else {
return false;
}
}

void display() {
// Display the circle
fill(0,life);
//stroke(0,life);
ellipse(x,y,w,w);
}
}

13 changes: 13 additions & 0 deletions examples/basic/color.pde
@@ -0,0 +1,13 @@
size(200, 200);
noStroke();

color inside = color(204, 102, 0);
color middle = color(204, 153, 0);
color outside = color(153, 51, 0);

fill(outside);
rect(0, 0, 200, 200);
fill(middle);
rect(40, 60, 120, 120);
fill(inside);
rect(60, 90, 80, 80);
44 changes: 44 additions & 0 deletions examples/basic/colorwheel.pde
@@ -0,0 +1,44 @@
int segs = 12;
int steps = 6;
float rotAdjust = TWO_PI / segs / 2;
float radius;
float segWidth;
float interval = TWO_PI / segs;

void setup() {
size(200, 200);
background(127);
smooth();
ellipseMode(RADIUS);
noStroke();
// make the diameter 90% of the sketch area
radius = min(width, height) * 0.45;
segWidth = radius / steps;

drawShadeWheel();
}

void drawShadeWheel() {
for (int j = 0; j < steps; j++) {
color[] cols = {
color(255-(255/steps)*j, 255-(255/steps)*j, 0),
color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0),
color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0),
color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0),
color(255-(255/steps)*j, 0, 0),
color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j),
color(255-(255/steps)*j, 0, 255-(255/steps)*j),
color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j),
color(0, 0, 255-(255/steps)*j),
color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j),
color(0, 255-(255/steps)*j, 0),
color((255/2)-((255/2)/steps)*j, 255-(255/steps)*j, 0)
};
for (int i = 0; i < segs; i++) {
fill(cols[i]);
arc(width/2, height/2, radius, radius,
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
}
33 changes: 33 additions & 0 deletions examples/basic/coollines.pde
@@ -0,0 +1,33 @@
int i = 0;
void setup() { // this is run once.

// set the background color
background(255);

// canvas size (Integers only, please.)
size(300, 300);

// smooth edges
smooth();

// limit the number of frames per second
frameRate(30);

// set the width of the line.
strokeWeight(12);
}

void draw() { // this is run repeatedly.
// set the color
stroke(random(50), random(255), random(255), 100);

// draw the line
line(i, 0, random(0, width), height);

// move over a pixel
if (i < width) {
i++;
} else {
i = 0;
}
}
27 changes: 27 additions & 0 deletions examples/basic/coordinatesystem.pde
@@ -0,0 +1,27 @@
size(450, 450);

background(255, 255, 255);

fill(0);
text("(0, 0)", 0, 25);
text("X", width/2, 13);
text("Y", 0, height/2);

strokeWeight(2);
stroke(255, 50, 50);
line(30, 0, 30, height);
line(0, 30, width, 30);

strokeWeight(1);
stroke(0);
for (int i = 50; i < width; i = i + 20) {
line(i, 30, i, height);
line(30, i, width, i);
}

for (int i = 0; i <= 20; i++) {
textAlign(CENTER, BASELINE);
text(i, 40 + (i * 20), 25);
textAlign(RIGHT, BASELINE);
text(i, 25, 45 + (i * 20));
}
17 changes: 17 additions & 0 deletions examples/basic/createimage.pde
@@ -0,0 +1,17 @@
PImage img;

void setup()
{
size(200, 200);
img = createImage(120, 120, ARGB);
for(int i=0; i < img.pixels.length; i++) {
img.pixels[i] = color(0, 90, 102, i%img.width * 2);
}
}

void draw()
{
background(204);
image(img, 33, 33);
image(img, mouseX-60, mouseY-60);
}
Binary file added examples/basic/eames.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions examples/basic/easing.pde
@@ -0,0 +1,30 @@
float x;
float y;
float targetX, targetY;
float easing = 0.05;

void setup()
{
size(200, 200);
smooth();
noStroke();
}

void draw()
{
background( 51 );

targetX = mouseX;
float dx = targetX - x;
if(abs(dx) > 1) {
x += dx * easing;
}

targetY = mouseY;
float dy = targetY - y;
if(abs(dy) > 1) {
y += dy * easing;
}

ellipse(x, y, 33, 33);
}
13 changes: 13 additions & 0 deletions examples/basic/fillstrokeweight.pde
@@ -0,0 +1,13 @@
size(200, 200);
background(255);

rect(5, 5, 90, 90);

fill(50, 200, 50);
rect(105, 5, 90, 90);

strokeWeight(10);
rect(10, 110, 80, 80);

stroke(50, 50, 150);
rect(110, 110, 80, 80);
22 changes: 22 additions & 0 deletions examples/basic/functions.pde
@@ -0,0 +1,22 @@
void setup() {
size(450, 450);
background(51);
noStroke();
smooth();
noLoop();
}

void draw() {
drawTarget(250, 250, 400, 10);
drawTarget(152, 16, 200, 3);
drawTarget(100, 144, 180, 5);
}

void drawTarget(int xloc, int yloc, int size, int num) {
float grayvalues = 255/num;
float steps = size/num;
for (int i = 0; i < num; i++) {
fill(i*grayvalues);
ellipse(xloc, yloc, size-i*steps, size-i*steps);
}
}
2 changes: 2 additions & 0 deletions examples/basic/google-code-prettify/lang-apollo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions examples/basic/google-code-prettify/lang-clj.js
@@ -0,0 +1,18 @@
/*
Copyright (C) 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var a=null;
PR.registerLangHandler(PR.createSimpleLexer([["opn",/^[([{]+/,a,"([{"],["clo",/^[)\]}]+/,a,")]}"],["com",/^;[^\n\r]*/,a,";"],["pln",/^[\t\n\r \xa0]+/,a,"\t\n\r \xa0"],["str",/^"(?:[^"\\]|\\[\S\s])*(?:"|$)/,a,'"']],[["kwd",/^(?:def|if|do|let|quote|var|fn|loop|recur|throw|try|monitor-enter|monitor-exit|defmacro|defn|defn-|macroexpand|macroexpand-1|for|doseq|dosync|dotimes|and|or|when|not|assert|doto|proxy|defstruct|first|rest|cons|defprotocol|deftype|defrecord|reify|defmulti|defmethod|meta|with-meta|ns|in-ns|create-ns|import|intern|refer|alias|namespace|resolve|ref|deref|refset|new|set!|memfn|to-array|into-array|aset|gen-class|reduce|map|filter|find|nil?|empty?|hash-map|hash-set|vec|vector|seq|flatten|reverse|assoc|dissoc|list|list?|disj|get|union|difference|intersection|extend|extend-type|extend-protocol|prn)\b/,a],
["typ",/^:[\dA-Za-z-]+/]]),["clj"]);
2 changes: 2 additions & 0 deletions examples/basic/google-code-prettify/lang-css.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/basic/google-code-prettify/lang-go.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/basic/google-code-prettify/lang-hs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/basic/google-code-prettify/lang-lisp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/basic/google-code-prettify/lang-lua.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/basic/google-code-prettify/lang-ml.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/basic/google-code-prettify/lang-n.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/basic/google-code-prettify/lang-proto.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/basic/google-code-prettify/lang-scala.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/basic/google-code-prettify/lang-sql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/basic/google-code-prettify/lang-tex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/basic/google-code-prettify/lang-vb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba33cc3

Please sign in to comment.