Permalink
Browse files

Test EOL

  • Loading branch information...
1 parent 579f166 commit 55ebef575a7da1d977ab3a6dc728067db1da2f5f blitz-research committed Apr 1, 2013
Showing with 9,223 additions and 9,225 deletions.
  1. +1 −0 .gitattributes
  2. +0 −3 README.TXT
  3. +118 −118 bananas/Richard_Betson/TileImage/TileImage.monkey
  4. +321 −321 bananas/Richard_Betson/glfw_diffusion/glfw_diffusion_example.monkey
  5. +378 −378 bananas/Richard_Betson/line_v_circle_collision/line_v_circle_collision.monkey
  6. +102 −102 bananas/Richard_Betson/mirror_fx_transform/mirror_fx_transform.monkey
  7. +469 −469 bananas/Richard_Betson/simple_verlet_physics/simple_verlet_physics.monkey
  8. +271 −271 bananas/beaker/angelfont_example/angelfont_example.data/angel3.fnt
  9. +96 −96 bananas/beaker/angelfont_example/angelfont_example.data/angel3.txt
  10. +271 −271 bananas/beaker/angelfont_example/angelfont_example.data/angel_verdana.fnt
  11. +262 −262 bananas/beaker/angelfont_example/angelfont_example.data/angel_verdana.txt
  12. +199 −199 bananas/beaker/angelfont_example/angelfont_example.data/pagedfont.fnt
  13. +954 −954 bananas/beaker/angelfont_example/config.monkey
  14. +27 −27 bananas/beaker/angelfont_example/kernpair.monkey
  15. +124 −124 bananas/difference/champagne/champagne.monkey
  16. +487 −487 bananas/hitoro/autofit/autofit.monkey
  17. +91 −91 bananas/hitoro/autofit/autofitdemo.monkey
  18. +33 −33 bananas/hitoro/autofit/info.txt
  19. +51 −51 bananas/hitoro/autofit/simpledemo.monkey
  20. +88 −88 bananas/hitoro/basicgame/basicgame.monkey
  21. +23 −23 bananas/hitoro/delta/delta timing.txt
  22. +120 −120 bananas/hitoro/delta/delta.monkey
  23. +170 −170 bananas/hitoro/gamestates_demo/gamestates_demo.monkey
  24. +238 −238 bananas/hitoro/jump_rotate/jump_rotate.monkey
  25. +120 −120 bananas/hitoro/matrixrocks/explained.txt
  26. +487 −487 bananas/hitoro/rockout/imports/autofit.monkey
  27. +94 −94 bananas/hitoro/rockout/imports/block.monkey
  28. +41 −41 bananas/hitoro/rockout/imports/button.monkey
  29. +52 −52 bananas/hitoro/rockout/imports/checkkeys.monkey
  30. +291 −291 bananas/hitoro/rockout/imports/collisions.monkey
  31. +7 −7 bananas/hitoro/rockout/imports/constants.monkey
  32. +10 −10 bananas/hitoro/rockout/imports/defaultmedia.monkey
  33. +55 −55 bananas/hitoro/rockout/imports/delta.monkey
  34. +49 −49 bananas/hitoro/rockout/imports/functions.monkey
  35. +90 −90 bananas/hitoro/rockout/imports/game.monkey
  36. +3 −3 bananas/hitoro/rockout/imports/globals.monkey
  37. +103 −103 bananas/hitoro/rockout/imports/level.monkey
  38. +19 −19 bananas/hitoro/rockout/imports/media.monkey
  39. +111 −111 bananas/hitoro/rockout/imports/rendergame.monkey
  40. +132 −132 bananas/hitoro/rockout/imports/rocket.monkey
  41. +41 −41 bananas/hitoro/rockout/imports/scorebubble.monkey
  42. +84 −84 bananas/hitoro/rockout/imports/session.monkey
  43. +108 −108 bananas/hitoro/rockout/imports/shot.monkey
  44. +34 −34 bananas/hitoro/rockout/imports/sprite.monkey
  45. +25 −25 bananas/hitoro/rockout/imports/timer.monkey
  46. +137 −137 bananas/hitoro/rockout/imports/updategame.monkey
  47. +383 −383 bananas/hitoro/rockout/imports/virtual.monkey
  48. +10 −10 bananas/hitoro/rockout/rockout.data/level1.txt
  49. +10 −10 bananas/hitoro/rockout/rockout.data/level10.txt
  50. +10 −10 bananas/hitoro/rockout/rockout.data/level2.txt
  51. +10 −10 bananas/hitoro/rockout/rockout.data/level3.txt
  52. +10 −10 bananas/hitoro/rockout/rockout.data/level4.txt
  53. +10 −10 bananas/hitoro/rockout/rockout.data/level5.txt
  54. +10 −10 bananas/hitoro/rockout/rockout.data/level6.txt
  55. +10 −10 bananas/hitoro/rockout/rockout.data/level7.txt
  56. +10 −10 bananas/hitoro/rockout/rockout.data/level8.txt
  57. +10 −10 bananas/hitoro/rockout/rockout.data/level9.txt
  58. +6 −6 bananas/hitoro/rockout/rockout.data/levels.bb
  59. +10 −10 bananas/hitoro/rockout/rockout.data/levels/default/level1.txt
  60. +76 −76 bananas/hitoro/rockout/rockout.monkey
  61. +267 −267 bananas/hitoro/rotationsickness/rotationsickness.monkey
  62. +77 −77 bananas/mak/fpstest/fpstest.monkey
  63. +102 −102 bananas/mak/gles20cube/geom.monkey
  64. +46 −46 bananas/mak/gles20cube/gles20cube.data/cube.txt
  65. +13 −13 bananas/mak/gles20cube/gles20cube.data/fshader.txt
  66. +13 −13 bananas/mak/gles20cube/gles20cube.data/vshader.txt
  67. +316 −316 bananas/mak/gles20cube/mat4.monkey
  68. +171 −171 bananas/mak/gles20cube/vec3.monkey
  69. +88 −88 bananas/mak/ifacetest/ifacetest
  70. +98 −98 bananas/mak/ifacetest/ifacetest.monkey
  71. +47 −47 bananas/mak/ifacetest/ifacetest2.monkey
  72. +42 −42 bananas/mak/joytest/joytest.monkey
  73. +62 −62 bananas/mak/unicodetest/unicodetest.data/ascii.txt
  74. +60 −60 bananas/origaming/DegreeAndRadian/DegreeAndRadian.monkey
  75. +56 −56 bananas/origaming/FollowMouse/FollowMouse.monkey
  76. +109 −109 bananas/origaming/MacOsMenu/MacOsMenu.monkey
  77. +2 −2 bananas/origaming/README.txt
  78. +92 −92 bananas/origaming/RotatingObjects/rotatingObjects.monkey
