Skip to content

Conversation

@wfouche
Copy link
Contributor

@wfouche wfouche commented Jul 10, 2025

A turtle graphics example program for the kids (or young at heart) learning to program in Java using JBang

image

@wfouche
Copy link
Contributor Author

wfouche commented Jul 11, 2025

Ready to be reviewed

@wfouche
Copy link
Contributor Author

wfouche commented Jul 11, 2025

@quintesse , @maxandersen

Just thinking out loud. Would it ever make sense to support the following functionaliy allowing the path to a local JAR file to be specified as a dependency?

//DEPS ./aplu5.jar

or maybe even (without having to first download the jar file) support the following syntax as well.

//DEPS https://java-online.ch/download/aplu5.jar

Some jars are not published to Maven Central, but can be downloaded from project specific web sites to a local folder. APLU5.jar is one of them. APLU5.jar is self-contained and do not depend on any other external Java libraries.

@wfouche
Copy link
Contributor Author

wfouche commented Jul 11, 2025

What is the "best" turtle graphics library for Java?

@maxandersen
Copy link
Collaborator

Standalone jars are not dependencies but class path entries. '--classpath %{url}' should work.

Not at laptop atm so can't verify if we ever got around to implement //CLASPATH in source files.

@maxandersen
Copy link
Collaborator

What is the "best" turtle graphics library for Java?

Link doesn't work

// Usage: jbang turtle.java
// Requires: JDK 8 or higher

//DEPS ch.aplu.turtle:aplu5:0.1.9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i love the idea of turtle example but if it not something available from maven central or that some other way jbang can fetch it (*) then i think it makes more damage than good

(*) yes, we should probably support //CLASSPATH but we dont right now)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, there are not other good Java-based turtle examples. This is the only one that I could find.

Now updated to the Java 25 version that you provided.

@wfouche
Copy link
Contributor Author

wfouche commented Aug 15, 2025

This new TurtleDemo.java program can be run without relying on external dependencies.

$ jbang run TurtleDemo.java

@wfouche wfouche requested a review from quintesse August 15, 2025 17:36
@wfouche wfouche changed the title feat: a turtle graphics example using aplu5.jar feat: a turtle graphics demo program Aug 15, 2025
@wfouche
Copy link
Contributor Author

wfouche commented Aug 15, 2025

Link doesn't work

Unfortunately, none of the Turtle graphics libraries created for Java are availalbe from Maven Central. They are mostly available as source code or downloadable JAR files.

The Turtle Demo has been re-implemented using Turtle.java from

@quintesse
Copy link
Contributor

Well running jbang https://github.com/jbangdev/jbang-examples/blob/ae3947cda944f2e354cf65a970d15b97a1084964/examples/turtle/TurtleDemo.java definitely works :-)

@quintesse
Copy link
Contributor

But somehow I would find this even more "impressive":

///usr/bin/env jbang "$0" "$@" ; exit $?

//SOURCES https://github.com/NicholasSeward/Turtle/blob/main/Turtle.java

import java.awt.Color;

public class TurtleDemo {
    public static void main(String[] args) {
        Turtle joe = new Turtle();
        joe.penColor(Color.RED);
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 4; j++) {
                joe.forward(150);
                joe.right(90);
            }
            joe.left(36);
        }
        joe.left(90);
    }
}

No need to copy a file, instead it gets taken directly from the source.

Copy link
Collaborator

had same thought @quintesse.

One reason to copy it though could be so we could get rid of these warnings:

/Users/max/.jbang/cache/urls/8534b236b27dedef0acdcb3141b4961123c53487ef787f1ef59f09bc23ebda89/Turtle.java:41: warning: [removal] JApplet in javax.swing has been deprecated and marked for removal
    private static JApplet applet;
                   ^
/Users/max/.jbang/cache/urls/8534b236b27dedef0acdcb3141b4961123c53487ef787f1ef59f09bc23ebda89/Turtle.java:221: warning: [removal] JApplet in javax.swing has been deprecated and marked for removal
    public static void startApplet(JApplet applet)
                                   ^
Note: /Users/max/.jbang/cache/urls/8534b236b27dedef0acdcb3141b4961123c53487ef787f1ef59f09bc23ebda89/Turtle.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

@quintesse
Copy link
Contributor

Sure, but it would be nicer to do that upstream, right?

@quintesse
Copy link
Contributor

Btw, I just found another one-file library that could be nice for a JBang example: https://github.com/arkanovicz/essential-json/blob/master/src/main/java/com/republicate/json/Json.java it's a JSON parser in a single file (there's also a Maven artifact, but where's the fun in that? :-) )

@wfouche
Copy link
Contributor Author

wfouche commented Aug 19, 2025

I've submitted a pull request to resolve one of the warnings in the Turtle.java code

@wfouche
Copy link
Contributor Author

wfouche commented Aug 19, 2025

Turtle.java itself has a main method with a nice demo that it runs.

$ jbang run https://github.com/NicholasSeward/Turtle/blob/main/Turtle.java

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants