# Crazy Vectors

Model was written in NetLogo 5.0.2
•
Viewed 388 times
•
Downloaded 26 times
•
Run 0 times

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## Comments and Questions

Please start the discussion about this model!
(You'll first need to log in.)

Click to Run Model

extensions [bitmap qtj] breed [vectors vector] breed [balls ball] vectors-own [vector-size head-turtle] balls-own [speed energy last-collision last-vector] patches-own [cluster previous-color] globals [ circle-patches line-patches wall-patches circle-clusters line-clusters max-tick-delta background-color] to reset-image clear-all set background-color 9.9 ask patches [set cluster nobody set pcolor background-color] set-default-shape balls "circle 2" set-default-shape vectors "circle 2" reset-ticks end to reset-background ask patches [set pcolor background-color] end to import-image let myimage "images/random-balls.png" if image-file = "random-balls" [set myimage "images/random-balls.png"] if image-file = "force-field" [set myimage "images/force-field.png"] if image-file = "current" [set myimage "images/current.png"] import-pcolors myimage end to normalize-colors set circle-patches patches with [(pcolor > 11 and pcolor < 18) or (pcolor > 121 and pcolor < 128) or (pcolor > 131 and pcolor < 138)] set line-patches patches with [shade-of? blue pcolor = true] set wall-patches patches with [pcolor >= 0 and pcolor <= 1] reset-background ask circle-patches [set pcolor 15] ask line-patches [set pcolor 105] ask wall-patches [set pcolor 0] end to detect-clusters let drawing-patches (patch-set circle-patches line-patches) if any? drawing-patches with [cluster = nobody] [ let counter 1 set circle-clusters [] set line-clusters [] loop [ let seed one-of drawing-patches with [cluster = nobody] if seed = nobody [ stop ] ask seed [ set cluster counter grow-cluster ifelse pcolor = red [set circle-clusters lput counter circle-clusters] [set line-clusters lput counter line-clusters] ] set counter counter + 1 ] ] end to grow-cluster ;; patch procedure ;ask neighbors with [(cluster = nobody) and ask patches in-radius 2 with [(cluster = nobody) and ;ask neighbors4 with [(cluster = nobody) and (pcolor = [pcolor] of myself)] [ set cluster [cluster] of myself grow-cluster ] end to convert-to-turtles reset-background ask wall-patches [set pcolor 0] foreach circle-clusters [ if count (patches with [cluster = ?]) > 5 [generate-circles patches with [cluster = ?]] ] foreach line-clusters [ if count (patches with [cluster = ?]) > 5 [generate-lines patches with [cluster = ?] ?] ] end to generate-circles [shape-patch-set] let max-x-point max [pxcor] of shape-patch-set let min-x-point min [pxcor] of shape-patch-set let max-y-point max [pycor] of shape-patch-set let min-y-point min [pycor] of shape-patch-set let radius (max-x-point - min-x-point + max-y-point - min-y-point) / 4 ; find approximate radius for the circle let center-x ((max-x-point + min-x-point) / 2) let center-y ((max-y-point + min-y-point) / 2) let center-patch patch center-x center-y ;center of circle let std-to-center (standard-deviation ([distance center-patch] of shape-patch-set) / (mean [distance center-patch] of shape-patch-set)) if std-to-center < std-to-center-threshold [ create-balls 1 [ setxy center-x center-y set size (radius * 2) set color red set speed 0 set heading 0 set last-vector -1 * vector-refresh ] ] end to generate-lines [shape-patch-set cluster_] let max-x-point max [pxcor] of shape-patch-set let min-x-point min [pxcor] of shape-patch-set let max-y-point max [pycor] of shape-patch-set let min-y-point min [pycor] of shape-patch-set let center-patch patch ((max-x-point + min-x-point) / 2) ((max-y-point + min-y-point) / 2) let end-patch1 (max-one-of shape-patch-set [distance center-patch]) ;end-patches are the tip and end patches let end-patch2 (max-one-of shape-patch-set [distance end-patch1]) let head-patch max-one-of (patch-set end-patch1 end-patch2) [count shape-patch-set in-radius 3] ;with the arrow shape there are more patches let bottom-patch min-one-of (patch-set end-patch1 end-patch2) [count shape-patch-set in-radius 3] ;the tip-patch has the arrow head let new-vector nobody create-vectors 1 [ setxy [pxcor] of bottom-patch [pycor] of bottom-patch set size 2 set color blue set vector-size sqrt ((max-x-point - min-x-point) ^ 2 + (max-y-point - min-y-point) ^ 2) set new-vector self ] ask head-patch [sprout 1 [ set shape "default" set size 5 set color blue set heading (180 + towards new-vector) create-link-from new-vector [set shape "vector" set color blue] ask new-vector [set head-turtle myself set heading [heading] of myself] ] ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Below is the physics simulator. The code above is used for recognizing shapes and converting them into turtles ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to setup ; set max-tick-delta 2;0.1073 ask balls [set speed 0 set heading 0] ;set tick-delta 1 reset-ticks end to go ask balls [move] tick-advance tick-delta end to move let radius size / 2 ifelse pen-down? = true [pendown][penup] let vector-range (radius) + 5 let is-vector? (any? vectors in-radius vector-range and (ticks - last-vector > vector-refresh)) let is-friction? (friction > 0) if is-vector? or gravity > 0 [ let x-speed speed * cos heading let y-speed speed * sin heading if is-vector? [ ask vectors in-radius vector-range [ set x-speed (x-speed + (vector-size * (cos heading) * tick-delta) / [size] of myself) set y-speed (y-speed + (vector-size * (sin heading) * tick-delta) / [size] of myself) if remove-vectors-on-hit? = true [ask head-turtle [die] die] ] set last-vector ticks ] if gravity > 0 [ set x-speed (x-speed - 0.0001 * gravity) ] set speed sqrt (x-speed ^ 2 + y-speed ^ 2) if not (x-speed = 0 and y-speed = 0) [set heading atan y-speed x-speed] ] if friction > 0 [set speed speed * (1 - friction)] ;;;BOUNCE if (not horizontal-wrap? and abs xcor + radius >= max-pxcor) or ([pcolor] of patch (xcor + radius) ycor = 0) or ([pcolor] of patch (xcor - radius) ycor = 0) [set heading (-1 * heading) ] if (not vertical-wrap? and abs ycor + radius >= max-pycor) or ([pcolor] of patch xcor (ycor + radius) = 0) or ([pcolor] of patch xcor (ycor - radius) = 0) [set heading (180 - heading) ] fd speed * tick-delta end

There is only one version of this model, created almost 11 years ago by Firat Soylu.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

Crazy Vectors.png | preview | Preview for 'Crazy Vectors' | over 10 years ago, by Firat Soylu | Download |

This model does not have any ancestors.

This model does not have any descendants.