You need a draw() loop. Then you can use variables instead of static numbers or maybe even methods like sin(), noise() etc. See all the examples that come with Processing, about 99% of these sketches are dynamic / interactive and use the setup() and draw() methods. Also check out the learning and reference sections on the website.
Note that you can post code on the forum as shown below.
Code Example
- color blue = color(0, 0, 255);
- color orange = color(255, 160, 0);
-
- void setup() {
- size(400, 700);
- rectMode(CENTER);
- smooth();
- }
-
- void draw() {
- background(0);
- strokeWeight(12);
- stroke(255);
- float h = height/8;
- for (int i=0; i<8; i++) {
- float y = (i*h*1.5+frameCount*2)%(height+h)-h;
- line(width/2, y, width/2, y+h);
- }
- drawCar(noise(frameCount*0.005)*width/2, sin(frameCount*0.005)*height/2+height/2, orange);
- drawCar(mouseX, mouseY, blue);
- }
-
- void drawCar(float x, float y, color c) {
- noStroke();
- fill(255);
- ellipse(x-22, y-30, 10, 10);
- ellipse(x+23, y-30, 10, 10);
- ellipse(x-22, y+30, 10, 10);
- ellipse(x+23, y+30, 10, 10);
- strokeWeight(2);
- stroke(255);
- fill(c);
- rect(x, y, 40, 70);
- line(x-20, y-35, x-10, y-50);
- line(x+20, y-35, x+10, y-50);
- line(x-10, y-50, x+10, y-50);
- line(x-20, y+35, x-10, y+50);
- line(x+20, y+35, x+10, y+50);
- line(x-10, y+50, x+10, y+50);
- }