Read this first: https://10print.org/
create a new b4j project and paste this code:
create a new b4j project and paste this code:
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private vpW, vpH As Float
Private cnv As Canvas
Private timer1 As Timer
Private left = 0, top = 0, spacing = 10 As Float
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
vpW = MainForm.RootPane.Width
vpH = MainForm.RootPane.Height
cnv.Initialize("")
MainForm.RootPane.AddNode(cnv,0,0, vpW, vpH)
timer1.Initialize("timer1",25)
timer1.Enabled = True
End Sub
Sub timer1_Tick
If Rnd(0,10) < 5 Then cnv.DrawLine(left,top,left+spacing,top+spacing,fx.Colors.Black,2) Else _ 'LINE MODE
cnv.DrawLine(left+spacing,top,left,top+spacing,fx.Colors.Black,2)
' If Rnd(0,10) < 5 Then cnv.DrawRect(left,top,spacing,spacing,fx.Colors.Black,True,0) Else _ 'RECT MODE
' cnv.DrawRect(left,top,spacing,spacing,fx.Colors.White,True,0)
' If Rnd(0,10) < 5 Then cnv.DrawText("p",left,top,fx.DefaultFont(16),fx.Colors.Black,"LEFT") Else _ 'TEXT MODE
' cnv.DrawText("b",left,top,fx.DefaultFont(16),fx.Colors.Black,"LEFT")
moveRight
End Sub
Sub moveRight
left = left + spacing
If left > vpW Then
left = 0
top = top + spacing
End If
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Attachments
Last edited: