Skip to content

Commit

Permalink
Code for example star (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored Sep 29, 2024
1 parent 3fa1c7f commit f07ffff
Show file tree
Hide file tree
Showing 42 changed files with 3,274 additions and 10 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": ["eslint:recommended", "prettier"],
"env": {
"es2020": true,
"node": true,
"browser": true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": "latest"
},
"ignorePatterns": ["src/wasm/*"]
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.txt text=auto eol=lf
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on:
push:
branches: [next]
pull_request:
branches: [next]

jobs:
build:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: dtolnay/rust-toolchain@stable
- uses: jetli/[email protected]
with:
version: "latest"
- run: npm install
- run: npm run test
- run: npm run build
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.DS_Store
**/target
src/wasm
dist
**/*-actual.txt
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/wasm/*
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 120,
"bracketSpacing": false
}
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2024-present Bairui SU https://github.com/pearmini

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
```js
import * as Cell from "@charming-art/cell";

function App(ctx) {
let x = 0;
function Star(ctx) {
return {
mode: "double",
width: 520,
height: 520,
setup() {
ctx.size(30, 20);
},
draw() {
ctx.background(" ");
ctx.fill("@", "red", "yellow");
ctx.rect(x, 0, 10, 5);
x += 1;
for (let t = 0; t <= Math.PI * 2; t += Math.PI / 120) {
const x = ctx.cols() / 2 + 12 * Math.cos(t) * Math.cos(t * 3);
const y = ctx.rows() / 2 + 12 * Math.sin(t) * Math.cos(t * 3);
ctx.stroke(Cell.wide("🌟"));
ctx.point(x, y);
}
},
};
}

document.body.append(await Cell.render(App));
document.body.append(await Cell.render(Star));
```
32 changes: 32 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Preview</title>
</head>
<body>
<script src="./dist/cell.umd.min.js" type="text/javascript"></script>
<script>
(async () => {
function Star(ctx) {
return {
mode: "double",
width: 520,
height: 520,
setup() {
for (let t = 0; t <= Math.PI * 2; t += Math.PI / 120) {
const x = ctx.cols() / 2 + 12 * Math.cos(t) * Math.cos(t * 3);
const y = ctx.rows() / 2 + 12 * Math.sin(t) * Math.cos(t * 3);
ctx.stroke(Cell.wide("🌟"));
ctx.point(x, y);
}
},
};
}

document.body.append(await Cell.render(Star));
})();
</script>
</body>
</html>
63 changes: 63 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@charming-art/cell",
"description": "The creative coding language for ASCII Art.",
"version": "0.0.1",
"author": {
"name": "pearmini",
"url": "https://github.com/pearmini"
},
"type": "module",
"license": "ISC",
"main": "dist/es/index.js",
"module": "dist/es/index.js",
"jsdelivr": "dist/cell.umd.min.js",
"unpkg": "dist/cell.umd.min.js",
"exports": {
"umd": "./dist/cell.umd.min.js",
"default": "./src/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/charming-art/cell.git"
},
"files": [
"dist/**/*.js",
"dist/**/*.wasm"
],
"scripts": {
"dev": "npm run build:rust && vite",
"test": "npm run test:rust && npm run test:js && npm run test:lint && npm run test:format",
"test:js": "npm run build:rust && vitest",
"test:rust": "cargo test --manifest-path ./rust/Cargo.toml",
"test:lint": "eslint src test",
"test:format": "prettier --check src test && cargo fmt --manifest-path ./rust/Cargo.toml --check",
"build": "npm run build:rust && npm run build:js",
"build:js": "rm -rf dist && rollup -c",
"build:rust": "rm -rf ./src/wasm && wasm-pack build ./rust --out-dir ../src/wasm --out-name index --target web",
"preview": "npm run build && vite preview",
"prepublishOnly": "npm run build"
},
"sideEffects": false,
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-wasm": "^6.1.3",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"prettier": "^2.8.8",
"rollup": "^3.26.0",
"vite": "^4.3.9",
"vitest": "^0.32.1",
"wasm-pack": "^0.13.0"
},
"dependencies": {
"d3-color": "^3.1.0",
"d3-timer": "^3.0.1"
},
"engines": {
"node": ">=14.18"
},
"publishConfig": {
"access": "public"
}
}
Loading

0 comments on commit f07ffff

Please sign in to comment.