1)
size(800,600);
background(0,26,130);
{noStroke();
fill(250,100,100);
quad(0,600,0,500,800,500,800,600);}
fill(255,255,255);
stroke(2);
ellipse(400, 300, 600, 600);
line(400,60,400,500);
fill(125,125,0);
noStroke();{
ellipse(300,50,150,50);
ellipse(500,50,150,50);
fill(120,0,125);
triangle(400,60,150,250,650,250);
fill(0,125,150);
quad(0,120,188,0,89,600,400,466);
quad(800,120,622,0,711,600,400,466);
}
fill(0,0,0);
ellipse(400,500,50,50);
This is a static image using multiple shapes (3 quadrilaterals, 3 ellipses, 1 traingle, and a line, with a random color assortment).
2) In order to make this static image active, and have it refresh at 60fps, you take any background and size functions, and put them in the void setup() function using {}, then you put all shapes and put them into the void draw() function using {}. This forces the image to refresh rather than just be drawn, though it makes the exact same image in this case.
void setup(){
size(800,600);
background(0,26,130);
}
void draw() {
{noStroke();
fill(250,100,100);
quad(0,600,0,500,800,500,800,600);}
fill(255,255,255);
stroke(2);
ellipse(400, 300, 600, 600);
line(400,60,400,500);
fill(125,125,0);
noStroke();{
ellipse(300,50,150,50);
ellipse(500,50,150,50);
fill(120,0,125);
triangle(400,60,150,250,650,250);
fill(0,125,150);
quad(0,120,188,0,89,600,400,466);
quad(800,120,622,0,711,600,400,466);
}
fill(0,0,0);
ellipse(400,500,50,50);
}
3) As an example of the beginShape() and endShape() functions, I made this and gave it a red background:
It uses 22 vertexes, and began by plotting out the right side, then looping back to draw a mirror image on the left side. The red is extra.
size(1000,1000);
background(255,0,0);
beginShape();
vertex(500,100);
vertex(505,250);
vertex(575,300);
vertex(550,325);
vertex(555,350);
vertex(560,375);
vertex(620,400);
vertex(570,410);
vertex(550,420);
vertex(550,475);
vertex(560,500);
vertex(500,550);
vertex(440,500);
vertex(450,475);
vertex(450,420);
vertex(430,410);
vertex(380,400);
vertex(440,375);
vertex(445,350);
vertex(450,325);
vertex(425,300);
vertex(495,250);
endShape(CLOSE);
4) Using a "for loop" to draw 15 rectangles:
I chose to do the placement using variables, though in an increasing manner, and used random color assignment (between cyan and lime green), using a random interger.
size(1000,1000);
background(255,255,255);
smooth();
for (int i = 50; i < 750; i += 50) {
float y = random(39);
if(y < 20){
fill(0,255,255);
}else{
fill(51,255,51);
}
quad(i, 40, i + 50, 40, i+50,i+90, i, i+90);
}
This concludes the playing around with Processing Blog.
~~Nathaniel Hendrix
No comments:
Post a Comment