Ooops
September 20, 2020, 11:20:36 AM

Author Topic: Syntax highlighting now available for multiple languages  (Read 2630 times)

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2515
  • I mostly code at night... Mostly.
    • SyntaxBomb - Indie Coders
Syntax highlighting now available for multiple languages
« on: June 17, 2017, 08:48:38 PM »
We now have syntax highlighting for multiple languages including Monkey, BlitzMax and BlitzBasic.

It works like so :

Code: [Select]
{code=language name}
blah blah blah
{/code}

replace curly with square brackets.

It uses the GeSHi plugin and I believe the monkey and max translations were done by Taiphoz

Monkey firepaint banana :

Code: Monkey
  1.  
  2. 'Firepaint redux!
  3. '
  4. 'Really a multitouch test...
  5.  
  6. Import mojo
  7.  
  8. Global BigList:=New List<Spark>
  9.  
  10. Class Spark
  11.  
  12.         Field x#,y#,xv#,yv#,a#
  13.        
  14.         Method New( x#,y# )
  15.                 Self.x=x
  16.                 Self.y=y
  17.                 Local an#=Rnd(360),v#=Rnd(3,4)
  18.                 Self.xv=Cos(an)*v
  19.                 Self.yv=Sin(an)*v
  20.                 Self.a=1
  21.         End
  22.        
  23. End
  24.  
  25. Class Firepaint Extends App
  26.  
  27.         Field sparkImage:Image
  28.         Field sparks:=New List<Spark>
  29.        
  30.         Field prim
  31.        
  32.         Method OnCreate()
  33.        
  34.                 For Local i=0 Until 65536*16
  35. '                       BigList.AddLast New Spark
  36.                 Next
  37.                
  38.                 sparkImage=LoadImage( "bluspark.png",1,Image.MidHandle )
  39.                
  40.                 SetUpdateRate 60
  41.         End
  42.        
  43.         Method OnUpdate()
  44.        
  45.                 Local out:=New List<Spark>
  46.                 For Local spark:=Eachin sparks
  47.                         spark.a=Max(spark.a-.01,0.0)
  48.                         If spark.a<=0 Continue
  49.                         spark.yv+=.05
  50.                         spark.x+=spark.xv
  51.                         spark.y+=spark.yv
  52.                         out.AddLast spark
  53.                 Next
  54.  
  55.                 sparks=out
  56.                
  57.                 For Local i=0 Until 32
  58.                         If TouchDown( i )
  59.                                 For Local j=1 To 10
  60.                                         sparks.AddLast New Spark( TouchX(i),TouchY(i) )
  61.                                 next
  62.                         Endif
  63.                 Next
  64.                
  65.                 If KeyHit( KEY_SPACE )
  66.                         prim=(prim+1) Mod 4
  67.                 Endif
  68.                
  69.         End
  70.        
  71.         Method OnRender()
  72.        
  73.                 Local w=DeviceWidth,h=DeviceHeight
  74.                
  75.                 SetBlend LightenBlend
  76.  
  77.                 Cls
  78.                
  79.                 DrawText "This way UP!",0,0
  80.                
  81.                 SetColor 255,0,0
  82.                 DrawRect 0,0,w,32
  83.                 SetColor 0,255,0
  84.                 DrawRect w-32,0,32,h
  85.                 SetColor 0,0,255
  86.                 DrawRect 0,h-32,w,32
  87.                 SetColor 128,128,128
  88.                 DrawRect 0,0,32,h
  89.                
  90.                 For Local spark:=Eachin sparks
  91.  
  92.                         SetAlpha spark.a
  93.                
  94.                         Select prim
  95.                         Case 0
  96.                                 DrawImage sparkImage,spark.x,spark.y
  97.                         Case 1
  98.                                 DrawRect spark.x-15,spark.y-15,30,30
  99.                         Case 2
  100.                                 DrawOval spark.x-15,spark.y-15,30,30
  101.                         Case 3
  102.                                 DrawLine spark.x-15,spark.y-15,spark.x+15,spark.y+15
  103.                                 DrawLine spark.x+15,spark.y-15,spark.x-15,spark.y+15
  104.                         End
  105.                 Next
  106.         End
  107.        
  108. End
  109.  
  110. Function Main()
  111.  
  112.         New Firepaint
  113.        
  114. End
  115.  


BlitzMax firepaint sample :

Code: BlitzMax
  1. Rem
  2.  
  3. Firepaint demo:
  4.  
  5. Hold down mouse button to emit *FIRE*!
  6.  
  7. EndRem
  8.  
  9. Strict
  10.  
  11. 'For minimal build...
  12. Rem
  13. Framework BRL.D3D7Max2D
  14. Import BRL.Basic
  15. Import BRL.System
  16. Import BRL.PNGLoader
  17. Import BRL.FreeAudioAudio
  18. Import BRL.WAVLoader
  19. End Rem
  20.  
  21. Import "color.bmx"
  22.  
  23. Incbin "stars.png"
  24. Incbin "player.png"
  25. Incbin "bullet.png"
  26. Incbin "shoot.wav"
  27.  
  28. Const WIDTH=640,HEIGHT=480
  29. Const DEPTH=32,HERTZ=60
  30.  
  31. Const GRAVITY#=.15,SPARKS_PER_FRAME=55
  32.  
  33. Global sparks:TList=New TList
  34. Global bullets:TList=New TList
  35.  
  36. Type TEntity
  37.  
  38.         Field link:TLink
  39.  
  40.         Method remove()
  41.                 link.remove
  42.         End Method
  43.  
  44.         Method AddLast( list:TList )
  45.                 link=list.AddLast( Self )
  46.         End Method
  47.  
  48.         Method Update() Abstract
  49.  
  50. End Type
  51.  
  52. Type TSpark Extends TEntity
  53.  
  54.         Field x#,y#,xs#,ys#
  55.         Field color[3],rot#,rots#
  56.  
  57.         Method Update()
  58.  
  59.                 ys:+GRAVITY
  60.                 x:+xs
  61.                 y:+ys
  62.  
  63.                 If x<0 Or x>=WIDTH Or y>=HEIGHT
  64.                         remove
  65.                         Return
  66.                 EndIf
  67.  
  68.                 rot=rot+rots
  69.                 SetHandle 8,8
  70.                 SetRotation rot#
  71.                 SetAlpha 1-y/HEIGHT
  72.                 SetColor color[0],color[1],color[2]
  73.                 DrawRect x,y,17,17
  74.                 SetHandle 0,0
  75.  
  76.         End Method
  77.  
  78.         Function CreateSpark:TSpark( x#,y#,color[] )
  79.                 Local spark:TSpark=New TSpark
  80.                 Local an#=Rnd(360),sp#=Rnd(3,5)
  81.                 spark.x=x
  82.                 spark.y=y
  83.                 spark.xs=Cos(an)*sp
  84.                 spark.ys=Sin(an)*sp
  85.                 spark.rots=Rnd(-15,15)
  86.                 spark.color=color
  87.                 spark.AddLast sparks
  88.                 Return spark
  89.         End Function
  90.  
  91. End Type
  92.  
  93. Type TBullet Extends TEntity
  94.  
  95.         Field x#,y#,ys#
  96.         Field rot#,img:TImage
  97.  
  98.         Method Update()
  99.                 ys:-.01
  100.                 y:+ys
  101.                 If y<0
  102.                         remove
  103.                         Return
  104.                 EndIf
  105.                 rot:+3
  106.                 SetRotation rot
  107.                 DrawImage img,x,y
  108.         End Method
  109.  
  110.         Function CreateBullet:TBullet( x#,y#,img:TImage )
  111.                 Local bullet:TBullet=New TBullet
  112.                 bullet.x=x
  113.                 bullet.y=y
  114.                 bullet.ys=-1
  115.                 bullet.img=img
  116.                 bullet.AddLast bullets
  117.                 Return bullet
  118.         End Function
  119.  
  120. End Type
  121.  
  122. Function UpdateEntities( list:TList )
  123.         For Local entity:TEntity=EachIn list
  124.                 entity.Update
  125.         Next
  126. End Function
  127.  
  128. Graphics WIDTH,HEIGHT,DEPTH,HERTZ
  129.  
  130. AutoMidHandle True
  131.  
  132. Local fire:TSound=LoadSound( "incbin::shoot.wav" )
  133. Local dude:TImage=LoadImage( "incbin::player.png" ),dude_x=WIDTH/2,dude_y=HEIGHT-30
  134. Local bull:TImage=LoadImage( "incbin::bullet.png" ),bull_x,bull_y
  135. Local stars:TImage=LoadImage( "incbin::stars.png" ),stars_x,stars_y
  136.  
  137. Local show_debug,color_rot#
  138.  
  139. While Not KeyHit( KEY_ESCAPE )
  140.  
  141.         Cls
  142.        
  143.         stars_y:+1
  144.         SetBlend MASKBLEND
  145.         TileImage stars,stars_x,stars_y
  146.         TileImage stars,stars_x+7,stars_y*2
  147.         TileImage stars,stars_x+7,stars_y*3
  148.        
  149.         If KeyDown( KEY_LEFT )
  150.                 dude_x:-5
  151.         Else If  KeyDown( KEY_RIGHT )
  152.                 dude_x:+5
  153.         EndIf
  154.  
  155.         SetBlend MASKBLEND
  156.         DrawImage dude,dude_x,dude_y
  157.  
  158.         If KeyHit( KEY_SPACE )
  159.                 PlaySound fire
  160.                 TBullet.CreateBullet dude_x,dude_y-16,bull
  161.         EndIf
  162.  
  163.         If MouseDown(1)
  164.                 color_rot:+1.5
  165.                 color_rot:Mod 360
  166.                 Local color:TRGBColor=HSVColor( color_rot,1,1 ).RGBColor()
  167.                 Local rgb[]=[Int(color.Red()*255),Int(color.Green()*255),Int(color.Blue()*255)]
  168.                 For Local k=1 To SPARKS_PER_FRAME
  169.                         TSpark.CreateSpark MouseX(),MouseY(),rgb
  170.                 Next
  171.         EndIf
  172.  
  173.         SetBlend MASKBLEND
  174.         UpdateEntities bullets
  175.         SetRotation 0
  176.  
  177.         SetBlend LIGHTBLEND
  178.         UpdateEntities sparks
  179.         SetAlpha 1
  180.         SetRotation 0
  181.         SetColor 255,255,255
  182.        
  183.         If KeyHit( Asc("D") ) show_debug=1-show_debug
  184.        
  185.         If show_debug
  186.                 DrawText "MemAlloced="+GCMemAlloced(),0,0
  187.         EndIf
  188.  
  189.         Flip
  190.        
  191. Wend
  192.  


Blitz3D firepaint 3D sample :

Code: BlitzBasic
  1. ;EnableDirectInput False
  2.  
  3. Global info1$="Firepaint3D Demo"
  4. Global info2$="Features dynamically colored sprites"
  5.  
  6. Include "../start.bb"
  7.  
  8. AmbientLight 0,0,0
  9.  
  10. Const grav#=-.02,intensity=5
  11.  
  12. Type Frag
  13.         Field ys#,alpha#,entity
  14. End Type
  15.  
  16. pivot=CreatePivot()
  17.  
  18. camera=CreateCamera( pivot )
  19. CameraClsMode camera,False,True
  20.  
  21. ;create blitzlogo 'cursor'
  22. cursor=CreateSphere( 8,camera )
  23. EntityTexture cursor,LoadTexture( "blitzlogo.bmp",3 )
  24. MoveEntity cursor,0,0,25
  25. EntityBlend cursor,3
  26. EntityFX cursor,1
  27.  
  28. ;create sky sphere
  29. sky=CreateSphere()
  30. tex=LoadTexture( "stars.bmp" )
  31. ScaleTexture tex,.125,.25
  32. EntityTexture sky,tex
  33. ScaleEntity sky,500,500,500
  34. EntityFX sky,1
  35. FlipMesh sky
  36.  
  37. spark=LoadSprite( "bluspark.bmp" )
  38.  
  39. time=MilliSecs()
  40.  
  41. MoveMouse 0,0
  42.  
  43. While Not KeyDown(1)
  44.  
  45.         Repeat
  46.                 elapsed=MilliSecs()-time
  47.         Until elapsed>0
  48.        
  49.         time=time+elapsed
  50.         dt#=elapsed*60.0/1000.0
  51.        
  52.         Local x_speed#,y_speed#
  53.        
  54.         x_speed=(MouseXSpeed()-x_speed)/4+x_speed
  55.         y_speed=(MouseYSpeed()-y_speed)/4+y_speed
  56.         MoveMouse 320,240
  57.  
  58.         TurnEntity pivot,0,-x_speed,0   ;turn player left/right
  59.         TurnEntity camera,-y_speed,0,0  ;tilt camera
  60.         TurnEntity cursor,0,dt*5,0
  61.        
  62.         If MouseDown(1)
  63.                 For t=1 To intensity
  64.                         f.Frag=New Frag
  65.                         f\ys=0
  66.                         f\alpha=Rnd(2,3)
  67.                         f\entity=CopyEntity( spark,cursor )
  68.                         EntityColor f\entity,Rnd(255),Rnd(255),Rnd(255)
  69.                         EntityParent f\entity,0
  70.                         RotateEntity f\entity,Rnd(360),Rnd(360),Rnd(360)
  71.                         num=num+1
  72.                 Next
  73.         EndIf
  74.        
  75.         For f.Frag=Each Frag
  76.                 f\alpha=f\alpha-dt*.02
  77.                 If f\alpha>0
  78.                         al#=f\alpha
  79.                         If al>1 Then al=1
  80.                         EntityAlpha f\entity,al
  81.                         MoveEntity f\entity,0,0,dt*.4
  82.                         ys#=f\ys+grav*dt
  83.                         dy#=f\ys*dt
  84.                         f\ys=ys
  85.                         TranslateEntity f\entity,0,dy,0
  86.                 Else
  87.                         FreeEntity f\entity
  88.                         Delete f
  89.                         num=num-1
  90.                 EndIf
  91.         Next
  92.  
  93.         UpdateWorld
  94.         RenderWorld
  95. ;       GetColor 0,0
  96. ;       Color 255,0,255
  97. ;       Rect 0,ScanLine(),640,1
  98.         Flip
  99. Wend
  100.  
  101. End
  102.  
Mac mini ( 2018 / 2020 ), 3 GHz 6-Core Intel Core i5, 16 GB 2667 MHz DDR4, 1TB NVMe, eGPU Radeon Pro 580 8 GB, LG Ultragear 27GL83A-B 27 Inch
Commodore VIC-20, 1.1Mhz MOS 6502 CPU, 5KB RAM, VIC ( 6560 ) GPU

Until the next time...

Offline Brucey

  • Full Member
  • ***
  • Posts: 134
Re: Syntax highlighting now available for multiple languages
« Reply #1 on: June 17, 2017, 08:54:05 PM »
Mostly working, apart from the Rem blocks :-)

Offline MikeHart

  • Hero Member
  • *****
  • Posts: 718
  • Cerberus-X Developer
    • Whitesky Games
Re: Syntax highlighting now available for multiple languages
« Reply #2 on: June 17, 2017, 08:54:51 PM »
YEAH! Thanks!

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2515
  • I mostly code at night... Mostly.
    • SyntaxBomb - Indie Coders
Re: Syntax highlighting now available for multiple languages
« Reply #3 on: June 17, 2017, 10:33:56 PM »
Mostly working, apart from the Rem blocks :-)
Everyones a critic :P

Not sure why Rem / EndRem isn't all 'remmed' out as the GeSHi module for Monkey has the correct multi comment section added in. Unless it doesn't support keyword multi comment properly?
Mac mini ( 2018 / 2020 ), 3 GHz 6-Core Intel Core i5, 16 GB 2667 MHz DDR4, 1TB NVMe, eGPU Radeon Pro 580 8 GB, LG Ultragear 27GL83A-B 27 Inch
Commodore VIC-20, 1.1Mhz MOS 6502 CPU, 5KB RAM, VIC ( 6560 ) GPU

Until the next time...

Offline therevills

  • Hero Member
  • *****
  • Posts: 611
Re: Syntax highlighting now available for multiple languages
« Reply #4 on: June 18, 2017, 01:58:22 AM »
Nice!

Any chance of a codebox instead of just code, like the one on the old bb.com site? (So it adds the code to an iframe and you can scroll thru it, also it doesnt take it so much real estate.

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2515
  • I mostly code at night... Mostly.
    • SyntaxBomb - Indie Coders
Re: Syntax highlighting now available for multiple languages
« Reply #5 on: June 18, 2017, 02:25:52 AM »
Quote
Any chance of a codebox instead of just code, like the one on the old bb.com site? (So it adds the code to an iframe and you can scroll thru it, also it doesnt take it so much real estate.
I noticed earlier that on Safari they do appear in a proper codebox but on Chrome they do not. I will investigate and press keys until it's fixed :)
Mac mini ( 2018 / 2020 ), 3 GHz 6-Core Intel Core i5, 16 GB 2667 MHz DDR4, 1TB NVMe, eGPU Radeon Pro 580 8 GB, LG Ultragear 27GL83A-B 27 Inch
Commodore VIC-20, 1.1Mhz MOS 6502 CPU, 5KB RAM, VIC ( 6560 ) GPU

Until the next time...

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2515
  • I mostly code at night... Mostly.
    • SyntaxBomb - Indie Coders
Re: Syntax highlighting now available for multiple languages
« Reply #6 on: June 18, 2017, 03:24:52 AM »
Quote
Any chance of a codebox instead of just code, like the one on the old bb.com site? (So it adds the code to an iframe and you can scroll thru it, also it doesnt take it so much real estate.
Sorted... You may need to clear your browsing data for SyntaxBomb ( for some silly reason )

Mac mini ( 2018 / 2020 ), 3 GHz 6-Core Intel Core i5, 16 GB 2667 MHz DDR4, 1TB NVMe, eGPU Radeon Pro 580 8 GB, LG Ultragear 27GL83A-B 27 Inch
Commodore VIC-20, 1.1Mhz MOS 6502 CPU, 5KB RAM, VIC ( 6560 ) GPU

Until the next time...

Offline therevills

  • Hero Member
  • *****
  • Posts: 611
Re: Syntax highlighting now available for multiple languages
« Reply #7 on: June 18, 2017, 06:07:23 AM »
Still not working for me, I've cleared the cookie for SyntaxBomb... never mind I'll live with it :)

(Running Windows 10, Chrome 59.0.3071.86... although it is updating now... now 59.0.3071.104)

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2515
  • I mostly code at night... Mostly.
    • SyntaxBomb - Indie Coders
Re: Syntax highlighting now available for multiple languages
« Reply #8 on: June 18, 2017, 08:38:18 AM »
Quote
Still not working for me, I've cleared the cookie for SyntaxBomb
God damn you trouble makers!! :P

I think it's more of a browser cache issue to do with some bizarre dynamic on the fly CSS. I make up that waffle as it appears that's what GeSHi does ??? - I had a quick scout through the source and I can't find any files to do with the CSS it makes and calls ( no doubt it's all easy when you know what it's doing ) - I had the same issue with Chrome on my Mac but after clearing all the SyntaxBomb cache ( not just the cookies ) it magically worked as it was supposed to do.

Out of curiosity, see what it does on a "private browsing" tab. I suspect it's fine in their and shows it's a cache issue. If not then just shut up about it :P
Mac mini ( 2018 / 2020 ), 3 GHz 6-Core Intel Core i5, 16 GB 2667 MHz DDR4, 1TB NVMe, eGPU Radeon Pro 580 8 GB, LG Ultragear 27GL83A-B 27 Inch
Commodore VIC-20, 1.1Mhz MOS 6502 CPU, 5KB RAM, VIC ( 6560 ) GPU

Until the next time...

Offline MikeHart

  • Hero Member
  • *****
  • Posts: 718
  • Cerberus-X Developer
    • Whitesky Games
Re: Syntax highlighting now available for multiple languages
« Reply #9 on: June 18, 2017, 09:57:13 AM »
Works fine here. Newest Chrome, Windows 7 64bit.

Offline Krischan

  • Full Member
  • ***
  • Posts: 221
    • Krischan's Homepage
Re: Syntax highlighting now available for multiple languages
« Reply #10 on: June 18, 2017, 10:31:51 AM »
Works here too, Firefox 54.0 x64. For Blitzbasic/Blitzmax I'd prefer the original IDE colorful template with the blue background like in IDEal :-p
Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
My Blitzbasic Archive | Extrasolar Project | My Github projects

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal