globals [ disk piston rod old-diam ] to startup setup end to resize if drive-diam != old-diam [ set old-diam drive-diam ask disk [ set size .001 + drive-diam setxy (min-pxcor + size * .5 + 1) 0 ] ask rod [ set size .001 + max-pxcor - min-pxcor - ( [xcor] of disk - min-pxcor ) - .5 * [size] of disk - [size] of piston - 2 ] ] end to setup ca ask patches [ set pcolor white ] crt 1 [ set disk self set size drive-diam set old-diam drive-diam ] crt 1 [ set piston self set size 10] crt 1 [ set rod self ] ask disk [ set shape "disk" setxy (min-pxcor + size * .5 + 1) 0 set color brown set heading 90 ] ask rod [ ; set shape "linkage" set shape "rod" __set-line-thickness 1 set size max-pxcor - min-pxcor - ( [xcor] of disk - min-pxcor ) - .5 * [size] of disk - [size] of piston - 2 snap-to-tail disk set color blue set rod self set heading 90 ] ask piston [ set shape "piston" snap-to-tail-x rod set color green set piston self face disk ] ask rod [ face piston ] ;; __tie rod disk end to go ;; rotate the drive wheel resize every (1 / 30 ) [ ask disk [ rt speed + .1 ] ;; snap the end of the rod to the drive wheel ;; point the rod at the piston ask rod [ snap-to-tail disk set heading towards piston ] ;; push the piston to the location of the end of the rod ask piston [ snap-to-tail-x rod ] tick ] end to snap-to-tail [ agent ] setxy ( [ xcor + dx * size * .5 ] of agent ) ( [ ycor + dy * size * .5] of agent ) end to snap-to-tail-x [ agent ] set xcor ( [ xcor + dx * size ] of agent ) end @#$#@#$#@ GRAPHICS-WINDOW 183 15 743 296 27 12 10.0 1 10 1 1 1 0 0 0 1 -27 27 -12 12 1 1 1 ticks CC-WINDOW 5 310 752 405 Command Center 0 BUTTON 13 15 76 48 NIL setup NIL 1 T OBSERVER NIL NIL NIL NIL BUTTON 13 56 76 89 NIL go T 1 T OBSERVER NIL NIL NIL NIL SLIDER 84 56 176 89 speed speed 1 20 5 1 1 NIL HORIZONTAL SLIDER 84 15 176 48 drive-diam drive-diam 10 18 12 1 1 NIL HORIZONTAL @#$#@#$#@ WHAT IS IT? ----------- A simulation of a simple crank and piston. Inspired by a diagram from "507 Mechanical Movements" by Henry T. Brown, originally published in 1896. I was thinking about making a mechanical movement construction set, with drag-and-drop features... but then "crayon physics" happened, and I thought, "why bother?" @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 disk true 6 Circle -13840069 true true -1 -1 301 Circle -1 true false 29 29 242 Rectangle -13840069 true true 135 15 165 285 Rectangle -13840069 true true 15 135 285 165 Circle -13840069 true true 120 -30 60 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 link true 0 Line -7500403 true 150 0 150 300 link direction true 0 Line -7500403 true 150 150 30 225 Line -7500403 true 150 150 270 225 linkage true 6 Polygon -13840069 true true 135 120 120 135 120 180 180 180 180 135 165 120 165 165 135 165 135 135 165 135 165 -120 180 -135 180 -180 120 -180 120 -135 135 -120 135 -165 165 -165 165 -135 135 -135 piston true 6 Rectangle -13840069 true true 75 150 225 195 Rectangle -13840069 true true 75 210 225 450 Circle -13840069 true true 105 105 90 rod true 6 Line -13840069 true 150 150 150 -150 @#$#@#$#@ NetLogo 4.0.4 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@