int Y_AXIS = 1; int X_AXIS = 2; color b1, b2; float angle; /*int weight1=30; int weight2=40; int distance1=144; int distance2=140;*/ Block block1; Block block2; void setup() { window.Processing.data.weight1=30; window.Processing.data.weight2=40; window.Processing.data.distance1=144; window.Processing.data.distance2=140; size(620,350); b1 = color(76,117,117); b2 = color(100,171,222); rectMode(CENTER); smooth(4); } void draw() { background(200,226,250); pushMatrix(); block1= new Block(color(78,121,135),-window.Processing.data.distance1,window.Processing.data.weight1,"left"); block2= new Block(color(78,92,135),window.Processing.data.distance2,window.Processing.data.weight2,"right"); translate(width/2, (height-120)); rotateMe(); noStroke(); rect(0,22, 26, 65); setGradient(-13,-10, 26/2, 65, b1, b2, X_AXIS); setGradient(0,-10, 26/2, 65, b2, b1, X_AXIS); fill(150,102,101); ellipse(0, 0, 10, 10); fill(204,148,147); ellipse(0, 0, 6, 6); popMatrix(); } void rotateMe(){ int chk1=round(window.Processing.data.distance1*window.Processing.data.weight1*9.8/100); int chk2=round(window.Processing.data.distance2*window.Processing.data.weight2*9.8/100); if (chk1 != chk2) { if (chk1 < chk2 && angle<23) { angle=angle+1; } if (chk1 > chk2 && angle>-23) { angle=angle-1; } } if(chk1==chk2){ if(angle<0){ angle=angle+1; } if(angle>0){ angle=angle-1; } } rotate(radians(angle)); fill(74,108,138); stroke(88); strokeWeight(1.7); rect(0,0, 400, 7,10,10,0,0); stroke(255,0,0); strokeWeight(.5); line(-200,-110,200,-110); line(-175,-120,-175,-100); line(-70,-120,-70,-100); line(175,-120,175,-100); line(70,-120,70,-100); line(-170,-115,-170,-105); line(-165,-115,-165,-105); line(-160,-115,-160,-105); line(-155,-115,-155,-105); line(-150,-115,-150,-105); line(-145,-115,-145,-105); line(-140,-115,-140,-105); line(-135,-115,-135,-105); line(-130,-115,-130,-105); line(-125,-115,-125,-105); line(-120,-115,-120,-105); line(-115,-115,-115,-105); line(-110,-115,-110,-105); line(-105,-115,-105,-105); line(-100,-115,-100,-105); line(-95,-115,-95,-105); line(-90,-115,-90,-105); line(-85,-115,-85,-105); line(-80,-115,-80,-105); line(-75,-115,-75,-105); line(0,-120,0,-100); line(170,-115,170,-105); line(165,-115,165,-105); line(160,-115,160,-105); line(155,-115,155,-105); line(150,-115,150,-105); line(145,-115,145,-105); line(140,-115,140,-105); line(135,-115,135,-105); line(130,-115,130,-105); line(125,-115,125,-105); line(120,-115,120,-105); line(115,-115,115,-105); line(110,-115,110,-105); line(105,-115,105,-105); line(100,-115,100,-105); line(95,-115,95,-105); line(90,-115,90,-105); line(85,-115,85,-105); line(80,-115,80,-105); line(75,-115,75,-105); textSize(14); fill(0, 102, 153); text("175 cm", -185, -127); text("70 cm", -80, -127); text("175 cm", 165, -127); text("70 cm", 60, -127); text("0", -4, -127); strokeWeight(1); fill(150,102,101); ellipse(0, 0, 10, 10); fill(204,148,147); ellipse(0, 0, 6, 6); block1.display(); block2.display(); rotate(-radians(angle)); } void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ) { noFill(); if (axis == Y_AXIS) { // Top to bottom gradient for (int i = y; i <= y+h; i++) { float inter = map(i, y, y+h, 0, 1); color c = lerpColor(c1, c2, inter); stroke(c); line(x, i, x+w, i); } } else if (axis == X_AXIS) { // Left to right gradient for (int i = x; i <= x+w; i++) { float inter = map(i, x, x+w, 0, 1); color c = lerpColor(c1, c2, inter); stroke(c); line(i, y, i, y+h); } } } class Block { color c; float xpos; float ypos; float boxWeight; String side; Block(color tempC, float tempXpos, float tempBoxWeight, String tempSide) { side = tempSide; c = tempC; boxWeight = tempBoxWeight; ypos = -3.5-(boxWeight*.6)/2; xpos=tempXpos; /*if(side=="left"){ xpos = -150+boxWeight/3;}else{ xpos = 150-boxWeight/3;}*/ } void display() { stroke(0); fill(c); rectMode(CENTER); rect(xpos,ypos,boxWeight/1.5,boxWeight*.6); stroke(46,242,141); strokeWeight(.9); line(block1.xpos,-120,block1.xpos,10); line(block2.xpos,-120,block2.xpos,10); strokeWeight(1); } }