ChatSD also managed touch
AI it's interesting and I use it a lot, but I can say that it is useful for creating small parts of a code. A complex query or solve some problems in known languages.
B4J code generated by ChatGPT (it only failed to handle arrow key press events).
Yes, in fact it was an answer to ChatGPT. It's still not at chatSD level
I know your skills in this area, @Star-Dust, but mine are much poorer. Note that I was not interested in getting something usable, I just wanted to test out ChatGPT's capabilities.
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private Timer1 As Timer
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
' Create a 3D sphere
Dim sphere As JavaObject
sphere.InitializeNewInstance("javafx.scene.shape.Sphere", Array(100)) ' 100 is the radius of the sphere
' Create a 3D scene
Dim scene As JavaObject
scene.InitializeNewInstance("javafx.scene.Scene", Array(MainForm.RootPane, 800, 600, True))
scene.RunMethod("setFill", Array(fx.Colors.White))
' Add the sphere to the scene
Dim root As JavaObject = scene.RunMethod("getRoot", Null)
root.RunMethod("getChildren", Null).RunMethod("add", Array(sphere))
' Create a PointLight
Dim pointLight As JavaObject
pointLight.InitializeNewInstance("javafx.scene.PointLight", Null)
pointLight.RunMethod("setColor", Array(fx.Colors.White))
pointLight.RunMethod("setTranslateX", Array(200))
pointLight.RunMethod("setTranslateY", Array(-100))
pointLight.RunMethod("setTranslateZ", Array(-300))
' Add the light to the scene
root.RunMethod("getChildren", Null).RunMethod("add", Array(pointLight))
' Set the scene to the form
MainForm.RootPane.RunMethod("setScene", Array(scene))
' Create a RotateTransition for the sphere
Dim rotateTransition As JavaObject
rotateTransition.InitializeNewInstance("javafx.animation.RotateTransition", Array(2000, sphere)) ' 2000 ms duration
rotateTransition.RunMethod("setByAngle", Array(360)) ' Rotate by 360 degrees
rotateTransition.RunMethod("setCycleCount", Array(-1)) ' Infinite loop
rotateTransition.RunMethod("setAutoReverse", Array(False))
' Start the rotation
rotateTransition.RunMethod("play", Null)
End Sub
Nothing (I think it's just a gift for @Star-Dust )Don't know what it has done with the Timer.....
Many errors.This is what Copilot gives me when asked to draw a 3D sphere in B4J and to rotate it. Have not tried it in a B4J project
I am sure that with a bit of effort one could turn this into a 3D rotating sphere.Many errors.
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
' Create a 3D sphere
Dim sphere As JavaObject
sphere.InitializeNewInstance("javafx.scene.shape.Sphere", Array(100.00)) ' 100 is the radius of the sphere
' Add the sphere to the scene
MainForm.RootPane.AddNode(sphere,300,300,-1,-1)
' Create a PointLight
Dim pointLight As JavaObject
pointLight.InitializeNewInstance("javafx.scene.PointLight", Null)
pointLight.RunMethod("setColor", Array(fx.Colors.blue))
pointLight.RunMethod("setTranslateX", Array(200.0))
pointLight.RunMethod("setTranslateY", Array(-100.0))
pointLight.RunMethod("setTranslateZ", Array(-600.0))
' Add the light to the scene
MainForm.RootPane.AddNode(pointLight,300,300,-1,-1)
' Set the scene to the form
'MainForm.RootPane.RunMethod("setScene", Array(scene))
' Create a RotateTransition for the sphere
' Dim rotateTransition As JavaObject
' rotateTransition.InitializeNewInstance("javafx.animation.RotateTransition", Array(2000, sphere)) ' 2000 ms duration
' rotateTransition.RunMethod("setByAngle", Array(360)) ' Rotate by 360 degrees
' rotateTransition.RunMethod("setCycleCount", Array(-1)) ' Infinite loop
' rotateTransition.RunMethod("setAutoReverse", Array(False))
' Start the rotation
' rotateTransition.RunMethod("play", Null)
End Sub
SureNothing (I think it's just a gift for @Star-Dust )
With bit effort with B4X and without AI he made a 3D in multiplatformI am sure that with a bit of effort one could turn this into a 3D rotating sphere.
Post the code that generated
B4J code generated by ChatGPT (it only failed to handle arrow key press events).
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
' get image for sphere
Dim img As Image
img.Initialize("C:/temp","mypicture.png")
'create material
Dim material As JavaObject
material.InitializeNewInstance("javafx.scene.paint.PhongMaterial",Null)
material.RunMethod("setDiffuseMap",Array(img))
' Create a 3D sphere
Dim sphere As JavaObject
sphere.InitializeNewInstance("javafx.scene.shape.Sphere", Array(100.00)) ' 100 is the radius of the sphere
'set sphere material
sphere.RunMethod("setMaterial",Array(material))
' Add the sphere to the scene
MainForm.RootPane.AddNode(sphere,300,300,-1,-1)
' Create a PointLight
Dim pointLight As JavaObject
pointLight.InitializeNewInstance("javafx.scene.PointLight", Null)
pointLight.RunMethod("setColor", Array(fx.Colors.white))
pointLight.RunMethod("setTranslateX", Array(200.0))
pointLight.RunMethod("setTranslateY", Array(-100.0))
pointLight.RunMethod("setTranslateZ", Array(-600.0))
' Add the light to the scene
MainForm.RootPane.AddNode(pointLight,300,300,-1,-1)
' duration of animation
Dim duration As JavaObject
duration.InitializeNewInstance("javafx.util.Duration",Array(4000.00))
'set axis for rotation
Dim axis As JavaObject
axis.InitializeNewInstance("javafx.geometry.Point3D",Array(0.0,1.0,0.0)) ' x,y,z one with 1.0 is axis to use
' Create a RotateTransition for the sphere
Dim rotateTransition As JavaObject
rotateTransition.InitializeNewInstance("javafx.animation.RotateTransition", Array(duration, sphere)) ' 2000 ms duration
rotateTransition.RunMethod("setByAngle", Array(359.0)) ' Rotate by 360 degrees
rotateTransition.RunMethod("setCycleCount", Array(-1)) ' Infinite loop
rotateTransition.RunMethod("setAutoReverse", Array(False))
rotateTransition.RunMethod("setAxis",Array(axis))
' Start the rotation
rotateTransition.RunMethod("play", Null)
End Sub
#Region Project Attributes
#MainFormWidth: 800
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private Timer1 As Timer
Private Canvas1 As Canvas
Private Sphere As List
Private Angle As Double
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1") ' Load the layout file.
MainForm.Show
Timer1.Initialize("Timer1", 30)
Timer1.Enabled = True
Sphere.Initialize
CreateSphere(150, 20, 20)
End Sub
Sub Timer1_Tick
Angle = Angle + 0.05
DrawSphere
End Sub
Sub CreateSphere(Radius As Double, Latitudes As Int, Longitudes As Int)
For i = 0 To Latitudes
Dim theta As Double = i * cPI / Latitudes
Dim sinTheta As Double = Sin(theta)
Dim cosTheta As Double = Cos(theta)
For j = 0 To Longitudes
Dim phi As Double = j * 2 * cPI / Longitudes
Dim sinPhi As Double = Sin(phi)
Dim cosPhi As Double = Cos(phi)
Dim x As Double = Radius * cosPhi * sinTheta
Dim y As Double = Radius * cosTheta
Dim z As Double = Radius * sinPhi * sinTheta
Dim point As Map
point.Initialize
point.Put("x", x)
point.Put("y", y)
point.Put("z", z)
Sphere.Add(point)
Next
Next
End Sub
Sub DrawSphere
Canvas1.ClearRect(0, 0, Canvas1.Width, Canvas1.Height)
For Each point As Map In Sphere
Dim x As Double = point.Get("x")
Dim y As Double = point.Get("y")
Dim z As Double = point.Get("z")
Dim screenX As Double = x * Cos(Angle) - z * Sin(Angle)
Dim screenY As Double = y
Dim screenZ As Double = x * Sin(Angle) + z * Cos(Angle)
Dim scale As Double = 300 / (300 + screenZ)
screenX = screenX * scale + Canvas1.Width / 2
screenY = screenY * scale + Canvas1.Height / 2
Canvas1.DrawCircle(screenX, screenY, 2, fx.Colors.Black, True, 1)
Next
End Sub
#Region Project Attributes
#MainFormWidth: 800
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private Canvas1 As Canvas
Private Sphere As Sphere3D
Private xAngle, yAngle As Float
Private MouseX, MouseY As Float
Private IsDragging As Boolean
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
Sphere.Initialize(Canvas1)
Canvas1 = Sphere.DrawSphere(105.0f, 0.0f)
End Sub
Private Sub Canvas1_MousePressed (EventData As MouseEvent)
MouseX = EventData.x
MouseY = EventData.y
IsDragging = True
End Sub
Private Sub Canvas1_MouseDragged (EventData As MouseEvent)
Dim x As Double = EventData.x
Dim y As Double = EventData.y
If IsDragging Then
xAngle = xAngle + (x - MouseX) * 0.1
yAngle = yAngle + (y - MouseY) * 0.1
MouseX = x
MouseY = y
Canvas1 = Sphere.DrawSphere(xAngle, yAngle)
End If
End Sub
Private Sub Canvas1_MouseReleased (EventData As MouseEvent)
IsDragging = False
End Sub
Sub Class_Globals
Private cvs As Canvas
Dim fx As JFX
End Sub
Public Sub Initialize(c As Canvas)
cvs = c
End Sub
public Sub DrawSphere(xAngle As Float, yAngle As Float) As Canvas
cvs.ClearRect(0, 0, cvs.Width, cvs.Height)
Dim radius As Float = Min(cvs.Width, cvs.Height) / 3
Dim centerX As Float = cvs.Width / 2
Dim centerY As Float = cvs.Height / 2
For lat = -90 To 90 Step 5
For lon = -180 To 180 Step 5
Dim x1, y1, z1 As Float
x1 = radius * CosD(lat) * CosD(lon)
y1 = radius * CosD(lat) * SinD(lon)
z1 = radius * SinD(lat)
Dim x2, y2 As Float
x2 = centerX + x1 * CosD(yAngle) - z1 * SinD(yAngle)
y2 = centerY + y1 * CosD(xAngle) - (x1 * SinD(yAngle) + z1 * CosD(yAngle)) * SinD(xAngle)
cvs.DrawCircle(x2, y2, 1, fx.Colors.Black, True, 1)
Next
Next
Return cvs
End Sub
Same with ChatGPT.but had to do some open-heart surgery on the Copilot code to make it work in B4J