60 likes | 134 Views
Processing - Einführung. www.processing.org. Grundaufbau. import processing.core.PApplet ; public class Proc_Minimal extends PApplet { public void setup (){ size (1024, 768); frameRate(60.0f); } public void draw () { background (255); fill (255,0,0); rectMode ( CENTER);
E N D
Processing - Einführung www.processing.org
Grundaufbau • importprocessing.core.PApplet; • public class Proc_Minimal extends PApplet { • publicvoidsetup(){ • size(1024, 768); • frameRate(60.0f); • } • publicvoiddraw() • { • background(255); • fill(255,0,0); • rectMode(CENTER); • rect(mouseX, mouseY, 50, 50); • } • static public void main(String args[]) { • //PApplet.main(new String[] { "--present", "Proc_Minimal" }); • PApplet.main(new String[] {"Proc_Minimal" }); • } • } Von Papplet ableiten Initialisierung Loop-Methode Create a Window
Wichtige Methoden/Attribute Größe d. Fensters + Renderer • size(width, height) • optional (width, height, Renderer) • z.B. size(1024, 768, OPENGL) • mouseX, mouseY • pMouseX, pMouseY Aktuelle Mouseposition Mouseposition des letzten Frames
Zeichnen • ellipse(x, y, width, height) • auch: rect, triangle, line • fill(grey) • fill(r,g,b) • fill(r,g,b,a); • noFill() • stroke(grey) // 0-255 • stroke(r,g,b) • stroke(r,g,b,a) • noStroke() • strokeWeigth(pixel) • colorMode(mode, range) • colorMode(HSB. 255) //usehsv • colorMode(HSB, hRange, sRange, vRange) background(128); fill(204, 102, 0); rect(30, 20, 55, 55); background(128); stroke(204, 102, 0); rect(30, 20, 55, 55); noStroke(); colorMode(HSB, 100); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { stroke(i, j, 100); point(i, j); } }
Transformationen • transform(x, y) • rotate(radiants) • Useradiants(degree) toconverttoradiants • scale(factor)
Transformationen Why ? Becausesometimesit‘seasier! voidsetup() { size(400, 100); background(255); for (int i = 10; i < 350; i = i + 50) { house(i, 20); } } voidhouse(int x, int y) { pushMatrix(); translate(x, y); triangle(15, 0, 0, 15, 30, 15); rect(0, 15, 30, 30); rect(12, 30, 10, 15); popMatrix(); } voidhouse(int x, int y) { triangle(x + 15, y, x, y + 15, x + 30, y + 15); rect(x, y + 15, 30, 30); rect(x + 12, y + 30, 10, 15); } vs.