@jawirhytam/kurokuro
v1.1.2
Published
A DjawaScript Turtle Graphics library.
Maintainers
Readme
Kurokuro 🐢
A simple and fun turtle graphics library for DjawaScript.
With Kurokuro, you can create drawings and patterns by giving commands to a "turtle" to move on a canvas.
(The image above is a placeholder; you can replace it with a screenshot of your code's output)
Table of Contents
Installation
To use Kurokuro, you will need two packages: djawascript (as the command-line tool) and kurokuro (the graphics library itself).
Install DjawaScript globally: Open your terminal and run the following command. You might need
sudoon Linux/macOS.npm install -g @jawirhytam/djawascriptInstall Kurokuro in Your Project: Create a new directory for your project, navigate into it, and install Kurokuro locally.
mkdir my-kurokuro-project cd my-kurokuro-project npm install @jawirhytam/kurokuro
Now you are ready to start drawing!
Usage
The process is very straightforward and designed to feel like running a regular script.
Step 1: Initialize Your Script
Create a new file with a .jawa extension (e.g., drawing.jawa). To tell djawa that this file will use the Kurokuro graphics library, you must add a special comment at the very top of your file:
// @kurokuro: pakeStep 2: Write Your Code
Use the functions from the Kurokuro API to start drawing.
// @kurokuro: pake
// Draw a simple square
kanggo (jarno i = 0; i < 4; i++) terus
maju(100);
mengen(90);
mbariStep 3: Run Your Script
Save your file, and run it using djawa run from your terminal.
djawa run drawing.jawaAn application window will appear and instantly display your drawing!
API Reference
Here are all the commands you can give to the turtle.
| Function | Parameters | Description |
| :--- | :--- | :--- |
| maju(distance) | distance: Angka | Moves the turtle forward by distance pixels. |
| mundur(distance) | distance: Angka | Moves the turtle backward by distance pixels. |
| mengen(degrees) | degrees: Angka | Turns the turtle right by degrees. |
| mengiri(degrees) | degrees: Angka | Turns the turtle left by degrees. |
| penMunggah() | - | Lifts the pen up. The turtle will move without drawing. |
| penMudun() | - | Puts the pen down. The turtle will draw again when moving. |
| reset() | - | Clears all drawings on the canvas and resets the turtle to its initial position. |
Complete Example
Here is an example to draw a hexagon.
hexagon.jawa
// @kurokuro: pake
// Clear the canvas and reset the turtle to the center
reset();
// Define properties for the hexagon
jarno sides = 6;
jarno sideLength = 80;
jarno angle = 360 / sides;
cetakno("Drawing a hexagon...");
// Loop to draw each side
kanggo (jarno i = 0; i < sides; i = i + 1) terus
maju(sideLength);
mengen(angle);
mbari
cetakno("Hexagon drawing complete!");To run it:
djawa run hexagon.jawaThis will open an application window displaying the hexagon you've created.
