/** * Hypocycloid 1 * * Hypocyloids and hypocycloid-like curves. * * Matthew Conroy ( jumbo (at) madandmoonly com (you know where the dot goes)) **/ HScrollbar hs1, hs2, hs3, hs4; PImage top, bottom; // Two image to load int topWidth, bottomWidth; // The width of the top and bottom images void setup() { size(500, 560); noStroke(); hs1 = new HScrollbar(0, height-80, width, 10, 3*5+1); hs2 = new HScrollbar(0, height-60, width, 10, 3*5+1); hs3 = new HScrollbar(0, height-40, width, 10, 3*5+1); hs4 = new HScrollbar(0, height-20, width, 10, 3*5+1); 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()-width/2.; float Pos2 = hs2.getPos()-width/2.; float Pos3 = hs3.getPos(); float Pos4 = hs4.getPos(); //loadPixels(); float xx=0; float yy=0; float xxLast=0,yyLast=0,xx0=0,yy0=0; float a=Pos1*0.5; float b=Pos2*0.5; int z1Fact = 1+int(Pos3/50); int z2Fact = 1+int(Pos4/50); smooth(); strokeWeight(1); int numPoints=1000; for(int i = 0; i0) { line(xx,yy,xxLast,yyLast); } else { xx0=xx; yy0=yy; } xxLast=xx; yyLast=yy; } line(xxLast,yyLast,xx0,yy0); //updatePixels(); 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(a*5./width*100)/100.,10,height-100); text("b="+int(b*5./width*100)/100.,10+width*0.25,height-100); text("m="+z1Fact,10+width*0.5,height-100); text("n="+z2Fact,10+width*0.75,height-100); //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) { swidth = sw; sheight = sh; int widthtoheight = sw - sh; ratio = (float)sw / (float)widthtoheight; xpos = xp; ypos = yp-sheight/2; spos = xpos + swidth/2 - 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; } }