Sorry, we could not display the entire diff because it was too big.
View
1 .gitattributes
@@ -1 +1,2 @@
+# Auto detect text files and perform LF normalization
* text=auto
View
3 README.TXT
@@ -1,6 +1,3 @@
-
-Edited on Mac!
-
For more Monkey fun, please visit: http://www.monkeycoder.co.nz
Monkey is released under the zlib/libpng license.
View
236 bananas/Richard_Betson/TileImage/TileImage.monkey
@@ -1,118 +1,118 @@
-'******************************************************************
-'* Tile Image Example
-'* Author: Richard R Betson
-'* Date: 01/23/11
-'* Language: monkey
-'* Tagets: HTML5, FLASH, GLFW
-'* License - Public Domain
-'******************************************************************
-
-Import mojo
-
-Function Main()
- New TileImage
-End Function
-
-
-Class TileImage Extends App
-Field img:Image
-Field ix#,iy#
-Field scale_width#=1.0,scale_hieght#=1.0
-
- Method OnCreate()
- SetUpdateRate(60)
- img=LoadImage( "bg.png" )
- SetFont Null
- End Method
-
- Method OnUpdate()
-
- If KeyDown (KEY_LEFT)
- scale_width = scale_width - 0.1
- If scale_width < 1.0 Then scale_width = 1.0
- Endif
- If KeyDown (KEY_RIGHT)
- scale_width = scale_width + 0.1
- Endif
- If KeyDown (KEY_DOWN)
- scale_hieght = scale_hieght - 0.1
- If scale_hieght < 1.0 Then scale_hieght = 1.0
- Endif
- If KeyDown (KEY_UP)
- scale_hieght = scale_hieght + 0.1
- Endif
-
- End Method
-
- Method OnRender()
- Local ih=128,iw=128
- Local scale_x#=.99 'Some browsers like FireFox need a .01 offset to display right
- Local scale_y#=.99
-
- 'Cls 0,0,0
- PushMatrix()
-
- Translate DeviceWidth * 0.5, DeviceHeight * 0.5 'Thanks BlitzSupport:)
- Scale scale_width,scale_hieght
- Translate -DeviceWidth * 0.5, -DeviceHeight * 0.5' ""
-
- ix=ix+1.5
- iy=iy+1
- Tile_Image(img,ix,iy,ih,iw,scale_x,scale_y)
- PopMatrix()
-
- PushMatrix()
- Translate(0,0)
- Scale (1,1)
- SetBlend 0
- DrawText("Use Arrow Keys to adjust scale.",10,10)
-
- PopMatrix()
-
- End Method
-
-
-
-Function Tile_Image(img:Image,x#,y#,ih,iw,scalex#,scaley#)
-'Based in part on - http://www.blitzbasic.com/codearcs/codearcs.php?code=1842
- Local w#=iw * scalex
- Local h#=ih * scaley
-
- Local scissor:Float[]
- scissor=GetScissor()
- Local viewport_x=scissor[0]
- Local viewport_y=scissor[1]
- Local viewport_w=scissor[2]
- Local viewport_h=scissor[3]
-
- Local ox#=viewport_x-w+1
- Local oy#=viewport_y-h+1
-
- Local px#=x
- Local py#=y
-
- Local fx#=px-Floor(px)
- Local fy#=py-Floor(py)
- Local tx#=Floor(px)-ox
- Local ty#=Floor(py)-oy
-
- If tx>=0 tx=tx Mod w + ox Else tx = w - -tx Mod w + ox
- If ty>=0 ty=ty Mod h + oy Else ty = h - -ty Mod h + oy
-
- Local vr#= viewport_x + viewport_w, vb# = viewport_y + viewport_h
-
- Local iy#=ty
- While iy<(vb + h)
- Local ix#=tx
- While ix<(vr + w)
- DrawImage(img,ix+fx,iy+fy)
- ix=ix+w
- Wend
- iy=iy+h
- Wend
-End Function
-
-
-End Class
-
-
+'******************************************************************
+'* Tile Image Example
+'* Author: Richard R Betson
+'* Date: 01/23/11
+'* Language: monkey
+'* Tagets: HTML5, FLASH, GLFW
+'* License - Public Domain
+'******************************************************************
+
+Import mojo
+
+Function Main()
+ New TileImage
+End Function
+
+
+Class TileImage Extends App
+Field img:Image
+Field ix#,iy#
+Field scale_width#=1.0,scale_hieght#=1.0
+
+ Method OnCreate()
+ SetUpdateRate(60)
+ img=LoadImage( "bg.png" )
+ SetFont Null
+ End Method
+
+ Method OnUpdate()
+
+ If KeyDown (KEY_LEFT)
+ scale_width = scale_width - 0.1
+ If scale_width < 1.0 Then scale_width = 1.0
+ Endif
+ If KeyDown (KEY_RIGHT)
+ scale_width = scale_width + 0.1
+ Endif
+ If KeyDown (KEY_DOWN)
+ scale_hieght = scale_hieght - 0.1
+ If scale_hieght < 1.0 Then scale_hieght = 1.0
+ Endif
+ If KeyDown (KEY_UP)
+ scale_hieght = scale_hieght + 0.1
+ Endif
+
+ End Method
+
+ Method OnRender()
+ Local ih=128,iw=128
+ Local scale_x#=.99 'Some browsers like FireFox need a .01 offset to display right
+ Local scale_y#=.99
+
+ 'Cls 0,0,0
+ PushMatrix()
+
+ Translate DeviceWidth * 0.5, DeviceHeight * 0.5 'Thanks BlitzSupport:)
+ Scale scale_width,scale_hieght
+ Translate -DeviceWidth * 0.5, -DeviceHeight * 0.5' ""
+
+ ix=ix+1.5
+ iy=iy+1
+ Tile_Image(img,ix,iy,ih,iw,scale_x,scale_y)
+ PopMatrix()
+
+ PushMatrix()
+ Translate(0,0)
+ Scale (1,1)
+ SetBlend 0
+ DrawText("Use Arrow Keys to adjust scale.",10,10)
+
+ PopMatrix()
+
+ End Method
+
+
+
+Function Tile_Image(img:Image,x#,y#,ih,iw,scalex#,scaley#)
+'Based in part on - http://www.blitzbasic.com/codearcs/codearcs.php?code=1842
+ Local w#=iw * scalex
+ Local h#=ih * scaley
+
+ Local scissor:Float[]
+ scissor=GetScissor()
+ Local viewport_x=scissor[0]
+ Local viewport_y=scissor[1]
+ Local viewport_w=scissor[2]
+ Local viewport_h=scissor[3]
+
+ Local ox#=viewport_x-w+1
+ Local oy#=viewport_y-h+1
+
+ Local px#=x
+ Local py#=y
+
+ Local fx#=px-Floor(px)
+ Local fy#=py-Floor(py)
+ Local tx#=Floor(px)-ox
+ Local ty#=Floor(py)-oy
+
+ If tx>=0 tx=tx Mod w + ox Else tx = w - -tx Mod w + ox
+ If ty>=0 ty=ty Mod h + oy Else ty = h - -ty Mod h + oy
+
+ Local vr#= viewport_x + viewport_w, vb# = viewport_y + viewport_h
+
+ Local iy#=ty
+ While iy<(vb + h)
+ Local ix#=tx
+ While ix<(vr + w)
+ DrawImage(img,ix+fx,iy+fy)
+ ix=ix+w
+ Wend
+ iy=iy+h
+ Wend
+End Function
+
+
+End Class
+
+
View
642 bananas/Richard_Betson/glfw_diffusion/glfw_diffusion_example.monkey
@@ -1,321 +1,321 @@
-'******************************************************************
-'* Diffusion Example
-'* Author: Richard R Betson
-'* Date: 02/20/11
-'* Language: Monkey
-'* Target: GLFW
-'******************************************************************
-' Linsence - Public Domain
-'******************************************************************
-
-
-Import monkey
-Import mojo
-
-
-Global flag=0
-Global clra:Int
-
-
-Function Main()
- New Diffusion
-End Function
-
-
-Class Diffusion Extends App
-
-
-Global fps,fp,fps_t
-Global mapx:Int[77900]
-Global mapx1:Int[77900]
-Global mapx2:Int[77900]
-Global mapx3:Int[77900]
-Global mapx4:Int[77900]
-
-Global clrr:Int[77900]
-Global clrb:Int[77900]
-
-Global clrr1:Int[77900]
-Global clrb1:Int[77900]
-
-Global ii
-Global fxsel_ttl
-Global fxsel
-
- Method OnCreate()
- fxsel_ttl=Millisecs()+9000
- SetUpdateRate(30)
- SetLookUp()
- End Method
-
- Method OnUpdate()
- If fxsel_ttl<Millisecs()
- fxsel=fxsel+1
- fxsel_ttl=Millisecs()+9000
- If fxsel>4 Then fxsel=0
- Endif
-
- ii=ii+1
- Local x2=(160 + (Sin(ii)*90) )
- Local y2=(120 + (Cos(ii)*90) )
- Local x3=(160 + (-Sin(ii)*90) )
- Local y3=(120 + (-Cos(ii)*90) )
-
- 'Draw Line
- LineB(160,120,x2,y2)
- LineB(160,120,x3,y3)
-
- For Local zz=0 To 100
- Local xz=Int(Rnd(50))+135
- Local yz=Int(Rnd(50))+95
- clrb1[ ( 320 *yz ) +xz ]=255
- If zz>60 Then clrr1[ ( 320 *yz ) +xz ]=200
-
- Next
-
- For Local y=1 To 240
- For Local x= 1 To 320
- 'Apply mapping via lookup table
- If fxsel=0
- clrr[ ( 320 *y ) +x ] = clrr1[ mapx[( 320 *y ) +x] ]
- clrb[ ( 320 *y ) +x ] = clrb1[ mapx[( 320 *y ) +x] ]
- Else If fxsel=1
- clrr[ ( 320 *y ) +x ] = clrr1[ mapx1[( 320 *y ) +x] ]
- clrb[ ( 320 *y ) +x ] = clrb1[ mapx1[( 320 *y ) +x] ]
- Else If fxsel=2
- clrr[ ( 320 *y ) +x ] = clrr1[ mapx2[( 320 *y ) +x] ]
- clrb[ ( 320 *y ) +x ] = clrb1[ mapx2[( 320 *y ) +x] ]
- Else If fxsel=3
- clrr[ ( 320 *y ) +x ] = clrr1[ mapx3[( 320 *y ) +x] ]
- clrb[ ( 320 *y ) +x ] = clrb1[ mapx3[( 320 *y ) +x] ]
- Else If fxsel=4
- clrr[ ( 320 *y ) +x ] = clrr1[ mapx4[( 320 *y ) +x] ]
- clrb[ ( 320 *y ) +x ] = clrb1[ mapx4[( 320 *y ) +x] ]
-
- Endif
- Next
- Next
-
- End Method
-
- Method OnRender()
- fps=fps+1
- If fps_t<Millisecs()
- fp=(fps)
- fps_t=1000+Millisecs()
- fps=0
- Endif
-
- PushMatrix()
-
- For Local y=1 To 240
- For Local x= 1 To 320
- 'Blur Image and Fade Color
- Local r=clrr[ ( 320 *y ) + x ]
- Local sumr = ((r *4) + clrr[ ( 320 *y ) + x+1 ] + clrr[ ( 320 *y ) + x-1 ] + clrr[ ( 320 *y-1 ) + x ] + clrr[ ( 320 *y+1 ) + x ] ) /8
- Local b=clrb[ ( 320 *y ) + x ]
- Local sumb = ((b *4) + clrb[ ( 320 *y ) + x+1 ] + clrb[ ( 320 *y ) + x-1 ] + clrb[ ( 320 *y-1 ) + x ] + clrb[ ( 320 *y+1 ) + x ] ) /8
- Local sumg,g
- r=sumr-4
- b=sumb-4
-
- If r<10 Then r=10
- If r>255 Then r=255
- If b<0 Then b=0
- If b>255 Then b=255
-
- clrr1[ ( 320 *y ) + x ]=r
- clrb1[ ( 320 *y ) + x ]=b
-
- SetColor(r,0,b)
- DrawRect(x*2,y*2,2,2)
- Next
- Next
-
- 'Uncomment to see FPS
- 'SetColor(255,255,255)
- 'DrawText(fp,10,10)
-
- PopMatrix()
- End Method
-
- Function LineB(x1,y1,x2,y2)
- 'Ported
- 'Bresenham Line Algorithm
- 'Source - GameDev.Net - Mark Feldman
- 'Public Domain
-
- Local deltax = Abs(x2 - x1)
- Local deltay = Abs(y2 - y1)
-
- Local numpixels,d,dinc1,dinc2,xinc1,xinc2,yinc1,yinc2,x,y,i
-
- If deltax >= deltay
- numpixels = deltax + 1
- d = (2 * deltay) - deltax
- dinc1 = deltay Shl 1
- dinc2 = (deltay - deltax) Shl 1
- xinc1 = 1
- xinc2 = 1
- yinc1 = 0
- yinc2 = 1
- Else
- numpixels = deltay + 1
- d = (2 * deltax) - deltay
- dinc1 = deltax Shl 1
- dinc2 = (deltax - deltay) Shl 1
- xinc1 = 0
- xinc2 = 1
- yinc1 = 1
- yinc2 = 1
- Endif
-
- If x1 > x2
- xinc1 = -xinc1
- xinc2 = -xinc2
- Endif
-
- If y1 > y2
- yinc1 = -yinc1
- yinc2 = -yinc2
-
- Endif
-
- x = x1
- y = y1
-
- For i = 1 To numpixels
-
- If d < 0
- d = d + dinc1
- x = x + xinc1
- y = y + yinc1
- Else
- d = d + dinc2
- x = x + xinc2
- y = y + yinc2
- Endif
-
- 'Draw line
- If x>0 And x<320 And y>0 And y<240
- clrr1[ (( 320 *y )+x) ]=255
- Endif
-
-
- Next
-
- End Function
-
-
- Method SetLookUp()
- Local ang
-
- For Local lui=0 To 4
-
- ang=0
- For Local y=1 To 240
-
- For Local x= 1 To 320
- ang=0
- Local rad#=Abs((x-160)*(x-160)) + Abs( (y-120) * (y-120) )
- If rad>0
- rad= Sqrt(rad)
- Else
- rad=0
- Endif
- If rad=0 Then rad=1
-
- Local dx#=((x-160)/(rad))
- Local dy#=((y-120)/(rad))
- If lui=0
- 'Parabolic
- rad= 1-( ( rad*.93 - ( Cos(-rad)*(Sin(rad*22000)) )) * (-Cos(rad*.5) ) )
-
- dx=(dx*Cos(ang) - dy*Sin(ang))
- dy=(dy*Cos(ang) + dx*Sin(ang))
-
- Local x1=Int(dx*rad)+(160)
- Local y1=Int(dy*rad)+(120)
-
- If y1<1 Then y1=1
- If y1>240 Then y1=240
- If x1<1 Then x1=1
- If x1>320 Then x1=320
-
- mapx[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
-
- Else If lui=1
- 'Free Float
- ang=1
- rad= 1-( ( rad- (Sin(rad*900)*-Cos(rad*900)*.5 )*3.1415926 ) * (-Cos((3.1415926) ) )*.9 )
- Local x1=Int(dx*rad)+(160)
- Local y1=Int(dy*rad)+(120)
- x1= ( x1*Cos(ang) - y1*Sin(ang) )
- y1= ( x1*Sin(ang) + y1*Cos(ang) )
-
- If y1<1 Then y1=1
- If y1>240 Then y1=240
- If x1<1 Then x1=1
- If x1>320 Then x1=320
-
- mapx2[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
-
- Else If lui=2
- 'Burst
- rad= 2-( ( rad- (Sin(rad*4000)*(-Cos(rad*2000)*.9) )*3.1415926 ) * (-Cos((3.1415926) ) )*.8 )
- dx=(dx*Cos(ang) - dy*Sin(ang))
- dy=(dy*Cos(ang) + dx*Sin(ang))
-
- Local x1=Int(dx*rad)+(160)
- Local y1=Int(dy*rad)+(120)
-
- If y1<1 Then y1=1
- If y1>240 Then y1=240
- If x1<1 Then x1=1
- If x1>320 Then x1=320
-
- mapx1[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
-
- Else If lui=3
- 'Orb
- rad= 2-( ( rad- (Sin(rad)*(Cos(rad)*2.5) )*3.1415926 ) * (-Cos((3.1415926) ))*.97 )
- dx=(dx*Cos(ang) - dy*Sin(ang))
- dy=(dy*Cos(ang) + dx*Sin(ang))
-
- Local x1=Int(dx*rad)+(160)
- Local y1=Int(dy*rad)+(120)
-
- If y1<1 Then y1=1
- If y1>240 Then y1=240
- If x1<1 Then x1=1
- If x1>320 Then x1=320
-
- mapx3[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
- Else If lui=4
- 'Swirl
- ang=-3
- rad= 1-( ( rad- (Sin(rad)*-Cos(rad)*.9 )*3.1415926 ) * (-Cos((3.1415926) ) )*.9 )
- dx=(dx*Cos(ang) - dy*Sin(ang))
- dy=(dy*Cos(ang) + dx*Sin(ang))
-
- Local x1=Int(dx*rad)+(160)
- Local y1=Int(dy*rad)+(120)
-
- If y1<1 Then y1=1
- If y1>240 Then y1=240
- If x1<1 Then x1=1
- If x1>320 Then x1=320
-
- mapx4[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
- Endif
-
-
- Next
- Next
- Next
-
- End Method
-
-End Class
-
-
+'******************************************************************
+'* Diffusion Example
+'* Author: Richard R Betson
+'* Date: 02/20/11
+'* Language: Monkey
+'* Target: GLFW
+'******************************************************************
+' Linsence - Public Domain
+'******************************************************************
+
+
+Import monkey
+Import mojo
+
+
+Global flag=0
+Global clra:Int
+
+
+Function Main()
+ New Diffusion
+End Function
+
+
+Class Diffusion Extends App
+
+
+Global fps,fp,fps_t
+Global mapx:Int[77900]
+Global mapx1:Int[77900]
+Global mapx2:Int[77900]
+Global mapx3:Int[77900]
+Global mapx4:Int[77900]
+
+Global clrr:Int[77900]
+Global clrb:Int[77900]
+
+Global clrr1:Int[77900]
+Global clrb1:Int[77900]
+
+Global ii
+Global fxsel_ttl
+Global fxsel
+
+ Method OnCreate()
+ fxsel_ttl=Millisecs()+9000
+ SetUpdateRate(30)
+ SetLookUp()
+ End Method
+
+ Method OnUpdate()
+ If fxsel_ttl<Millisecs()
+ fxsel=fxsel+1
+ fxsel_ttl=Millisecs()+9000
+ If fxsel>4 Then fxsel=0
+ Endif
+
+ ii=ii+1
+ Local x2=(160 + (Sin(ii)*90) )
+ Local y2=(120 + (Cos(ii)*90) )
+ Local x3=(160 + (-Sin(ii)*90) )
+ Local y3=(120 + (-Cos(ii)*90) )
+
+ 'Draw Line
+ LineB(160,120,x2,y2)
+ LineB(160,120,x3,y3)
+
+ For Local zz=0 To 100
+ Local xz=Int(Rnd(50))+135
+ Local yz=Int(Rnd(50))+95
+ clrb1[ ( 320 *yz ) +xz ]=255
+ If zz>60 Then clrr1[ ( 320 *yz ) +xz ]=200
+
+ Next
+
+ For Local y=1 To 240
+ For Local x= 1 To 320
+ 'Apply mapping via lookup table
+ If fxsel=0
+ clrr[ ( 320 *y ) +x ] = clrr1[ mapx[( 320 *y ) +x] ]
+ clrb[ ( 320 *y ) +x ] = clrb1[ mapx[( 320 *y ) +x] ]
+ Else If fxsel=1
+ clrr[ ( 320 *y ) +x ] = clrr1[ mapx1[( 320 *y ) +x] ]
+ clrb[ ( 320 *y ) +x ] = clrb1[ mapx1[( 320 *y ) +x] ]
+ Else If fxsel=2
+ clrr[ ( 320 *y ) +x ] = clrr1[ mapx2[( 320 *y ) +x] ]
+ clrb[ ( 320 *y ) +x ] = clrb1[ mapx2[( 320 *y ) +x] ]
+ Else If fxsel=3
+ clrr[ ( 320 *y ) +x ] = clrr1[ mapx3[( 320 *y ) +x] ]
+ clrb[ ( 320 *y ) +x ] = clrb1[ mapx3[( 320 *y ) +x] ]
+ Else If fxsel=4
+ clrr[ ( 320 *y ) +x ] = clrr1[ mapx4[( 320 *y ) +x] ]
+ clrb[ ( 320 *y ) +x ] = clrb1[ mapx4[( 320 *y ) +x] ]
+
+ Endif
+ Next
+ Next
+
+ End Method
+
+ Method OnRender()
+ fps=fps+1
+ If fps_t<Millisecs()
+ fp=(fps)
+ fps_t=1000+Millisecs()
+ fps=0
+ Endif
+
+ PushMatrix()
+
+ For Local y=1 To 240
+ For Local x= 1 To 320
+ 'Blur Image and Fade Color
+ Local r=clrr[ ( 320 *y ) + x ]
+ Local sumr = ((r *4) + clrr[ ( 320 *y ) + x+1 ] + clrr[ ( 320 *y ) + x-1 ] + clrr[ ( 320 *y-1 ) + x ] + clrr[ ( 320 *y+1 ) + x ] ) /8
+ Local b=clrb[ ( 320 *y ) + x ]
+ Local sumb = ((b *4) + clrb[ ( 320 *y ) + x+1 ] + clrb[ ( 320 *y ) + x-1 ] + clrb[ ( 320 *y-1 ) + x ] + clrb[ ( 320 *y+1 ) + x ] ) /8
+ Local sumg,g
+ r=sumr-4
+ b=sumb-4
+
+ If r<10 Then r=10
+ If r>255 Then r=255
+ If b<0 Then b=0
+ If b>255 Then b=255
+
+ clrr1[ ( 320 *y ) + x ]=r
+ clrb1[ ( 320 *y ) + x ]=b
+
+ SetColor(r,0,b)
+ DrawRect(x*2,y*2,2,2)
+ Next
+ Next
+
+ 'Uncomment to see FPS
+ 'SetColor(255,255,255)
+ 'DrawText(fp,10,10)
+
+ PopMatrix()
+ End Method
+
+ Function LineB(x1,y1,x2,y2)
+ 'Ported
+ 'Bresenham Line Algorithm
+ 'Source - GameDev.Net - Mark Feldman
+ 'Public Domain
+
+ Local deltax = Abs(x2 - x1)
+ Local deltay = Abs(y2 - y1)
+
+ Local numpixels,d,dinc1,dinc2,xinc1,xinc2,yinc1,yinc2,x,y,i
+
+ If deltax >= deltay
+ numpixels = deltax + 1
+ d = (2 * deltay) - deltax
+ dinc1 = deltay Shl 1
+ dinc2 = (deltay - deltax) Shl 1
+ xinc1 = 1
+ xinc2 = 1
+ yinc1 = 0
+ yinc2 = 1
+ Else
+ numpixels = deltay + 1
+ d = (2 * deltax) - deltay
+ dinc1 = deltax Shl 1
+ dinc2 = (deltax - deltay) Shl 1
+ xinc1 = 0
+ xinc2 = 1
+ yinc1 = 1
+ yinc2 = 1
+ Endif
+
+ If x1 > x2
+ xinc1 = -xinc1
+ xinc2 = -xinc2
+ Endif
+
+ If y1 > y2
+ yinc1 = -yinc1
+ yinc2 = -yinc2
+
+ Endif
+
+ x = x1
+ y = y1
+
+ For i = 1 To numpixels
+
+ If d < 0
+ d = d + dinc1
+ x = x + xinc1
+ y = y + yinc1
+ Else
+ d = d + dinc2
+ x = x + xinc2
+ y = y + yinc2
+ Endif
+
+ 'Draw line
+ If x>0 And x<320 And y>0 And y<240
+ clrr1[ (( 320 *y )+x) ]=255
+ Endif
+
+
+ Next
+
+ End Function
+
+
+ Method SetLookUp()
+ Local ang
+
+ For Local lui=0 To 4
+
+ ang=0
+ For Local y=1 To 240
+
+ For Local x= 1 To 320
+ ang=0
+ Local rad#=Abs((x-160)*(x-160)) + Abs( (y-120) * (y-120) )
+ If rad>0
+ rad= Sqrt(rad)
+ Else
+ rad=0
+ Endif
+ If rad=0 Then rad=1
+
+ Local dx#=((x-160)/(rad))
+ Local dy#=((y-120)/(rad))
+ If lui=0
+ 'Parabolic
+ rad= 1-( ( rad*.93 - ( Cos(-rad)*(Sin(rad*22000)) )) * (-Cos(rad*.5) ) )
+
+ dx=(dx*Cos(ang) - dy*Sin(ang))
+ dy=(dy*Cos(ang) + dx*Sin(ang))
+
+ Local x1=Int(dx*rad)+(160)
+ Local y1=Int(dy*rad)+(120)
+
+ If y1<1 Then y1=1
+ If y1>240 Then y1=240
+ If x1<1 Then x1=1
+ If x1>320 Then x1=320
+
+ mapx[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
+
+ Else If lui=1
+ 'Free Float
+ ang=1
+ rad= 1-( ( rad- (Sin(rad*900)*-Cos(rad*900)*.5 )*3.1415926 ) * (-Cos((3.1415926) ) )*.9 )
+ Local x1=Int(dx*rad)+(160)
+ Local y1=Int(dy*rad)+(120)
+ x1= ( x1*Cos(ang) - y1*Sin(ang) )
+ y1= ( x1*Sin(ang) + y1*Cos(ang) )
+
+ If y1<1 Then y1=1
+ If y1>240 Then y1=240
+ If x1<1 Then x1=1
+ If x1>320 Then x1=320
+
+ mapx2[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
+
+ Else If lui=2
+ 'Burst
+ rad= 2-( ( rad- (Sin(rad*4000)*(-Cos(rad*2000)*.9) )*3.1415926 ) * (-Cos((3.1415926) ) )*.8 )
+ dx=(dx*Cos(ang) - dy*Sin(ang))
+ dy=(dy*Cos(ang) + dx*Sin(ang))
+
+ Local x1=Int(dx*rad)+(160)
+ Local y1=Int(dy*rad)+(120)
+
+ If y1<1 Then y1=1
+ If y1>240 Then y1=240
+ If x1<1 Then x1=1
+ If x1>320 Then x1=320
+
+ mapx1[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
+
+ Else If lui=3
+ 'Orb
+ rad= 2-( ( rad- (Sin(rad)*(Cos(rad)*2.5) )*3.1415926 ) * (-Cos((3.1415926) ))*.97 )
+ dx=(dx*Cos(ang) - dy*Sin(ang))
+ dy=(dy*Cos(ang) + dx*Sin(ang))
+
+ Local x1=Int(dx*rad)+(160)
+ Local y1=Int(dy*rad)+(120)
+
+ If y1<1 Then y1=1
+ If y1>240 Then y1=240
+ If x1<1 Then x1=1
+ If x1>320 Then x1=320
+
+ mapx3[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
+ Else If lui=4
+ 'Swirl
+ ang=-3
+ rad= 1-( ( rad- (Sin(rad)*-Cos(rad)*.9 )*3.1415926 ) * (-Cos((3.1415926) ) )*.9 )
+ dx=(dx*Cos(ang) - dy*Sin(ang))
+ dy=(dy*Cos(ang) + dx*Sin(ang))
+
+ Local x1=Int(dx*rad)+(160)
+ Local y1=Int(dy*rad)+(120)
+
+ If y1<1 Then y1=1
+ If y1>240 Then y1=240
+ If x1<1 Then x1=1
+ If x1>320 Then x1=320
+
+ mapx4[ ( 320 *y ) +x ] = ( 320 *y1 ) +x1'Int(x1)
+ Endif
+
+
+ Next
+ Next
+ Next
+
+ End Method
+
+End Class
+
+
View
756 bananas/Richard_Betson/line_v_circle_collision/line_v_circle_collision.monkey
@@ -1,378 +1,378 @@
-'******************************************************************
-'* Line vs. Circle Collision Example
-'* Author - Richard R Betson
-'* 01/25/2010
-'* Language: monkey
-'* Targets: HTML5, FLASH, GLFW
-'* License - Public Domain
-'******************************************************************
-
-Import mojo
-
-Global line_list:=New List<Lines>
-Global circle_list:=New List<CirclesL>
-Global line_nx# 'Used by LineToCircle
-Global line_ny#
-Global IntersectX#, IntersectY# 'Used by NearestPointInLine
-
-Global total_circles=10 'Total Circles
-Global dh=1
-Global dw=1
-Global fps,fp,fps_t
-
-Function Main()
- New Collision
-End Function
-
-Class Lines
-Field x1,y1,x2,y2
- Method New(Lx1,Ly1,Lx2,Ly2)
- Self.x1=Lx1
- Self.y1=Ly1
- Self.x2=Lx2
- Self.y2=Ly2
- End Method
-End Class
-
-Class CirclesL
-Field x1#,y1#,rad,dx#,dy#
- Method New(Lx1,Ly1,rad1,dx1#=0,dy1#=0)
- Self.x1=Lx1
- Self.y1=Ly1
- Self.rad=rad1
- 'Seed=Millisecs()
- Self.dx=2.0+Rnd(-1.0,4.0)
- Self.dy=2.0+Rnd(-1.0,4.0)
- End Method
-End Class
-
-
-Class Collision Extends App
-
-Field img:Image
-
-
- Method OnCreate()
- SetUpdateRate(60)
-
- dw=DeviceWidth()
- dh=DeviceHeight()
- 'dw=320
- 'dh=440
- Local linej:Lines=New Lines(0,0,dw,0)
- line_list.AddLast linej
- linej=New Lines(dw,1,dw,dh-1)
- line_list.AddLast linej
- linej=New Lines (0,dh,dw,dh)
- line_list.AddLast linej
- linej=New Lines (0,1,0,dh-1)
- line_list.AddLast linej
-
-
-
- linej=New Lines(160,100,460,100)
- line_list.AddLast linej
- linej=New Lines(461,101,461,139)
- line_list.AddLast linej
- linej=New Lines (160,140,460,140)
- line_list.AddLast linej
- linej=New Lines (159,101,159,139)
- line_list.AddLast linej
-
- linej=New Lines (270,400,340,270)
- line_list.AddLast linej
- linej=New Lines (270,400,410,400)
- line_list.AddLast linej
- linej=New Lines (340,270,410,400)
- line_list.AddLast linej
-
-
- Local i
- For i=1 To total_circles
- Local c:CirclesL=New CirclesL(20+Rnd(20),50+Rnd(50),8)
- circle_list.AddLast c
- Next
-
- Image.DefaultFlags=Image.MidHandle
- img=LoadImage("circle2f.png")
-
- End Method
-
- Method OnUpdate()
- fps=fps+1
- If fps_t<Millisecs()
- fp=(fps)
- fps_t=1000+Millisecs()
- fps=0
- Endif
-
- End Method
-
- Method OnRender()
-
-' fps=fps+1
-' If fps_t<Millisecs()
-' 'fps2=fps
-' fp=(fps)
-' fps_t=1000+Millisecs()
-' fps=0
-' EndIf
-
-
-
-
- Cls 0,0,0
- For Local circle:CirclesL=Eachin circle_list
-
- PushMatrix()
-
- Local sw,lnc
- Local dist#
- Local lines:Lines
- For lines=Eachin line_list
- 'Check for line collision
- lnc=LineToCircle(lines.x1,lines.y1,lines.x2,lines.y2,circle.x1,circle.y1,circle.rad)
-
-
- If lnc=1
- 'Reverse direction
- Local circledx#=-circle.dx
- Local circledy#=-circle.dy
- 'Back up clear of the line
- While LineToCircle(lines.x1,lines.y1,lines.x2,lines.y2,circle.x1,circle.y1,circle.rad+.1)=1
- circle.x1=circle.x1+circledx
- circle.y1=circle.y1+circledy
- Wend
-
- Local old_dst#=100
- Local lines3:Lines=New Lines ' Find the nearest line point
- For Local lines2:Lines=Eachin line_list
-
- Local dst#= Abs( (DistanceToLineSegment (lines2.x1,lines2.y1,lines2.x2,lines2.y2,circle.x1,circle.y1) ))
-
- 'Local dst#= Abs( (NearestPointInLine (lines2.x1,lines2.y1,lines2.x2,lines2.y2,circle.x1,circle.y1) ))
-
- If dst=old_dst 'Then Print "kk"
- circle.dx=-circle.dx
- circle.dy=-circle.dy
- 'lines3=lines2
- old_dst=dst
- sw=0
- Endif
-
- If dst<old_dst
- lines3=lines2
- old_dst=dst
- sw=1
-
- Endif
- Next
-
- If sw=1
- LineRecalc( lines3.x1,lines3.y1,lines3.x2,lines3.y2 ) 'Calc Normal
- Local dot#=circle.dx*line_nx+circle.dy*line_ny ' Dot Product
- 'Print line_ny
- circle.dx=circle.dx-2.0*line_nx*dot 'Calc new DX/DY direction
- circle.dy=circle.dy-2.0*line_ny*dot
-
- circle.x1=(circle.x1+circle.dx*.95) ' Move - Friction/Braking
- circle.y1=(circle.y1+circle.dy*.95)
- Exit
- Endif
-
- Endif
- Next
- If sw=0
- circle.x1=circle.x1+circle.dx
- circle.y1=circle.y1+circle.dy
- Endif
-
- PopMatrix
- SetBlend 0
- DrawImage(img,circle.x1,circle.y1)
- Next
-
- SetColor (255,0,0)
- DrawLine(160,100,460,100)
- DrawLine(460,101,460,139)
- DrawLine(160,140,460,140)
- DrawLine(160,101,160,139)
-
- DrawLine(270,400,340,270)
- DrawLine(271,400,409,400)
- DrawLine(341,271,410,400)
-
- End Method
-
- Function LineToCircle:Float( lx1#, ly1#, lx2#, ly2#, cx#, cy#, r#)
- 'This function by Jeppe Nielsen (Public Domain)
- 'http://www.blitzbasic.com/codearcs/codearcs.php?code=998
-
- Local dx# = lx2 - lx1
- Local dy# = ly2 - ly1
- Local ld# = Sqrt((dx*dx) + (dy*dy))
- Local lux# = dx / ld
- Local luy# = dy / ld
- Local lnx# = luy
- Local lny# = -lux
- Local dx1# = cx - (lx1 - lux*r)
- Local dy1# = cy - (ly1 - luy*r)
- Local d# = Sqrt((dx1*dx1) + (dy1*dy1))
- dx1 = dx1 / d
- dy1 = dy1/ d
- Local dx2# = cx - (lx2 + lux * r)
- Local dy2# = cy - (ly2 + luy*r)
- d = Sqrt((dx2*dx2) + (dy2*dy2))
- dx2 = dx2 / d
- dy2 = dy2 / d
- Local dot1# = (dx1 * lux) + (dy1 * luy)
- Local dot2# = (dx2 * lux) + (dy2 * luy)
- Local px#=lx1-cx
- Local py#=ly1-cy
- Local distsq# = Abs((dx * py - px * dy) / ld )
-
- 'You can get point of collision using these two variables (make them global)
- 'Local LineColX# = cx - lnx * Sqrt(distsq)
- 'Local LineColY# = cy - lny * Sqrt(distsq)
-
-
- If (( dot1>=0.0 And dot2<=0.0) Or (dot1<=0.0 And dot2>=0.0)) And (distsq<=r)
- Return 1.0
- Endif
-
- End Function
-
- Function LineRecalc(line_x1#,line_y1#,line_x2#,line_y2#)
- 'This function by Jeppe Nielsen and Braincell(Public Domain)
- 'http://www.blitzbasic.com/codearcs/codearcs.php?code=998
-
- Local line_dx#=line_x2-line_x1
- Local line_dy#=line_y2-line_y1
-
- Local line_d#=Sqrt(line_dx*line_dx+line_dy*line_dy)
- 'Print line_d
- If line_d<0.0001
- line_d=0.0001
- Endif
- 'Print line_d
- 'Print line_dx
- Local line_ux#=line_dx/line_d
- Local line_uy#=line_dy/line_d
-
- line_nx=line_uy
- line_ny=-line_ux
-
- End Function
-
-
- Function Orientation% ( x1#,y1#, x2#,y2#, Px#,Py# )
- 'http://www.blitzbasic.com/codearcs/codearcs.php?code=2180 - Public Domain Function Source
- '
- ' Linear determinant of the 3 points.
- ' This function returns the orientation of px,py on line x1,y1,x2,y2.
- ' Look from x2,y2 to the direction of x1,y1.
- ' If px,py is on the right, function returns +1
- ' If px,py is on the left, function returns -1
- ' If px,py is directly ahead or behind, function returns 0
- Return Sgn((x2 - x1) * (Py - y1) - (Px - x1) * (y2 - y1))
- End Function
-
-
- Function IntersectPoint ( x1#,y1#, x2#,y2#, x3#,y3#, x4#,y4# )
- 'http://www.blitzbasic.com/codearcs/codearcs.php?code=2180 - Public Domain Function Source
- '
- 'Function returns the X,Y position of the two intersecting lines.
- 'IntersectX and IntersectY are global variables of the main program.
- 'The lines are infinite, is line1 goes through x1,y1,x2,y2 and line2 goes through x3,y3,x4,y4.
- 'For line segments you must check if the lines truly intersect with the function Intersect% before you use this.
-
- Local dx1# = x2 - x1
- Local dx2# = x4 - x3
- Local dx3# = x1 - x3
-
- Local dy1# = y2 - y1
- Local dy2# = y1 - y3
- Local dy3# = y4 - y3
-
- Local R# = dx1 * dy3 - dy1 * dx2
-
- If R <> 0 Then
- R = (dy2 * (x4 - x3) - dx3 * dy3) / R
- IntersectX = x1 + R * dx1
- IntersectY = y1 + R * dy1
- Else
- If (((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) = 0) Then
- IntersectX = x3
- IntersectY = y3
- Else
- IntersectX = x4
- IntersectY = y4
- Endif
- Endif
-
- End Function
-
- Function DistanceToLineSegment# ( x1#,y1#, x2#,y2#, Px#,Py# )
- ' This function calculates the distance between a line segment and a point.
- ' So this function is useful to determine if line intersects a circle.
- ' To also determine the point on the line x1,y1,x2,y2 which is the closest to px,py , use function NearestPointInLine#
-
- Local Dx#, Dy#, Ratio#
-
- If (x1 = x2) And (y1 = y2) Then
- Return Sqrt( (Px-x1)*(Px-x1)+(Py-y1)*(Py-y1) )
- Else
-
- Dx = x2 - x1
- Dy = y2 - y1
- Ratio = ((Px - x1) * Dx + (Py - y1) * Dy) / (Dx * Dx + Dy * Dy)
-
- If Ratio < 0 Then
- Return Sqrt( (Px-x1)*(Px-x1)+(Py-y1)*(Py-y1) )
- Else If Ratio > 1
- Return Sqrt( (Px-x2)*(Px-x2)+(Py-y2)*(Py-y2) )
- Else
- Return Sqrt ((Px - ((1 - Ratio) * x1 + Ratio * x2))*(Px - ((1 - Ratio) * x1 + Ratio * x2))+(Py - ((1 - Ratio) * y1 + Ratio * y2))*(Py - ((1 - Ratio) * y1 + Ratio * y2)))
- Endif
-
- Endif
-
- End Function
-
-
- Function NearestPointInLine# ( lx1#,ly1#, lx2#,ly2#, x#,y# )
- 'Public Domain Function by Jasu
- 'http://www.blitzbasic.com/codearcs/codearcs.php?code=2180
- '
- ' This function calculates the point between lx1,ly1 and lx2,ly2 which is the nearest to x,y.
- ' Result is put in global variables IntersectX,IntersectY
- ' Function also returns the distance between x,y and the calculated point.
-
- Local dx#=lx2-lx1
- Local dy#=ly2-ly1
- 'd# = Sqrt(dx*dx+dy*dy)
- 'ux# = dx/d
- 'uy# = dy/d
- Local Ori1% = Orientation(lx1,ly1, (lx1+dy),(ly1-dx), x,y)
- Local Ori2% = Orientation(lx2,ly2, (lx2+dy),(ly2-dx), x,y)
- If (Ori1 = 1 And Ori2 = 1) Or Ori2 = 0 Then
- IntersectX = lx2
- IntersectY = ly2
- Else If (Ori1 = -1 And Ori2 = -1) Or Ori1 = 0
- IntersectX = lx1
- IntersectY = ly1
- Else
- IntersectPoint( lx1,ly1, lx2,ly2, x,y, x+dy,y-dx )
- Endif
- Return Sqrt((x-IntersectX)*(x-IntersectX)+(y-IntersectY)*(y-IntersectY))
-
- End Function
-
-End Class
-
-
-
-
-
-
-
+'******************************************************************
+'* Line vs. Circle Collision Example
+'* Author - Richard R Betson
+'* 01/25/2010
+'* Language: monkey
+'* Targets: HTML5, FLASH, GLFW
+'* License - Public Domain
+'******************************************************************
+
+Import mojo
+
+Global line_list:=New List<Lines>
+Global circle_list:=New List<CirclesL>
+Global line_nx# 'Used by LineToCircle
+Global line_ny#
+Global IntersectX#, IntersectY# 'Used by NearestPointInLine
+
+Global total_circles=10 'Total Circles
+Global dh=1
+Global dw=1
+Global fps,fp,fps_t
+
+Function Main()
+ New Collision
+End Function
+
+Class Lines
+Field x1,y1,x2,y2
+ Method New(Lx1,Ly1,Lx2,Ly2)
+ Self.x1=Lx1
+ Self.y1=Ly1
+ Self.x2=Lx2
+ Self.y2=Ly2
+ End Method
+End Class
+
+Class CirclesL
+Field x1#,y1#,rad,dx#,dy#
+ Method New(Lx1,Ly1,rad1,dx1#=0,dy1#=0)
+ Self.x1=Lx1
+ Self.y1=Ly1
+ Self.rad=rad1
+ 'Seed=Millisecs()
+ Self.dx=2.0+Rnd(-1.0,4.0)
+ Self.dy=2.0+Rnd(-1.0,4.0)
+ End Method
+End Class
+
+
+Class Collision Extends App
+
+Field img:Image
+
+
+ Method OnCreate()
+ SetUpdateRate(60)
+
+ dw=DeviceWidth()
+ dh=DeviceHeight()
+ 'dw=320
+ 'dh=440
+ Local linej:Lines=New Lines(0,0,dw,0)
+ line_list.AddLast linej
+ linej=New Lines(dw,1,dw,dh-1)
+ line_list.AddLast linej
+ linej=New Lines (0,dh,dw,dh)
+ line_list.AddLast linej
+ linej=New Lines (0,1,0,dh-1)
+ line_list.AddLast linej
+
+
+
+ linej=New Lines(160,100,460,100)
+ line_list.AddLast linej
+ linej=New Lines(461,101,461,139)
+ line_list.AddLast linej
+ linej=New Lines (160,140,460,140)
+ line_list.AddLast linej
+ linej=New Lines (159,101,159,139)
+ line_list.AddLast linej
+
+ linej=New Lines (270,400,340,270)
+ line_list.AddLast linej
+ linej=New Lines (270,400,410,400)
+ line_list.AddLast linej
+ linej=New Lines (340,270,410,400)
+ line_list.AddLast linej
+
+
+ Local i
+ For i=1 To total_circles
+ Local c:CirclesL=New CirclesL(20+Rnd(20),50+Rnd(50),8)
+ circle_list.AddLast c
+ Next
+
+ Image.DefaultFlags=Image.MidHandle
+ img=LoadImage("circle2f.png")
+
+ End Method
+
+ Method OnUpdate()
+ fps=fps+1
+ If fps_t<Millisecs()
+ fp=(fps)
+ fps_t=1000+Millisecs()
+ fps=0
+ Endif
+
+ End Method
+
+ Method OnRender()
+
+' fps=fps+1
+' If fps_t<Millisecs()
+' 'fps2=fps
+' fp=(fps)
+' fps_t=1000+Millisecs()
+' fps=0
+' EndIf
+
+
+
+
+ Cls 0,0,0
+ For Local circle:CirclesL=Eachin circle_list
+
+ PushMatrix()
+
+ Local sw,lnc
+ Local dist#
+ Local lines:Lines
+ For lines=Eachin line_list
+ 'Check for line collision
+ lnc=LineToCircle(lines.x1,lines.y1,lines.x2,lines.y2,circle.x1,circle.y1,circle.rad)
+
+
+ If lnc=1
+ 'Reverse direction
+ Local circledx#=-circle.dx
+ Local circledy#=-circle.dy
+ 'Back up clear of the line
+ While LineToCircle(lines.x1,lines.y1,lines.x2,lines.y2,circle.x1,circle.y1,circle.rad+.1)=1
+ circle.x1=circle.x1+circledx
+ circle.y1=circle.y1+circledy
+ Wend
+
+ Local old_dst#=100
+ Local lines3:Lines=New Lines ' Find the nearest line point
+ For Local lines2:Lines=Eachin line_list
+
+ Local dst#= Abs( (DistanceToLineSegment (lines2.x1,lines2.y1,lines2.x2,lines2.y2,circle.x1,circle.y1) ))
+
+ 'Local dst#= Abs( (NearestPointInLine (lines2.x1,lines2.y1,lines2.x2,lines2.y2,circle.x1,circle.y1) ))
+
+ If dst=old_dst 'Then Print "kk"
+ circle.dx=-circle.dx
+ circle.dy=-circle.dy
+ 'lines3=lines2
+ old_dst=dst
+ sw=0
+ Endif
+
+ If dst<old_dst
+ lines3=lines2
+ old_dst=dst
+ sw=1
+
+ Endif
+ Next
+
+ If sw=1
+ LineRecalc( lines3.x1,lines3.y1,lines3.x2,lines3.y2 ) 'Calc Normal
+ Local dot#=circle.dx*line_nx+circle.dy*line_ny ' Dot Product
+ 'Print line_ny
+ circle.dx=circle.dx-2.0*line_nx*dot 'Calc new DX/DY direction
+ circle.dy=circle.dy-2.0*line_ny*dot
+
+ circle.x1=(circle.x1+circle.dx*.95) ' Move - Friction/Braking
+ circle.y1=(circle.y1+circle.dy*.95)
+ Exit
+ Endif
+
+ Endif
+ Next
+ If sw=0
+ circle.x1=circle.x1+circle.dx
+ circle.y1=circle.y1+circle.dy
+ Endif
+
+ PopMatrix
+ SetBlend 0
+ DrawImage(img,circle.x1,circle.y1)
+ Next
+
+ SetColor (255,0,0)
+ DrawLine(160,100,460,100)
+ DrawLine(460,101,460,139)
+ DrawLine(160,140,460,140)
+ DrawLine(160,101,160,139)
+
+ DrawLine(270,400,340,270)
+ DrawLine(271,400,409,400)
+ DrawLine(341,271,410,400)
+
+ End Method
+
+ Function LineToCircle:Float( lx1#, ly1#, lx2#, ly2#, cx#, cy#, r#)
+ 'This function by Jeppe Nielsen (Public Domain)
+ 'http://www.blitzbasic.com/codearcs/codearcs.php?code=998
+
+ Local dx# = lx2 - lx1
+ Local dy# = ly2 - ly1
+ Local ld# = Sqrt((dx*dx) + (dy*dy))
+ Local lux# = dx / ld
+ Local luy# = dy / ld
+ Local lnx# = luy
+ Local lny# = -lux
+ Local dx1# = cx - (lx1 - lux*r)
+ Local dy1# = cy - (ly1 - luy*r)
+ Local d# = Sqrt((dx1*dx1) + (dy1*dy1))
+ dx1 = dx1 / d
+ dy1 = dy1/ d
+ Local dx2# = cx - (lx2 + lux * r)
+ Local dy2# = cy - (ly2 + luy*r)
+ d = Sqrt((dx2*dx2) + (dy2*dy2))
+ dx2 = dx2 / d
+ dy2 = dy2 / d
+ Local dot1# = (dx1 * lux) + (dy1 * luy)
+ Local dot2# = (dx2 * lux) + (dy2 * luy)
+ Local px#=lx1-cx
+ Local py#=ly1-cy
+ Local distsq# = Abs((dx * py - px * dy) / ld )
+
+ 'You can get point of collision using these two variables (make them global)
+ 'Local LineColX# = cx - lnx * Sqrt(distsq)
+ 'Local LineColY# = cy - lny * Sqrt(distsq)
+
+
+ If (( dot1>=0.0 And dot2<=0.0) Or (dot1<=0.0 And dot2>=0.0)) And (distsq<=r)
+ Return 1.0
+ Endif
+
+ End Function
+
+ Function LineRecalc(line_x1#,line_y1#,line_x2#,line_y2#)
+ 'This function by Jeppe Nielsen and Braincell(Public Domain)
+ 'http://www.blitzbasic.com/codearcs/codearcs.php?code=998
+
+ Local line_dx#=line_x2-line_x1
+ Local line_dy#=line_y2-line_y1
+
+ Local line_d#=Sqrt(line_dx*line_dx+line_dy*line_dy)
+ 'Print line_d
+ If line_d<0.0001
+ line_d=0.0001
+ Endif
+ 'Print line_d
+ 'Print line_dx
+ Local line_ux#=line_dx/line_d
+ Local line_uy#=line_dy/line_d
+
+ line_nx=line_uy
+ line_ny=-line_ux
+
+ End Function
+
+
+ Function Orientation% ( x1#,y1#, x2#,y2#, Px#,Py# )
+ 'http://www.blitzbasic.com/codearcs/codearcs.php?code=2180 - Public Domain Function Source
+ '
+ ' Linear determinant of the 3 points.
+ ' This function returns the orientation of px,py on line x1,y1,x2,y2.
+ ' Look from x2,y2 to the direction of x1,y1.
+ ' If px,py is on the right, function returns +1
+ ' If px,py is on the left, function returns -1
+ ' If px,py is directly ahead or behind, function returns 0
+ Return Sgn((x2 - x1) * (Py - y1) - (Px - x1) * (y2 - y1))
+ End Function
+
+
+ Function IntersectPoint ( x1#,y1#, x2#,y2#, x3#,y3#, x4#,y4# )
+ 'http://www.blitzbasic.com/codearcs/codearcs.php?code=2180 - Public Domain Function Source
+ '
+ 'Function returns the X,Y position of the two intersecting lines.
+ 'IntersectX and IntersectY are global variables of the main program.
+ 'The lines are infinite, is line1 goes through x1,y1,x2,y2 and line2 goes through x3,y3,x4,y4.
+ 'For line segments you must check if the lines truly intersect with the function Intersect% before you use this.
+
+ Local dx1# = x2 - x1
+ Local dx2# = x4 - x3
+ Local dx3# = x1 - x3
+
+ Local dy1# = y2 - y1
+ Local dy2# = y1 - y3
+ Local dy3# = y4 - y3
+
+ Local R# = dx1 * dy3 - dy1 * dx2
+
+ If R <> 0 Then
+ R = (dy2 * (x4 - x3) - dx3 * dy3) / R
+ IntersectX = x1 + R * dx1
+ IntersectY = y1 + R * dy1
+ Else
+ If (((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) = 0) Then
+ IntersectX = x3
+ IntersectY = y3
+ Else
+ IntersectX = x4
+ IntersectY = y4
+ Endif
+ Endif
+
+ End Function
+
+ Function DistanceToLineSegment# ( x1#,y1#, x2#,y2#, Px#,Py# )
+ ' This function calculates the distance between a line segment and a point.
+ ' So this function is useful to determine if line intersects a circle.
+ ' To also determine the point on the line x1,y1,x2,y2 which is the closest to px,py , use function NearestPointInLine#
+
+ Local Dx#, Dy#, Ratio#
+
+ If (x1 = x2) And (y1 = y2) Then
+ Return Sqrt( (Px-x1)*(Px-x1)+(Py-y1)*(Py-y1) )
+ Else
+
+ Dx = x2 - x1
+ Dy = y2 - y1
+ Ratio = ((Px - x1) * Dx + (Py - y1) * Dy) / (Dx * Dx + Dy * Dy)
+
+ If Ratio < 0 Then
+ Return Sqrt( (Px-x1)*(Px-x1)+(Py-y1)*(Py-y1) )
+ Else If Ratio > 1
+ Return Sqrt( (Px-x2)*(Px-x2)+(Py-y2)*(Py-y2) )
+ Else
+ Return Sqrt ((Px - ((1 - Ratio) * x1 + Ratio * x2))*(Px - ((1 - Ratio) * x1 + Ratio * x2))+(Py - ((1 - Ratio) * y1 + Ratio * y2))*(Py - ((1 - Ratio) * y1 + Ratio * y2)))
+ Endif
+
+ Endif
+
+ End Function
+
+
+ Function NearestPointInLine# ( lx1#,ly1#, lx2#,ly2#, x#,y# )
+ 'Public Domain Function by Jasu
+ 'http://www.blitzbasic.com/codearcs/codearcs.php?code=2180
+ '
+ ' This function calculates the point between lx1,ly1 and lx2,ly2 which is the nearest to x,y.
+ ' Result is put in global variables IntersectX,IntersectY
+ ' Function also returns the distance between x,y and the calculated point.
+
+ Local dx#=lx2-lx1
+ Local dy#=ly2-ly1
+ 'd# = Sqrt(dx*dx+dy*dy)
+ 'ux# = dx/d
+ 'uy# = dy/d
+ Local Ori1% = Orientation(lx1,ly1, (lx1+dy),(ly1-dx), x,y)
+ Local Ori2% = Orientation(lx2,ly2, (lx2+dy),(ly2-dx), x,y)
+ If (Ori1 = 1 And Ori2 = 1) Or Ori2 = 0 Then
+ IntersectX = lx2
+ IntersectY = ly2
+ Else If (Ori1 = -1 And Ori2 = -1) Or Ori1 = 0
+ IntersectX = lx1
+ IntersectY = ly1
+ Else
+ IntersectPoint( lx1,ly1, lx2,ly2, x,y, x+dy,y-dx )
+ Endif
+ Return Sqrt((x-IntersectX)*(x-IntersectX)+(y-IntersectY)*(y-IntersectY))
+
+ End Function
+
+End Class
+
+
+
+
+
+
+
View
204 bananas/Richard_Betson/mirror_fx_transform/mirror_fx_transform.monkey
@@ -1,102 +1,102 @@
-'*****************************************************
-'* Mirror FX using Transform
-'* Author: Richard Betson
-'* Date: 02/09/11
-'* Language: monkey
-'* Tagets: HTML5, FLASH, GLFW
-'* License - Public Domain
-'*****************************************************
-
-Import mojo
-
-Global img:Image
-
-Class MyApp Extends App
-
- Global t#
- Global tt#
- Global ttx#
- Global rt#
- Global rtt#
-
- Method OnCreate()
- SetUpdateRate 60
- img=LoadImage("c.png")
- End Method
-
- Method OnUpdate()
- rtt=rtt+1
- If KeyDown(KEY_RIGHT) Then t=t+.001
- If KeyDown(KEY_LEFT) Then t=t-.001
- If KeyDown(KEY_UP) Then tt=tt+.0001
- If KeyDown(KEY_DOWN) Then tt=tt-.0001
- If KeyDown(KEY_1) Then ttx=ttx+.0001
- If KeyDown(KEY_2) Then ttx=ttx-.0001
-
- End Method
-
- Method OnRender()
- Cls
- PushMatrix()
- Local stp=0
- Local clr#
- Local oldx=20
- Local oldy=10
-
- For Local ii=0 To 200
- Local i=200-ii
- clr=clr+.004
- If clr>=1 Then clr=1
-
- stp=stp+1
- If stp>=30
- stp=0
- SetColor((i)+55,0,255-i)
-
- For Local y=10 To 480 Step 110
- SetAlpha (1-clr)
-
- For Local x=20 To 640 Step 120
- DrawLine oldx,y,x,y
- DrawLine x,oldy,x,y
- oldx=x
- DrawCircle(x,y,(8-(ii*.01)))
- Next
- oldx=20
- oldy=y
- Next
- Endif
- Translate(2,2)
- Transform 1+Sin(t-.259)-ttx-.001,0,0,Cos(t-.259)-tt-.007,Cos(rtt),Sin(rtt)
-
-
- Next
- Translate(0,0)
- Transform 1,0,0,1,0,0
- PopMatrix()
-
- oldx=20
- SetColor 255,0,0
- SetAlpha 1
- For Local y=10 To 480 Step 110
- For Local x=20 To 640 Step 120
- DrawLine oldx,y,x,y
- DrawLine x,oldy,x,y
- oldx=x
- DrawImage(img,x-9,y-7,1,1,1)
- Next
- oldx=20
- oldy=y
- Next
-
- SetColor 255,255,255
-
- End Method
-
-End Class
-
-Function Main()
-
- New MyApp
-
-End
+'*****************************************************
+'* Mirror FX using Transform
+'* Author: Richard Betson
+'* Date: 02/09/11
+'* Language: monkey
+'* Tagets: HTML5, FLASH, GLFW
+'* License - Public Domain
+'*****************************************************
+
+Import mojo
+
+Global img:Image
+
+Class MyApp Extends App
+
+ Global t#
+ Global tt#
+ Global ttx#
+ Global rt#
+ Global rtt#
+
+ Method OnCreate()
+ SetUpdateRate 60
+ img=LoadImage("c.png")
+ End Method
+
+ Method OnUpdate()
+ rtt=rtt+1
+ If KeyDown(KEY_RIGHT) Then t=t+.001
+ If KeyDown(KEY_LEFT) Then t=t-.001
+ If KeyDown(KEY_UP) Then tt=tt+.0001
+ If KeyDown(KEY_DOWN) Then tt=tt-.0001
+ If KeyDown(KEY_1) Then ttx=ttx+.0001
+ If KeyDown(KEY_2) Then ttx=ttx-.0001
+
+ End Method
+
+ Method OnRender()
+ Cls
+ PushMatrix()
+ Local stp=0
+ Local clr#
+ Local oldx=20
+ Local oldy=10
+
+ For Local ii=0 To 200
+ Local i=200-ii
+ clr=clr+.004
+ If clr>=1 Then clr=1
+
+ stp=stp+1
+ If stp>=30
+ stp=0
+ SetColor((i)+55,0,255-i)
+
+ For Local y=10 To 480 Step 110
+ SetAlpha (1-clr)
+
+ For Local x=20 To 640 Step 120
+ DrawLine oldx,y,x,y
+ DrawLine x,oldy,x,y
+ oldx=x
+ DrawCircle(x,y,(8-(ii*.01)))
+ Next
+ oldx=20
+ oldy=y
+ Next
+ Endif
+ Translate(2,2)
+ Transform 1+Sin(t-.259)-ttx-.001,0,0,Cos(t-.259)-tt-.007,Cos(rtt),Sin(rtt)
+
+
+ Next
+ Translate(0,0)
+ Transform 1,0,0,1,0,0
+ PopMatrix()
+
+ oldx=20
+ SetColor 255,0,0
+ SetAlpha 1
+ For Local y=10 To 480 Step 110
+ For Local x=20 To 640 Step 120
+ DrawLine oldx,y,x,y
+ DrawLine x,oldy,x,y
+ oldx=x
+ DrawImage(img,x-9,y-7,1,1,1)
+ Next
+ oldx=20
+ oldy=y
+ Next
+
+ SetColor 255,255,255
+
+ End Method
+
+End Class
+
+Function Main()
+
+ New MyApp
+
+End
View
938 bananas/Richard_Betson/simple_verlet_physics/simple_verlet_physics.monkey
@@ -1,469 +1,469 @@
-'******************************************************************
-'* Monkey port of Simple Verlet (physics) by grable
-'* http://www.blitzbasic.com/codearcs/codearcs.php?code=1769
-'* Port Author: Richard R Betson
-'* 02/09/11
-'* Language: monkey
-'* Tagets: HTML5, FLASH, GLFW
-'* License - Public Domain
-'******************************************************************
-
-Import mojo
-
-Const S_TIMESTEP:Float = 0.1
-
-
-
-
-Class TSPoint
- Field x:Float,y:Float ' current position
- Field oldx:Float,oldy:Float ' old position
- Field fx:Float,fy:Float ' impulse force
- Field mass:Float
- Field active:Int
-
- Function Create:TSPoint( x:Float,y:Float, mass:Float, active:Int = True)
- Local p:TSPoint = New TSPoint
- p.x = x
- p.y = y
- p.oldx = x
- p.oldy = y
- p.mass = mass
- p.active = active
- Return p
- End Function
-
- Method Update()
- If Not active Then Return
-
- Local tmpx1:Float = x
- Local tmpy1:Float = y
- Local tmpx2:Float = fx * S_TIMESTEP * S_TIMESTEP
- Local tmpy2:Float = fy * S_TIMESTEP * S_TIMESTEP
-
- oldx = oldx+ tmpx2
- oldy = oldy+ tmpy2
-
- x = x- oldx
- y = y- oldy
-
- x = x+ tmpx1
- y = y+ tmpy1
-
- oldx = tmpx1
- oldy = tmpy1
-
- fx = 0
- fy = 0
- End Method
-
- Method Render()
- SetColor 0,0,255
- DrawOval x-2,y-2, 5,5
- End Method
-
- Method Translate( x:Float,y:Float, reset:Int = False)
- Self.x = Self.x+ x
- Self.y = Self.y+ y
- ' reset movement
- If reset Then
- oldx = Self.x
- oldy = Self.y
- Endif
- End Method
-
- Method Rotate( dir:Float, center:Float[], reset:Int = False)
- Local xr:Float = x - center[0]
- Local yr:Float = y - center[1]
- x = xr * Cos(dir) - yr * Sin(dir)
- y = xr * Sin(dir) + yr * Cos(dir)
- x = x+ center[0]
- y = y+ center[1]
- ' reset movement
- If reset Then
- oldx = x
- oldy = y
- Endif
- End Method
-End Class
-
-
-Class TSLink
- Field p1:TSPoint
- Field p2:TSPoint
- Field restLength:Float
- Field k:Float
- Field stress:Float
-
- Function Create:TSLink( p1:TSPoint, p2:TSPoint, k:Float)
- Local l:TSLink = New TSLink
- l.p1 = p1
- l.p2 = p2
- l.k = k
- l.CalcRestLength()
- Return l
- End Function
-
- Method Update()
- Local dx:Float = p1.x - p2.x
- Local dy:Float = p1.y - p2.y
- Local dist:Float = Sqrt( dx*dx + dy*dy)
- Local w:Float = p1.mass + p2.mass
-
- If p1.active Then
- p1.x = p1.x- ((dx / dist) * ((dist - restLength) * k)) * (p1.mass / w)
- p1.y = p1.y- ((dy / dist) * ((dist - restLength) * k)) * (p1.mass / w)
- Endif
-
- If p2.active Then
- p2.x = p2.x+ ((dx / dist) * ((dist - restLength) * k)) * (p2.mass / w)
- p2.y = p2.y+ ((dy / dist) * ((dist - restLength) * k)) * (p2.mass / w)
- Endif
-
- stress = (dist - restLength) / restLength
- End Method
-
- Method Render()
- SetColor 255,255,255
- DrawLine p1.x,p1.y, p2.x,p2.y
- End Method
-
- Method CalcRestLength()
- restLength = Sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y))
- End Method
-End Class
-
-
-Class TSGroup
- Field points:=New List<TSPoint>
- Field links:=New List<TSLink>
- Field gravity:Float
- Field active:Int
- Field bbox:Float[4]
- Field center:Float[2]
-
- Function Create:TSGroup( gravity:Float = 0.0, active:Int = True)
- Local g:TSGroup = New TSGroup
- g.gravity = gravity
- Return g
- End Function
-
- Method AddPoint( p:TSPoint)
- If p Then points.AddLast( p)
- End Method
-
- Method AddLink( l:TSLink)
- If l Then links.AddLast( l)
- End Method
-
- Method Update()
- If Not active Then Return
-
- For Local p:TSPoint = Eachin points
- p.fy = gravity
- p.Update()
- Next
-
- For Local l:TSLink = Eachin links
- l.Update()
- Next
-
- CalcBoundingBox()
- CalcCenterPoint()
- End Method
-
- Method Render()
- For Local l:TSLink = Eachin links
- l.Render()
- Next
-
- For Local p:TSPoint = Eachin points
- p.Render()
- Next
-
- SetColor 0,192,0
- DrawFrame( bbox[0], bbox[1], bbox[2], bbox[3])
-
- SetColor 255,0,0
- DrawOval center[0]-2,center[1]-2,4,4
- End Method
-
- Method Translate( x:Float,y:Float, reset:Int = False)
- For Local p:TSPoint = Eachin points
- p.Translate( x,y, reset)
- Next
- CalcBoundingBox()
- CalcCenterPoint()
- End Method
-
- Method Rotate( dir:Float, reset:Int = False)
- For Local p:TSPoint = Eachin points
- p.Rotate( dir, center, reset)
- Next
- CalcBoundingBox()
- CalcCenterPoint()
- End Method
-
- Method CalcBoundingBox()
- bbox[0] = $FFFFFFF
- bbox[1] = $FFFFFFF
- bbox[2] = 0
- bbox[3] = 0
- For Local p:TSPoint = Eachin points
- bbox[0] = Min( bbox[0], p.x)
- bbox[1] = Min( bbox[1], p.y)
- bbox[2] = Max( bbox[2], p.x)
- bbox[3] = Max( bbox[3], p.y)
- Next
- bbox[2] = bbox[2]- bbox[0]
- bbox[3] = bbox[3]- bbox[1]
- End Method
-
- Method CalcCenterPoint()
- Local xtmp:Float,ytmp:Float, sz:Int = points.Count()
- For Local p:TSPoint = Eachin points
- xtmp = xtmp+ p.x
- ytmp = ytmp+ p.y
- Next
- center[0] = xtmp / sz
- center[1] = ytmp / sz
- End Method
-End Class
-
-
-
-Function DrawFrame( x:Float,y:Float, w:Float,h:Float)
- DrawLine x,y, x+w,y ' top
- DrawLine x,y+h, x+w,y+h ' bottom
- DrawLine x,y, x,y+h ' left
- DrawLine x+w,y, x+w,y+h ' right
-End Function
-
-Function PointInRect:Int( px:Int,py:Int, rect:Int[])
- Return (px >= rect[0]) And (py >= rect[1]) And (px < rect[0] + rect[2]) And (py < rect[1] + rect[3])
-End Function
-
-
-
-
-Function Main()
- New Collision
-End Function
-
-Class Collision Extends App
-
-Global obj1:TSGroup = TSGroup.Create( -5, False)
-Const BOX_COEF:Float = 0.4
-Const BOX_MASS:Float = 30
-Global mb1:Int,mb2:Int
-Global mx:Int,my:Int
-Global mpoint:TSPoint
-Global GHeight:Int=480
-Global GWidth:Int=640
-
-' globals
-
-
- Method OnCreate()
- SetUpdateRate(60)
-
- Local p1:TSPoint = TSPoint.Create( 0,0, BOX_MASS, True)
- Local p2:TSPoint = TSPoint.Create( 64,0, BOX_MASS, True)
- Local p3:TSPoint = TSPoint.Create( 0,64, BOX_MASS, True)
- Local p4:TSPoint = TSPoint.Create( 64,64, BOX_MASS, True)
-
- obj1.AddPoint( p1)
- obj1.AddPoint( p2)
- obj1.AddPoint( p3)
- obj1.AddPoint( p4)
-
- obj1.AddLink( TSLink.Create( p1, p2, BOX_COEF)) ' top
- obj1.AddLink( TSLink.Create( p2, p4, BOX_COEF)) ' right
- obj1.AddLink( TSLink.Create( p4, p3, BOX_COEF)) ' bottom
- obj1.AddLink( TSLink.Create( p3, p1, BOX_COEF)) ' left
- obj1.AddLink( TSLink.Create( p3, p2, BOX_COEF)) ' cross 1
- obj1.AddLink( TSLink.Create( p1, p4, BOX_COEF)) ' cross 2
-
- ' move it some to the right
- obj1.Translate( 405,32, True)
- ' rotate it and give it some speed
- obj1.Rotate( 10)
- obj1.Translate( 4,0)
-
-
-
- End Method
-
- Method OnUpdate()
- If KeyHit( KEY_SPACE) Then obj1.active = Not obj1.active
-
-' create points / links
-
- If KeyDown( KEY_Q) Or KeyDown( KEY_W) And (Not obj1.active)
-
- mx = MouseX()
- my = MouseY()
- If TouchHit(0) And KeyDown(KEY_Q)
- ' create point
- obj1.AddPoint( TSPoint.Create( mx,my, BOX_MASS, True))
- Else
- If TouchHit(0) And KeyDown( KEY_W)
- ' create link
- Local rect:Int[4]
- If mpoint = Null Then
- ' select first point
- For Local p:TSPoint = Eachin obj1.points
- rect[0] = p.x - 4
- rect[1] = p.y - 4
- rect[2] = 8
- rect[3] = 8
- If PointInRect( mx,my, rect) Then
- mpoint = p
- Exit
- Exit
- Endif
- Next
- 'endif
- Else
- ' select second point
- For Local p:TSPoint = Eachin obj1.points
- rect[0] = p.x - 4
- rect[1] = p.y - 4
- rect[2] = 8
- rect[3] = 8
- If PointInRect( mx,my, rect) Then
- obj1.AddLink( TSLink.Create( mpoint, p, BOX_COEF))
- 'Exit
- Exit
- Endif
- Next
- mpoint = Null
- Endif
- Endif
- Endif
- ' FlushMouse()
- Else
-' move single point / modify link
- If TouchDown(0) Then
- mx = MouseX()
- my = MouseY()
- If Not mb1 Then
- ' select point
- Local rect:Int[4]
- For Local p:TSPoint = Eachin obj1.points
- rect[0] = p.x - 4
- rect[1] = p.y - 4
- rect[2] = 8
- rect[3] = 8
- If PointInRect( mx,my, rect) Then
- mpoint = p
- ' Exit
- Exit
- Endif
- Next
- mb1 = True
- Endif
- ' modify point
- If mpoint Then
- mpoint.x = mx
- mpoint.y = my
- ' modify connected links
- If Not obj1.active Then
- ' search for links with this point
- For Local l:TSLink = Eachin obj1.links
- If (l.p1 = mpoint) Or (l.p2 = mpoint) Then
- l.CalcRestLength()
- Endif
- Next
- ' cancel allow movement
- mpoint.oldx = mpoint.x
- mpoint.oldy = mpoint.y
- Endif
- Endif
- Else
- If mb1 Then
- ' reset
- mb1 = False
- mpoint = Null
- ' FlushMouse()
- Endif
- Endif
- Endif