Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<img src="./src/main/resources/applogo/appicon.png" width="40%" />
</td>
<td>
<h3>Piccaso Code</h3>
<h3>Picasso Code</h3>
<h6>Creativity + Logic + Math</h6>
<p>A code based image editor created 100% in java</p>
</td>
Expand All @@ -15,17 +15,17 @@
[![Java CI with Maven](https://github.com/Glimmr-Lang/PicassoCode/actions/workflows/maven.yml/badge.svg)](https://github.com/Glimmr-Lang/PicassoCode/actions/workflows/maven.yml)

## About
Piccasso code is an image editor that uses code to create/edit an image. This allows powerful designs to be created with ease and
automation. The editor uses *glimr* as the scripting language for writing the image editing code.
Picasso code is an image editor that uses code to create/edit an image. This allows powerful designs to be created with ease and
automation. The editor uses *PiccodeScript* as the scripting language for writing the image editing code.

## Download
>> Coming soon

## Building

```sh
$ git clone git@github.com:hexaredecimal/Piccode.git
$ cd Piccode
$ git clone https://github.com/Glimmr-Lang/PicassoCode.git
$ cd PicassoCode
$ mvn package
```
### Test your build
Expand All @@ -35,7 +35,7 @@ $ java -jar target/Piccode-1.0-SNAPSHOT-jar-with-dependencies.jar


## Inspired by
Piccassocode is heavily inspired by the [OpenSCAD](https://openscad.org/) program and tries to mimic its functionality
PicassoCode is heavily inspired by the [OpenSCAD](https://openscad.org/) program and tries to mimic its functionality
as much as it can while still being an image editor. I was stoked when I tried OpenSCAD for the first time and ended up
challenging myself to start a new project based araound the idea. A friend suggested something that has to do with graphics
and my first though was OpenSCAD, but 2D. The idea quickly grew and the small program became an image editor.
Expand All @@ -47,7 +47,7 @@ and my first though was OpenSCAD, but 2D. The idea quickly grew and the small pr

## License
```sh
drawString("
Render::drawString("
+-----------------------------------+
| ▄▖▘ ▌ |
| ▙▌▌▛▘▀▌▛▘▛▘▛▌▛▘▛▌▛▌█▌ |
Expand Down
8 changes: 8 additions & 0 deletions piccode/render/context.pics
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


Render :: module {
getContext :: () = pic_nat_get_gfx()

drawLine :: (ctx, startx, starty, endx, endy) = pic_nat_draw_line(ctx, startx, starty, endx, endy)
}

11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>

<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<updatePolicy>always</updatePolicy>
</releases>

</repository>
</repositories>

Expand Down Expand Up @@ -66,7 +75,7 @@
<dependency>
<groupId>com.github.Glimmr-Lang</groupId>
<artifactId>PiccodeScript</artifactId>
<version>-SNAPSHOT</version>
<version>main-SNAPSHOT</version>
</dependency>

</dependencies>
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/org/editor/CanvasFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,8 @@ protected void paintComponent(Graphics g) {
g2.setColor(Color.BLACK);
gfx = g2;
if (start && file != null && code != null) {
SwingUtilities.invokeLater(() -> {
AccessFrame.msgs.setText("");
new Thread(() -> compileFrame())
.start();
});
start = false;
compileFrame();
}

drawSelection(g2);
Expand All @@ -131,6 +127,7 @@ protected void paintComponent(Graphics g) {
}

private PiccodeValue compileFrame() {
Context.top.resetContext();
var result = Compiler.compile(file, code);
return result;
}
Expand Down
88 changes: 88 additions & 0 deletions src/main/java/org/editor/nativemods/PiccodeGfxModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.editor.nativemods;

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.HashMap;
import java.util.List;
import org.editor.CanvasFrame;
import org.piccode.rt.Context;
import org.piccode.rt.PiccodeException;
import org.piccode.rt.PiccodeNumber;
import org.piccode.rt.PiccodeObject;
import org.piccode.rt.PiccodeString;
import org.piccode.rt.PiccodeUnit;
import org.piccode.rt.PiccodeValue;
import org.piccode.rt.PiccodeValue.Type;
import org.piccode.rt.modules.NativeFunctionFactory;

/**
*
* @author hexaredecimal
*/
public class PiccodeGfxModule {

public static void addFunctions() {
NativeFunctionFactory.create("get_gfx", List.of(), (args, namedArgs, frame) -> {
var gfx = CanvasFrame.gfx;
var obj = Context.getObject(gfx.hashCode());
if (obj == null) {
Context.allocate(gfx);
return makeObj(gfx);
}
return makeObj(gfx);
}, null);

NativeFunctionFactory.create("draw_line", List.of("ctx", "x1", "y1", "x2", "y2"), (args, namedArgs, frame) -> {
var _ctx = namedArgs.get("ctx");
var _x1 = namedArgs.get("x1");
var _y1 = namedArgs.get("y1");
var _x2 = namedArgs.get("x2");
var _y2 = namedArgs.get("y2");

var ctx = frame == null ?
Context.top
: Context.getContextAt(frame);
var caller = ctx.getTopFrame().caller;

PiccodeValue.verifyType(caller, _ctx, Type.OBJECT);
PiccodeValue.verifyType(caller, _x1, Type.NUMBER);
PiccodeValue.verifyType(caller, _y1, Type.NUMBER);
PiccodeValue.verifyType(caller, _x2, Type.NUMBER);
PiccodeValue.verifyType(caller, _y2, Type.NUMBER);

var obj = (PiccodeObject) _ctx;
var map = obj.obj;
if (!map.containsKey("hash")) {
throw new PiccodeException(caller.file, caller.line, caller.column, "Context is not an object");
}

var _hash = map.get("hash");
PiccodeValue.verifyType(caller, _hash, Type.NUMBER);
var hash = (int) (double) ((PiccodeNumber) _hash).raw();
var _gfx = Context.getObject(hash);
if (_gfx == null) {
throw new PiccodeException(caller.file, caller.line, caller.column, "Context is not allocated");
}
if (!(_gfx instanceof Graphics2D)) {
throw new PiccodeException(caller.file, caller.line, caller.column, "Context is not a correct object. Expected Graphics2D");
}

var gfx = (Graphics2D) _gfx;
var x1 = (int) (double) ((PiccodeNumber) _x1).raw();
var y1 = (int) (double) ((PiccodeNumber) _y1).raw();
var x2 = (int) (double) ((PiccodeNumber) _x2).raw();
var y2 = (int) (double) ((PiccodeNumber) _y2).raw();

gfx.drawLine(x1, y1, x2, y2);
return obj;
}, null);

}

private static PiccodeValue makeObj(Graphics2D obj) {
var _obj = new HashMap<String, PiccodeValue>();
_obj.put("hash", new PiccodeNumber(obj.hashCode()));
_obj.put("class", new PiccodeString(obj.getClass().getName()));
return new PiccodeObject(_obj);
}
}
7 changes: 6 additions & 1 deletion src/main/java/org/piccode/piccode/Piccode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.editor.AccessFrame;
import org.editor.EditorWindow;
import org.editor.nativemods.PiccodeGfxModule;
import org.piccode.backend.Compiler;
import org.piccode.piccodescript.ErrorAsciiKind;

Expand All @@ -15,7 +16,11 @@ public static void main(String[] args) {
Compiler.exitOnError = false;
Compiler.errorKind = ErrorAsciiKind.EMACS_COMP_STYLE;
Compiler.out = AccessFrame.AccessFrameOutputStream.out;

initializeNativeAppModules();
EditorWindow.the();
}

private static void initializeNativeAppModules() {
Compiler.addNativeFunctions(PiccodeGfxModule::addFunctions);
}
}