// A new variable, for gravity (i.e. acceleration). // We use a relatively small number (0.1) because this accelerations accumulates over time, increasing the speed. // Try changing this number to 2.0 and see what happens. PVector Origin, Scale; PVector[] wv = new PVector[3]; PVector[] sv = new PVector[3]; PFont fontA; float x, y; void setup() { size(600,600); smooth(); noLoop(); Origin = new PVector(150, 150); Scale = new PVector(50, 50); for(int i=0; i<3; i++) { wv[i] = new PVector(0, 0); sv[i] = new PVector(100, 100); } fontA = loadFont("ComicSansMS-Bold-32.vlw"); textAlign(CENTER); textFont(fontA, 8); } PVector World2Screen(PVector v){ // v.x=v.x*Scale.x+Origin.x; // v.y=height-v.y*Scale.y-Origin.y; v.mult(Scale); v.add(Origin); v.y=height-v.y; return v; } void draw() { background(200); fill(0); stroke(0); rectMode(CENTER); sv[0]=World2Screen(wv[0]); ellipse(sv[0].x, sv[0].y, 5, 5); text("O", sv[0].x-5, sv[0].y+10); wv[0].set(-1,0,0); wv[1].set(5,0,0); sv[0]=World2Screen(wv[0]); sv[1]=World2Screen(wv[1]); line(sv[0].x, sv[0].y, sv[1].x, sv[1].y); wv[0].set(0,-1,0); wv[1].set(0,5,0); sv[0]=World2Screen(wv[0]); sv[1]=World2Screen(wv[1]); line(sv[0].x, sv[0].y, sv[1].x, sv[1].y); for(int i=1; i<=5; i++) { wv[0].set(i,0,0); sv[0]=World2Screen(wv[0]); line(sv[0].x, sv[0].y-5, sv[0].x, sv[0].y+5); text(i, sv[0].x, sv[0].y+15); } for(x=0; x<5; x+=0.1) { y=ft(x); wv[0].set(x,y,0); sv[0]=World2Screen(wv[0]); rect(sv[0].x, sv[0].y, 1, 1); } } float ft(float x) { return x*x-x; }