PGraphics backDrop; polBar polarBar; polPlot polarPlot; rectBar rectangularBar; rectPlot rectangularPlot; int windowSize=300; float scalingFactor=windowSize/6.28; float theta=0; float graphR; float graphX; float graphY; float lastGraphX=0; float lastGraphY=0; void setup () { frameRate(30); size(windowSize,2*windowSize); backDrop = createGraphics(width, height,JAVA2D); backDrop.beginDraw(); backDrop.background(255,255,255); backDrop.endDraw(); smooth(); rectangularPlot = new rectPlot(); polarPlot = new polPlot(); } void draw() { float graphR=scalingFactor*(.5+1.5*cos(3*theta)); float graphX=windowSize/2 + graphR*cos(theta); float graphY=windowSize/2 - graphR*sin(theta); background(255,55,55); { if ((abs(graphX-lastGraphX)+abs(graphY-lastGraphY))>3) { backDrop.beginDraw(); backDrop.noStroke(); backDrop.smooth(); backDrop.fill(255,255,255); backDrop.ellipse(graphX, graphY+windowSize,4,4); backDrop.ellipse(scalingFactor*theta, 3*scalingFactor-graphR,4,4); backDrop.fill(-10*graphR,50,3*graphR); backDrop.ellipse(graphX, graphY+windowSize, 3, 3); backDrop.ellipse(scalingFactor*theta, 3*scalingFactor-graphR, 3, 3); //backDrop.fill(255,255,255,3); //backDrop.rect(0,0,windowSize, 2*windowSize); backDrop.modified=true; backDrop.endDraw(); lastGraphX=graphX; lastGraphY=graphY; } } image(backDrop,0,0); rectangularPlot.draw(); polarPlot.draw(); polarBar = new polBar(graphX,graphY); polarBar.draw(); rectangularBar = new rectBar(graphR); rectangularBar.draw(); if (mousePressed == false) theta = theta+.01; if (theta>2*PI) { theta=0; lastGraphX=0; lastGraphY=0; } } class rectPlot { void draw () { strokeWeight(1); stroke(200,200,200); pushMatrix(); for(int counter=1; counter<12; counter++) { translate(0,scalingFactor/2); line(0,0,windowSize,0); } popMatrix(); stroke(50,50,50); line(0,3*scalingFactor,windowSize,3*scalingFactor); } } class polPlot { void draw () { pushMatrix(); translate(0,windowSize); strokeWeight(1); stroke(200,200,200); noFill(); line(windowSize/2,windowSize/2,windowSize,windowSize/2); ellipse(windowSize/2,windowSize/2, scalingFactor,scalingFactor); ellipse(windowSize/2,windowSize/2, 2*scalingFactor,2*scalingFactor); ellipse(windowSize/2,windowSize/2, 3*scalingFactor,3*scalingFactor); ellipse(windowSize/2,windowSize/2, 4*scalingFactor,4*scalingFactor); ellipse(windowSize/2,windowSize/2, 5*scalingFactor,5*scalingFactor); } } class rectBar { rectBar(float _graphR ) { graphR= _graphR; } void draw() { strokeWeight(1); stroke(0,0,200,100); line(scalingFactor*theta,0.5*scalingFactor,scalingFactor*theta,3*scalingFactor); stroke(200,0,0,100); line(scalingFactor*theta,3*scalingFactor,scalingFactor*theta,5.5*scalingFactor); strokeWeight(1); stroke(150,150,250); fill(255,255,255); strokeWeight(5); line(scalingFactor*theta, 3*scalingFactor, scalingFactor*theta, 3*scalingFactor-graphR); fill(-10*graphR,50,3*graphR); ellipse(scalingFactor*theta,3*scalingFactor-graphR,11,11); } } class polBar { float graphX, graphY; polBar ( float _graphX, float _graphY ) { graphX = _graphX; graphY = _graphY; } void draw () { float xPos = 2.5*scalingFactor*cos(theta); float yPos = 2.5*scalingFactor*sin(theta); // the directional lines strokeWeight(1); stroke(0,0,200,100); line(windowSize/2,windowSize/2,windowSize/2+xPos,windowSize/2-yPos); stroke(200,0,0,100); line(windowSize/2,windowSize/2,windowSize/2-xPos,windowSize/2+yPos); // the moving bar strokeWeight(5); stroke(150,150,250); // fill(255,0,0); fill(-10*graphR,50,3*graphR); line(windowSize/2,windowSize/2,graphX,graphY); ellipse(graphX,graphY,11,11); popMatrix(); } }