/** * Cycloid 1 * * For messing around with cycloids of various sorts * * Matthew Conroy ( conroy (at) math dot washington dot edu ) **/ HScrollbar hs1, hs2, hs3, hs4; PImage top, bottom; // Two image to load int topWidth, bottomWidth; // The width of the top and bottom images float lasta, lastb; // to keep track of whether things have changed int lastm; float[] coeffs = new float[30]; //array for the coefficients of the taylor polynomials void setup() { size(700, 560); noStroke(); //hs1 = new HScrollbar(0, height-80, width, 10, 3*5+1); hs2 = new HScrollbar(0, height-60, width, 10, 3*5+1,50); hs3 = new HScrollbar(0, height-40, width, 10, 3*5+1,50); hs4 = new HScrollbar(0, height-20, width, 10, 3*5+1,50); PFont fontA = loadFont("CourierNew36.vlw"); textFont(fontA, 18); } void draw() { background(255); // Get the position of the top scrollbar // and convert to a value to display the top image //float Pos1 = hs1.getPos(); float Pos2 = hs2.getPos(); float Pos3 = hs3.getPos(); float Pos4 = hs4.getPos(); float xx=0; float yy=0; float xxLast=0,yyLast=0,xx0=0,yy0=0; float scale=7.5; // float a=0.+1.0*Pos1/width; // float b=(Pos2/width-1./2.)*2*3.1415926535; float x1 = Pos2; float r1 = 5+Pos3/5.; float r2 = 5+Pos4/5.; smooth(); strokeWeight(1); //draw axes stroke(33); line(0,height/2,width,height/2); //line(width/2,0,width/2,height); //draw cycloid int numPoints=1000; for(int i = 0; i0) { line(xx,yy,xxLast,yyLast); } else { xx0=xx; yy0=yy; } xxLast=xx; yyLast=yy; } //draw rolling circle numPoints=100; for(int i=0; i0) { line(xx,yy,xxLast,yyLast); } else { xx0=xx; yy0=yy; } xxLast=xx; yyLast=yy; } line(xxLast,yyLast,xx0,yy0); //draw the dot stroke(77); xx = x1+r2*cos(-(x1-width/2.)/r1-3.1415926/2.); yy = height/2.-(r1+r2*sin(-(x1-width/2.)/r1-3.1415926/2.)); ellipse(xx,yy,5,5); line(x1,height/2.-r1,xx,yy); stroke(128); //hs1.update(); hs2.update(); hs3.update(); hs4.update(); //hs1.draw(); hs2.draw(); hs3.draw(); hs4.draw(); //words //text("a="+int(a*100)/100.+" b="+int(b*10)/10.+" m="+z1Fact+" n="+z2Fact,10,height-100); fill(0); //text("a="+int(100*a)/100.,10,height-100); //text("b="+int(100*b)/100.,10+width*0.25,height-100); //text("b="+int(100*mm)/100.,10+width*0.5,height-60); //text("n="+n,10+width*0.75,height-60); // lasta=a; // lastb=b; // lastm=m; //} // end of if things have changed //println(hs1.getPos()); } class HScrollbar { int swidth, sheight; // width and height of bar int xpos, ypos; // x and y position of bar float spos, newspos; // x position of slider int sposMin, sposMax; // max and min values of slider int loose; // how loose/heavy boolean over; // is the mouse over the slider? boolean locked; float ratio; HScrollbar (int xp, int yp, int sw, int sh, int l, int sposition) { swidth = sw; sheight = sh; int widthtoheight = sw - sh; ratio = (float)sw / (float)widthtoheight; xpos = xp; ypos = yp-sheight/2; // note the width and height of the slider are both sheight spos = xpos+sheight/2.+sposition/100.*(swidth-sheight)-sheight/2.; newspos = spos; sposMin = xpos; sposMax = xpos + swidth - sheight; loose = l; } void update() { if(over()) { over = true; } else { over = false; } if(mousePressed && over) { locked = true; } if(!mousePressed) { locked = false; } if(locked) { newspos = constrain(mouseX-sheight/2, sposMin, sposMax); } if(abs(newspos - spos) > 1) { spos = spos + (newspos-spos)/loose; } } int constrain(int val, int minv, int maxv) { return min(max(val, minv), maxv); } boolean over() { if(mouseX > xpos && mouseX < xpos+swidth && mouseY > ypos && mouseY < ypos+sheight) { return true; } else { return false; } } void draw() { fill(255); rect(xpos, ypos, swidth, sheight); if(over || locked) { fill(128); } else { fill(0); } rect(spos, ypos, sheight, sheight); } float getPos() { // convert spos to be values between // 0 and the total width of the scrollbar return spos * ratio; } }