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

Add GPT-4 generated README #2031

Open
wants to merge 29 commits into
base: kumavis-1kce-demo
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a79901d
doc(cli): fix cli arg
kumavis Nov 13, 2023
0d9976b
1kce - init
kumavis Nov 13, 2023
9d65288
fix(pass-style): allow error with line numbers
kumavis Nov 14, 2023
6df3819
1kce - game mvp
kumavis Nov 14, 2023
f429954
1kce - card rendering
kumavis Nov 14, 2023
7782311
1kce - cards lookin heckin neato
kumavis Nov 15, 2023
1944c2b
1kce - track and display card locations
kumavis Nov 15, 2023
0624f0c
1kce - fix array subscriptions
kumavis Nov 16, 2023
92fbb31
1kce - state refactor with grains
kumavis Nov 17, 2023
91fa447
1kce - calculate scores with grain
kumavis Nov 17, 2023
f2b9663
1kce - library of alexandria
kumavis Nov 17, 2023
53aee8c
1kce - refactor and cleanup
kumavis Nov 17, 2023
5c9925c
1kce - fruitful harvest
kumavis Nov 17, 2023
f45c901
1kce - deja vu
kumavis Nov 17, 2023
7ccc171
1kce - ui improvements
kumavis Nov 17, 2023
7dcfbf5
1kce - fix phase bug when prepending phase
kumavis Nov 17, 2023
c906bfb
refactor(1kce): refactor to use grains (#1863)
kumavis Nov 21, 2023
f4319d6
feat(grain): add grain observable store package
kumavis Nov 21, 2023
f4380b1
refactor(1kce): use grain package
kumavis Nov 21, 2023
baf72ac
1kce: move into own dir and break ui into files
kumavis Nov 21, 2023
bb3dd7e
feat(grain): add support for remote grainMaps
kumavis Nov 21, 2023
2ccdd4c
refactor(1kce): to use remote grainMaps and distribute powers
kumavis Nov 22, 2023
fcab801
feat(1kce): ui improvement
kumavis Nov 22, 2023
fc029b3
1kce/cards: vidi imagination / add mouse interaction
kumavis Nov 22, 2023
8d1add2
1kce: add missing deck method
kumavis Nov 22, 2023
08a0825
1kce - add presentation diagrams
kumavis Nov 22, 2023
a121a1d
fix: updated test code
tgrecojs Dec 4, 2023
f710716
Add GPT-4 generated README
danfinlay Feb 2, 2024
00e3e1b
Further improve readme
danfinlay Feb 2, 2024
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
9 changes: 9 additions & 0 deletions packages/cli/demo/1kce/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# start
```
yarn run 1kce
```

# development
```
yarn run 1kce:dev
```
15 changes: 15 additions & 0 deletions packages/cli/demo/1kce/addCards.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

cd ./demo/1kce/cards

for file in *.js
do
filename=$(basename -- "$file")
extension="${filename##*.}"
filename="${filename%.*}"
yarn endo make "demo/1kce/cards/$file" -n "card-$filename"
if [ $? -ne 0 ]; then
exit 1
fi
done
25 changes: 25 additions & 0 deletions packages/cli/demo/1kce/card-art-prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Please make a canvas animation that responds to mouse position without using any libraries or external resources.
The animation should depict a "deja vu".
Respond with just the makeRenderer function. Match the below format:

function makeRenderer () {
let isInitialized = false
function initialize (rect) {
// init code
}

/**
* @param {CanvasRenderingContext2D} context
* @param {DOMRect} rect
* @param {Object} mousePos
* @param {number} mousePos.x
* @param {number} mousePos.y
**/
return function draw(context, rect, mousePos) {
if (!isInitialized) {
initialize(rect)
isInitialized = true
}
// draw code
};
}
80 changes: 80 additions & 0 deletions packages/cli/demo/1kce/cards/deja-vu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { E, Far } from '@endo/far'

export const make = () => {
return Far('deja vu', {
async play (gameController) {
const cards = await E(gameController).getDeckCards()
await E(gameController).addCardsToDeck(cards)
},
getDetails () {
return {
name: 'deja vu',
description: 'duplicate the cards in the deck, in the same order.\n\n-25 points',
pointValue: -25,
}
},
getRendererCode () {
return `${makeRenderer}`
},
})
}

function makeRenderer() {
let isInitialized = false;
const elements = [];
const speed = 0.1;

function initialize(rect) {
// Populate the elements array with initial elements
for (let i = 0; i < 50; i++) {
elements.push({
x: Math.random() * rect.width,
y: Math.random() * rect.height,
size: Math.random() * 20 + 5,
color: `hsla(${Math.random() * 360}, 100%, 50%, 0.7)`,
});
}
}

return function draw(context, rect, mousePos) {
if (!isInitialized) {
initialize(rect);
isInitialized = true;
}

// Clear the canvas
context.clearRect(0, 0, rect.width, rect.height);

// // Draw lines between all elements and the mouse position, creating a web-like effect
// elements.forEach(element => {
// context.beginPath();
// context.moveTo(mousePos.x, mousePos.y);
// context.lineTo(element.x, element.y);
// context.strokeStyle = element.color;
// context.stroke();
// });

// Draw each element as a circle
elements.forEach(element => {
context.beginPath();
context.arc(element.x, element.y, element.size, 0, Math.PI * 2);
context.fillStyle = element.color;
context.fill();
});

// Update elements to create the "deja vu" effect
elements.forEach((element, index) => {
const margin = 2 * element.size;
const maxWidth = rect.width + (margin * 2);
const maxHeight = rect.height + (margin * 2);
// Change position and size in a loop to create a repeating effect
if (index % 2 === 0) { // Every other element
element.x = (element.x + margin + speed + maxWidth) % (maxWidth) - margin;
element.y = (element.y + margin + speed + maxHeight) % (maxHeight) - margin;
} else {
element.x = (element.x + margin - speed + maxWidth) % (maxWidth) - margin;
element.y = (element.y + margin - speed + maxHeight) % (maxHeight) - margin;
}
});
};
}
92 changes: 92 additions & 0 deletions packages/cli/demo/1kce/cards/firmament.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Far } from '@endo/far'

