Syntax highlighting now available for multiple languages

Started by Qube, June 17, 2017, 20:48:38

Previous topic - Next topic

Qube

We now have syntax highlighting for multiple languages including Monkey, BlitzMax and BlitzBasic.

It works like so :


{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) Select


'Firepaint redux!
'
'Really a multitouch test...

Import mojo

Global BigList:=New List<Spark>

Class Spark

Field x#,y#,xv#,yv#,a#

Method New( x#,y# )
Self.x=x
Self.y=y
Local an#=Rnd(360),v#=Rnd(3,4)
Self.xv=Cos(an)*v
Self.yv=Sin(an)*v
Self.a=1
End

End

Class Firepaint Extends App

Field sparkImage:Image
Field sparks:=New List<Spark>

Field prim

Method OnCreate()

For Local i=0 Until 65536*16
' BigList.AddLast New Spark
Next

sparkImage=LoadImage( "bluspark.png",1,Image.MidHandle )

SetUpdateRate 60
End

Method OnUpdate()

Local out:=New List<Spark>
For Local spark:=Eachin sparks
spark.a=Max(spark.a-.01,0.0)
If spark.a<=0 Continue
spark.yv+=.05
spark.x+=spark.xv
spark.y+=spark.yv
out.AddLast spark
Next

sparks=out

For Local i=0 Until 32
If TouchDown( i )
For Local j=1 To 10
sparks.AddLast New Spark( TouchX(i),TouchY(i) )
next
Endif
Next

If KeyHit( KEY_SPACE )
prim=(prim+1) Mod 4
Endif

End

Method OnRender()

Local w=DeviceWidth,h=DeviceHeight

SetBlend LightenBlend

Cls

DrawText "This way UP!",0,0

SetColor 255,0,0
DrawRect 0,0,w,32
SetColor 0,255,0
DrawRect w-32,0,32,h
SetColor 0,0,255
DrawRect 0,h-32,w,32
SetColor 128,128,128
DrawRect 0,0,32,h

For Local spark:=Eachin sparks

SetAlpha spark.a

Select prim
Case 0
DrawImage sparkImage,spark.x,spark.y
Case 1
DrawRect spark.x-15,spark.y-15,30,30
Case 2
DrawOval spark.x-15,spark.y-15,30,30
Case 3
DrawLine spark.x-15,spark.y-15,spark.x+15,spark.y+15
DrawLine spark.x+15,spark.y-15,spark.x-15,spark.y+15
End
Next
End

End

Function Main()

New Firepaint

End



BlitzMax firepaint sample :

Code (blitzmax) Select

Rem

Firepaint demo:

Hold down mouse button to emit *FIRE*!

EndRem

Strict

'For minimal build...
Rem
Framework BRL.D3D7Max2D
Import BRL.Basic
Import BRL.System
Import BRL.PNGLoader
Import BRL.FreeAudioAudio
Import BRL.WAVLoader
End Rem

Import "color.bmx"

Incbin "stars.png"
Incbin "player.png"
Incbin "bullet.png"
Incbin "shoot.wav"

Const WIDTH=640,HEIGHT=480
Const DEPTH=32,HERTZ=60

Const GRAVITY#=.15,SPARKS_PER_FRAME=55

Global sparks:TList=New TList
Global bullets:TList=New TList

Type TEntity

Field link:TLink

Method remove()
link.remove
End Method

Method AddLast( list:TList )
link=list.AddLast( Self )
End Method

Method Update() Abstract

End Type

Type TSpark Extends TEntity

Field x#,y#,xs#,ys#
Field color[3],rot#,rots#

Method Update()

ys:+GRAVITY
x:+xs
y:+ys

If x<0 Or x>=WIDTH Or y>=HEIGHT
remove
Return
EndIf

rot=rot+rots
SetHandle 8,8
SetRotation rot#
SetAlpha 1-y/HEIGHT
SetColor color[0],color[1],color[2]
DrawRect x,y,17,17
SetHandle 0,0

End Method

Function CreateSpark:TSpark( x#,y#,color[] )
Local spark:TSpark=New TSpark
Local an#=Rnd(360),sp#=Rnd(3,5)
spark.x=x
spark.y=y
spark.xs=Cos(an)*sp
spark.ys=Sin(an)*sp
spark.rots=Rnd(-15,15)
spark.color=color
spark.AddLast sparks
Return spark
End Function

End Type

Type TBullet Extends TEntity

Field x#,y#,ys#
Field rot#,img:TImage

Method Update()
ys:-.01
y:+ys
If y<0
remove
Return
EndIf
rot:+3
SetRotation rot
DrawImage img,x,y
End Method

Function CreateBullet:TBullet( x#,y#,img:TImage )
Local bullet:TBullet=New TBullet
bullet.x=x
bullet.y=y
bullet.ys=-1
bullet.img=img
bullet.AddLast bullets
Return bullet
End Function

End Type

Function UpdateEntities( list:TList )
For Local entity:TEntity=EachIn list
entity.Update
Next
End Function

Graphics WIDTH,HEIGHT,DEPTH,HERTZ

AutoMidHandle True

Local fire:TSound=LoadSound( "incbin::shoot.wav" )
Local dude:TImage=LoadImage( "incbin::player.png" ),dude_x=WIDTH/2,dude_y=HEIGHT-30
Local bull:TImage=LoadImage( "incbin::bullet.png" ),bull_x,bull_y
Local stars:TImage=LoadImage( "incbin::stars.png" ),stars_x,stars_y

Local show_debug,color_rot#

While Not KeyHit( KEY_ESCAPE )

Cls

stars_y:+1
SetBlend MASKBLEND
TileImage stars,stars_x,stars_y
TileImage stars,stars_x+7,stars_y*2
TileImage stars,stars_x+7,stars_y*3

If KeyDown( KEY_LEFT )
dude_x:-5
Else If  KeyDown( KEY_RIGHT )
dude_x:+5
EndIf

SetBlend MASKBLEND
DrawImage dude,dude_x,dude_y

If KeyHit( KEY_SPACE )
PlaySound fire
TBullet.CreateBullet dude_x,dude_y-16,bull
EndIf

If MouseDown(1)
color_rot:+1.5
color_rot:Mod 360
Local color:TRGBColor=HSVColor( color_rot,1,1 ).RGBColor()
Local rgb[]=[Int(color.Red()*255),Int(color.Green()*255),Int(color.Blue()*255)]
For Local k=1 To SPARKS_PER_FRAME
TSpark.CreateSpark MouseX(),MouseY(),rgb
Next
EndIf

SetBlend MASKBLEND
UpdateEntities bullets
SetRotation 0

SetBlend LIGHTBLEND
UpdateEntities sparks
SetAlpha 1
SetRotation 0
SetColor 255,255,255

If KeyHit( Asc("D") ) show_debug=1-show_debug

If show_debug
DrawText "MemAlloced="+GCMemAlloced(),0,0
EndIf

Flip

Wend



Blitz3D firepaint 3D sample :

Code (blitzbasic) Select

;EnableDirectInput False

Global info1$="Firepaint3D Demo"
Global info2$="Features dynamically colored sprites"

Include "../start.bb"

AmbientLight 0,0,0

Const grav#=-.02,intensity=5

Type Frag
Field ys#,alpha#,entity
End Type

pivot=CreatePivot()

camera=CreateCamera( pivot )
CameraClsMode camera,False,True

;create blitzlogo 'cursor'
cursor=CreateSphere( 8,camera )
EntityTexture cursor,LoadTexture( "blitzlogo.bmp",3 )
MoveEntity cursor,0,0,25
EntityBlend cursor,3
EntityFX cursor,1

;create sky sphere
sky=CreateSphere()
tex=LoadTexture( "stars.bmp" )
ScaleTexture tex,.125,.25
EntityTexture sky,tex
ScaleEntity sky,500,500,500
EntityFX sky,1
FlipMesh sky

spark=LoadSprite( "bluspark.bmp" )

time=MilliSecs()

MoveMouse 0,0

While Not KeyDown(1)

Repeat
elapsed=MilliSecs()-time
Until elapsed>0

time=time+elapsed
dt#=elapsed*60.0/1000.0

Local x_speed#,y_speed#

x_speed=(MouseXSpeed()-x_speed)/4+x_speed
y_speed=(MouseYSpeed()-y_speed)/4+y_speed
MoveMouse 320,240

TurnEntity pivot,0,-x_speed,0 ;turn player left/right
TurnEntity camera,-y_speed,0,0 ;tilt camera
TurnEntity cursor,0,dt*5,0

If MouseDown(1)
For t=1 To intensity
f.Frag=New Frag
f\ys=0
f\alpha=Rnd(2,3)
f\entity=CopyEntity( spark,cursor )
EntityColor f\entity,Rnd(255),Rnd(255),Rnd(255)
EntityParent f\entity,0
RotateEntity f\entity,Rnd(360),Rnd(360),Rnd(360)
num=num+1
Next
EndIf

For f.Frag=Each Frag
f\alpha=f\alpha-dt*.02
If f\alpha>0
al#=f\alpha
If al>1 Then al=1
EntityAlpha f\entity,al
MoveEntity f\entity,0,0,dt*.4
ys#=f\ys+grav*dt
dy#=f\ys*dt
f\ys=ys
TranslateEntity f\entity,0,dy,0
Else
FreeEntity f\entity
Delete f
num=num-1
EndIf
Next

UpdateWorld
RenderWorld
; GetColor 0,0
; Color 255,0,255
; Rect 0,ScanLine(),640,1
Flip
Wend

End
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Brucey


MikeHart


Qube

Quote from: Brucey on June 17, 2017, 20:54:05
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 Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

therevills

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.

Qube

QuoteAny 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 Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Qube

QuoteAny 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 Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

therevills

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)

Qube

QuoteStill 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 Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

MikeHart


Krischan

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]
Metaverse | Blitzbasic Archive | My Github projects