home
|
featured sketches
|
gallery
|
write a sketch
|
community
|
Copy sketch
Printouts
// just type here // and click "save" when your done float inc = 0.0; int numTails = 20; Tail [] testTails = new Tail[numTails]; Tail [] badTails = new Tail[numTails]; void setup() { size(800, 600); stroke(255, 50); //smooth(); for (int i = 0; i < testTails.length; i++) { testTails[i] = new Tail(100+i*2, 6+i, sin(inc)/10.0 + sin(inc*1.2)/20.0); badTails[i] = new Tail (200+i*4, 20+i, sin(inc)/20.0 + sin(inc*1.2)/40.0); } //testTail = new Tail(20, 10, sin(inc)/10.0 + sin(inc*1.2)/20.0); } void draw() { background(0); inc += 0.01; float angle = sin(inc)/10.0 + sin(inc*1.2)/20.0; for (int j = 0; j < testTails.length; j++) { float changedAngle = angle+j; testTails[j].update(changedAngle/1.3); testTails[j].display(); badTails[j].update(changedAngle*2); badTails[j].display(); //testTails[j].update(changedAngle*2); //testTails[j].display(); } /* tail(18, 9, angle/1.3); tail(33, 12, angle); tail(44, 10, angle/1.3); tail(62, 5, angle); tail(88, 7, angle*2); */ } class Tail { float x, y; float angle; int units; //constructor Tail (float xpos, int u, float ang) { x=xpos; //y=ypos; angle=ang; units = u; } void update(float tempAngle) { angle=tempAngle; } void display() { pushMatrix(); translate(x, 100); for (int i = units; i>0; i--) { strokeWeight(i); line(0, 0, 0, -30);//was -8 //translate(0, -30);// same as above translate(40,-50); rotate(angle); } popMatrix(); } }
Sketches you submit on sketchPatch will be licensed under the
Creative Commons Attribution 3.0 Unported License
. If you upload code based on other people's work, please check the licence compatibility.
Click below to see an example
Get Started...
Copy this code into the text area to set up a basic sketch...
void setup() {
size(500,500);
}
void draw() {
background(200,30,90);
fill(20,40,150);
rect(100,100, 100,100);
}
Draw basic Shapes
Rectangle
Copy this code into the 'void draw ()' area of your code in the text area to draw a basic rectangle...
rect(100,100,100,100);
Triangle
Copy this code into the 'void draw ()' area of your code in the text area to draw a basic triangle...
triangle(30, 75, 58, 20, 86, 75);
Ellipse
Copy this code into the 'void draw ()' area of your code in the text area to draw a basic ellipse...
ellipse(56, 46, 55, 55);
Randomise
You can change how things look at random by using "random", all you need to do is specify the minimum and the maximum value you want.
Copy this code into the text area to randomly change the size and colour of your ellipse:
fill(random(0,255),20,200);
stroke(255,255,0);
ellipse(150, 150, random(10,150), 150);
Animate
You can animate your graphics by replacing numbers with "mouseX" , "mouseY" or "frameCount". In this example we change colors and shape size using the mouse:
background(20,30,mouseX);
fill(20,mouseY,150);
rect(100,100, 100,mouseX);
Drawing Tool
Copy this code into the 'void draw ()' area of your code to make a drawing tool...
fill(0,0,0);
noStroke();
ellipse(mouseX,mouseY, 2,2);
Then remove the line 'background();'
Repeat
You can repeat any piece of code by using a 'for loop'. A for loop changes a variable of a quantity you decide, until it reaches a number you want.
Example: add 10 each time to a variable called "i", until it gets to 200:
Copy this code into the text area to see a rectangle repeat across the sketch:
for (int i=0; i<200; i=i+10) {
rect(i,i, 100,100);
}
Ooops, found some glitches.
Write your sketch here
Check the Processing language
reference
(
most
of it works).
Need inspiration? Play with the examples in
the gallery
.
Title
Tags
Publish
(come on, let other people see your sketch!)
Your comments about the sketch
This is a sketch that reminds me of being on the beach with a load of angry crabs as a kid, so happy to recreate the experience with sin...