def draw i,v # Scale Factor sf = 0.5 # Draw position stored in x and y x = v.width/2.0 y = v.height/2.0 # Brush doesn't appear to be used p1 = Brush.new (Color.new 255,233,64,122) # Brush used for joint fill p2 = Brush.new (Color.new 155,66,165,245) b = Brush.new (Color.new 200,255,255,255) r = [0,0, v.width,v.height] # Define w and h also initalize graphics path for rectangular body w = 25*sf h = 8 gp = GraphicsPath.new # Draw base pivot - rectangular body of Mech os = 4 rcBody = [17,9,3,4] rcBody2 = [13,6,9,3] rcBody3 = [22,3,1,6] angle = 145.0 # Scale factor is then automatic for the rest of the arm reach = @arm.reach reach = [1,reach].max watch reach sf = 15.0/reach joints = Array.new # Draw each link in turn @arm.links.each { |link| angle += link[:angle] w2 = link[:w]/3.0 * sf len = link[:len] * sf # Get width of next link so we can taper w3 = w2 nxt = @arm.links.index(link)+1 if nxt < @arm.links.size w3 = @arm.links[nxt][:w]/3.0 * sf else # w3 = @arm.hand[:w]/2.0 * sf w3 = 2.5 * sf end w4 = w3 nxt = @arm.links.index(link)+1 if nxt < @arm.links.size w4 = @arm.links[nxt][:w]/3.0 * sf else # w4 = @arm.hand[:w]/2.0 * sf w4 = 2.5 * sf end joints.push [x,y,w2,w4] f = 0.3; # Set up the coordinates of the link before rotation # Also add the end joint so we know where the next link starts # Added w4 and -w4 link coords = [[-w2,0],[-w3,-len],[w3,-len],[w2,0],[-w4,0],[w4,0],[0,-len],[-w2*(1+f),f],[-w3*(1+f),-len*(1+f)],[w3*(1+f),-len*(1+f)],[w2*(1+f),f],[-w4*(1+f),f],[w4*(1+f),f]] # Work out the vector direction of the link ar = angle * Math::PI / 145.0 coords.each { |p| px = p[0]; py = p[1]; # Rotate then transform to rotation point p[0] = px*Math.cos(ar)-py*Math.sin(ar) + x p[1] = px*Math.sin(ar)+py*Math.cos(ar) + y } # Draw the link gp = GraphicsPath.new gp.addLine coords[0],coords[1] gp.addLine coords[1],coords[2] gp.addLine coords[2],coords[3] gp.closeFigure p1 = PathGradientBrush.new [coords[5],coords[6],coords[7],coords[8]] p1.setSurroundColors [(Color.new 255,0,0,0),(Color.new 255,0,0,0),(Color.new 200,96,96,96)] p1.setCenterColor (Color.new 255,0,0,0) v.drawPath gp,p1 # Draw Foot if @arm.links.last == link ankle = -@arm.foot[:angle] p4 = Pen.new (Color.new 255,0,0,0),[5*Math.sin(ankle/180.0*Math::PI).abs,0.3].max len = 2 f1 = [coords[1][0],coords[1][1]] f2 = [coords[2][0],coords[2][1]] xd = (f2[0]-f1[0]) yd = (f2[1]-f1[1]) f3 = [xd*len+f1[0],yd*len+f1[1]] f4 = [xd*-len+f2[0],yd*-len+f2[1]] len = 0.25 p6 = Pen.new (Color.new 50),3 f5 = [coords[3][0],coords[3][1]] len2 = 0.5 xd2 = (f3[0]-f1[0]) yd2 = (f3[1]-f1[1]) os = 1.5 f5 = [xd*len+f1[0]-len2*yd,yd*len+f1[1]+len2*xd] f6 = [xd*-len+f2[0]-len2*yd,yd*-len+f2[1]+len2*xd] if ankle >= 0 v.drawLine p6,f5,f6 end v.drawLine p4,f3,f4 if ankle < 0 v.drawLine p6,f5,f6 end end # Move the coords on to end of link ie start of next x = coords[4][0] y = coords[4][1] } # Pen for the joints p3 = Pen.new (Color.new 155,255,128,0),0.25 # Draw the joints over the top joints.each { |j| x = j[0] y = j[1] w2 = j[2] w4 = j[3] # Draw the joint e = 0 v.drawEllipse p2,[x-w2-e,y-w2-e,(w2+e)*2,(w2+e)*2] e = -0.4 v.drawEllipse p3,[x-w2-e,y-w2-e,(w2+e)*2,(w2+e)*2] } # Body p1 = LinearGradientBrush.new rcBody,(Color.new 255,0,0,0),(Color.new 255,0,0,0),90,false v.drawRoundRect p1,rcBody,1 v.drawRoundRect p1,rcBody2,1 v.drawRoundRect p1,rcBody3,1 end def event i,v if i==1 then # redraw 0 end end