Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for example star #136

Merged
merged 1 commit into from
Sep 29, 2024
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
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/wasm-pack-action@v0.4.0
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
Loading