export const make = () => {
return Far('the firmament', {
async play (game) {

},
getDetails () {
return {
name: 'the firmament',
description: 'you have discovered the firmament, the mysteries of the universe unfold in a boundless dance.\n\n+100 points',
pointValue: 100,
}
},
getRendererCode () {
return `${makeRenderer}`
},
})
}

function makeRenderer () {
const gridh = 50;
const gridw = 30;
const maxDistance = 140;
const power = 4;
const friction = 0.9;
const ratio = 0.25;
const maxD2 = maxDistance * maxDistance;
const a = power / maxD2;
const pointsArray = [];

init();

function init() {
for (let y = 0; y < gridh; ++y) {
pointsArray[y] = [];
for (let x = 0; x < gridw; ++x) {
pointsArray[y][x] = new Point((x * 10) - 10, (y * 10) - 10);
}
}
}
function draw(context, rect, mousePos) {
context.clearRect(0, 0, 600, 400);
context.beginPath();
context.fillStyle = '#EFEFEF';
context.rect(0, 0, 600, 400);
context.closePath();
context.fill();
for (let y = 0; y < gridh; ++y) {
for (let x = 0; x < gridw; ++x) {
const p = pointsArray[y][x];
p.run(mousePos);
const radius = 1.5;
const px = p.x;
const py = p.y;
context.beginPath();
context.fillStyle = '#000000';
context.arc(px, py, radius, 0, Math.PI * 2, true);
context.closePath();
context.fill();
}
}
// stats.update();
}
function Point(x, y) {
this.startx = x;
this.starty = y;
this.speedx = 0;
this.speedy = 0;
this.x = x;
this.y = y;
this.run = function (mousePos) {
const distanceX = mousePos.x - this.x;
const distanceY = mousePos.y - this.y;
const signX = (distanceX > 0) ? -1 : 1;
const signY = (distanceY > 0) ? -1 : 1;
const distance2 = distanceX * distanceX + distanceY * distanceY;
let forceX = 0;
let forceY = 0;
if (distance2 <= maxD2) {
const force = (-a * distance2 + power);
forceX = (distanceX * distanceX) / distance2 * signX * force;
forceY = (distanceY * distanceY) / distance2 * signY * force;
}
this.speedx = this.speedx * friction + (this.startx - this.x) * ratio + forceX;
this.speedy = this.speedy * friction + (this.starty - this.y) * ratio + forceY;
this.x += this.speedx;
this.y += this.speedy;
}
}
return draw;
}
71 changes: 71 additions & 0 deletions packages/cli/demo/1kce/cards/fruitful-harvest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { E, Far } from '@endo/far'

