ChatGPT - "3D sphere"

Star-Dust

Expert
Licensed User
Longtime User
ChatSD also handled touch

1727275944891.png
27.gif

 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User

B4J code generated by ChatGPT (it only failed to handle arrow key press events).
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.
But it is not efficient in all languages, it often applies the syntax of another language or non-existent methods, it always needs to be fixed. It also can't develop an app unless it's very small. Often uses instructions incorrectly.
 

Star-Dust

Expert
Licensed User
Longtime User
😅

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.
Yes, in fact it was an answer to ChatGPT. It's still not at chatSD level
 

Johan Schoeman

Expert
Licensed User
Longtime User
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. Don't know what it has done with the Timer.....

write b4j code to draw a 3d sphere:
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
 

Daestrum

Expert
Licensed User
Longtime User
most of the errors were caused by passing integer values where it needed doubles.

also a white sphere on a white background with a white light - not a good combination if you actually want to see anything.

modified code (no rotation - as a plain sphere wont look like its rotating anyways)
B4X:
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
 

Star-Dust

Expert
Licensed User
Longtime User
I am sure that with a bit of effort one could turn this into a 3D rotating sphere.
With bit effort with B4X and without AI he made a 3D in multiplatform

I have tested Copilot a lot, it also has a fairly effective image generation. For the rest they don't change much. I use both, when I'm lucky one gives me an acceptable result


B4J code generated by ChatGPT (it only failed to handle arrow key press events).
Post the code that generated
 
Last edited:
Top