export const make = () => {
return Far('fruitful harvest', {
async play (game) {
await E(game).prependTurnPhase('draw')
},
getDetails () {
return {
name: 'fruitful harvest',
description: 'each player now draws an additional card at the start of each turn.\n\n+25 points',
pointValue: 25,
}
},
getRendererCode () {
return `${makeRenderer}`
},
})
}

function makeRenderer() {
let fruits

let isInitialized = false
function initialize (rect) {
// Initial setup
fruits = Array.from({ length: 5 }, () => ({
x: Math.random() * rect.width,
y: Math.random() * rect.height,
size: 10 + Math.random() * 10, // Size between 10 and 20
}));
}

// Draw a simple fruit
function drawFruit(context, fruit) {
context.beginPath();
context.arc(fruit.x, fruit.y, fruit.size, 0, 2 * Math.PI);
context.fillStyle = 'orange'; // color of the fruit
context.fill();
context.stroke();
}

return function draw(context, rect, mousePos) {
if (!isInitialized) {
initialize(rect)
isInitialized = true
}

// Clear the canvas
context.clearRect(0, 0, rect.width, rect.height);

// Draw each fruit
fruits.forEach(fruit => drawFruit(context, fruit));

// Optional: React to mouse position
const isInFrame = mousePos.x >= 0 && mousePos.x <= rect.width && mousePos.y >= 0 && mousePos.y <= rect.height
if (!isInFrame) {
return
}
// Change something based on mousePos.x and mousePos.y
// Example: Increase the size of the nearest fruit
const nearestFruit = fruits.reduce((nearest, fruit) => {
const distance = Math.sqrt((fruit.x - mousePos.x) ** 2 + (fruit.y - mousePos.y) ** 2);
return distance < nearest.distance ? { fruit, distance } : nearest;
}, { fruit: null, distance: Infinity });

if (nearestFruit.fruit && nearestFruit.distance < nearestFruit.fruit.size) {
nearestFruit.fruit.size += 0.1; // Grow the nearest fruit slightly
}
};
}
75 changes: 75 additions & 0 deletions packages/cli/demo/1kce/cards/library-of-alexandria.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { E, Far } from '@endo/far'

export const make = () => {
return Far('library of alexandria', {
async play (controller) {
await E(controller).setScoreFn(Far('scoreFn container', {
scoreFn: async ({ cards }) => {
let score = 0
for (const card of cards) {
const { name } = await E(card).getDetails()
score += name.length * 10
}
return score
},
}))
},
getDetails () {
return {
name: 'library of alexandria',
description: 'scores are now based on the length of the name the cards.\n\nwhen they burned the library of Alexandria the crowd cheered in horrible joy. They understood that there was something older than wisdom, and it was fire, and something truer than words, and it was ashes.',
pointValue: -100,
}
},
getRendererCode () {
return `${makeRenderer}`
},
})
}

function makeRenderer() {
const particles = [];

// Function to initialize particles
function initParticles(rect) {
for (let i = 0; i < 100; i++) {
particles.push({
x: Math.random() * rect.width,
y: rect.height,
size: Math.random() * 3 + 1,
speed: Math.random() * 5 + 1,
opacity: Math.random(),
color: `rgba(255, ${Math.floor(Math.random() * 100)}, 0, ${Math.random()})`,
});
}
}

let isInitialized = false

return function draw(context, rect, mousePos) {
if (!isInitialized) {
initParticles(rect)
isInitialized = true
}

// Clear the canvas
context.clearRect(0, 0, rect.width, rect.height);

// Update and draw particles
particles.forEach((particle, index) => {
particle.y -= particle.speed;
context.globalAlpha = particle.opacity;
context.fillStyle = particle.color;
context.beginPath();
context.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
context.fill();

// Reset particle if it goes above the canvas
if (particle.y < 0) {
particle.y = rect.height;
}
});

context.globalAlpha = 1;
};
}
Loading
Loading