Skip to content

Commit

Permalink
1kce/grains refactor wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis committed Nov 20, 2023
1 parent 7dcfbf5 commit 5623e74
Show file tree
Hide file tree
Showing 11 changed files with 540 additions and 316 deletions.
167 changes: 109 additions & 58 deletions packages/cli/demo/1kce.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/cli/demo/cards/deja-vu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Far } from "@endo/far"
import { Far } from '@endo/far'

export const make = (powers) => {
return Far('deja vu', {
Expand All @@ -21,7 +21,7 @@ export const make = (powers) => {

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

function initialize(rect) {
Expand All @@ -31,7 +31,7 @@ function makeRenderer() {
x: Math.random() * rect.width,
y: Math.random() * rect.height,
size: Math.random() * 20 + 5,
color: `hsla(${Math.random() * 360}, 100%, 50%, 0.7)`
color: `hsla(${Math.random() * 360}, 100%, 50%, 0.7)`,
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/demo/cards/firmament.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Far } from "@endo/far"
import { Far } from '@endo/far'

export const make = (powers) => {
return Far('the firmament', {
Expand Down Expand Up @@ -42,7 +42,7 @@ function makeRenderer () {
function draw(context, rect, mousePos) {
context.clearRect(0, 0, 600, 400);
context.beginPath();
context.fillStyle = "#EFEFEF";
context.fillStyle = '#EFEFEF';
context.rect(0, 0, 600, 400);
context.closePath();
context.fill();
Expand All @@ -54,7 +54,7 @@ function makeRenderer () {
const px = p.x;
const py = p.y;
context.beginPath();
context.fillStyle = "#000000";
context.fillStyle = '#000000';
context.arc(px, py, radius, 0, Math.PI * 2, true);
context.closePath();
context.fill();
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/demo/cards/fruitful-harvest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Far } from "@endo/far"
import { Far } from '@endo/far'

export const make = (powers) => {
return Far('fruitful harvest', {
Expand Down Expand Up @@ -27,7 +27,7 @@ function makeRenderer() {
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
size: 10 + Math.random() * 10, // Size between 10 and 20
}));
}

Expand Down Expand Up @@ -60,7 +60,7 @@ function makeRenderer() {
// Change something based on mousePos.x and mousePos.y
// Example: Increase the size of the nearest fruit
const nearestFruit = fruits.reduce((nearest, fruit) => {
let distance = Math.sqrt((fruit.x - mousePos.x) ** 2 + (fruit.y - mousePos.y) ** 2);
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 });

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/demo/cards/library-of-alexandria.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { E, Far } from "@endo/far"
import { E, Far } from '@endo/far'

export const make = (powers) => {
return Far('library of alexandria', {
Expand All @@ -11,7 +11,7 @@ export const make = (powers) => {
score += name.length * 10
}
return score
}
},
}))
},
getDetails () {
Expand Down
78 changes: 39 additions & 39 deletions packages/cli/demo/cards/lost-and-afraid.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Far } from "@endo/far"
import { Far } from '@endo/far'

export const make = (powers) => {
return Far('lost and afraid', {
Expand Down Expand Up @@ -28,19 +28,19 @@ function makeRenderer () {
// c.height = box.height;
// }

var light = {
const light = {
x: 160,
y: 200
y: 200,
}

var colors = ["#f5c156", "#e6616b", "#5cd3ad"];
const colors = ['#f5c156', '#e6616b', '#5cd3ad'];

function drawLight (ctx) {
ctx.beginPath();
ctx.arc(light.x, light.y, 10000, 0, 2 * Math.PI);
var gradient = ctx.createRadialGradient(light.x, light.y, 0, light.x, light.y, 1000);
gradient.addColorStop(0, "#3b4654");
gradient.addColorStop(0.4, "#2c343f");
const gradient = ctx.createRadialGradient(light.x, light.y, 0, light.x, light.y, 1000);
gradient.addColorStop(0, '#3b4654');
gradient.addColorStop(0.4, '#2c343f');
ctx.fillStyle = gradient;
ctx.fill();
}
Expand All @@ -54,40 +54,40 @@ function makeRenderer () {
this.color = colors[Math.floor((Math.random() * colors.length))];

this.getDots = function() {
var full = (Math.PI * 2) / 4;
const full = (Math.PI * 2) / 4;

var p1 = {
const p1 = {
x: this.x + this.half_size * Math.sin(this.r),
y: this.y + this.half_size * Math.cos(this.r)
y: this.y + this.half_size * Math.cos(this.r),
};
var p2 = {
const p2 = {
x: this.x + this.half_size * Math.sin(this.r + full),
y: this.y + this.half_size * Math.cos(this.r + full)
y: this.y + this.half_size * Math.cos(this.r + full),
};
var p3 = {
const p3 = {
x: this.x + this.half_size * Math.sin(this.r + full * 2),
y: this.y + this.half_size * Math.cos(this.r + full * 2)
y: this.y + this.half_size * Math.cos(this.r + full * 2),
};
var p4 = {
const p4 = {
x: this.x + this.half_size * Math.sin(this.r + full * 3),
y: this.y + this.half_size * Math.cos(this.r + full * 3)
y: this.y + this.half_size * Math.cos(this.r + full * 3),
};

return {
p1: p1,
p2: p2,
p3: p3,
p4: p4
p1,
p2,
p3,
p4,
};
}
this.rotate = function() {
var speed = (60 - this.half_size) / 200;
const speed = (60 - this.half_size) / 200;
this.r += speed * 0.002;
this.x += speed;
this.y += speed;
}
this.draw = function(ctx) {
var dots = this.getDots();
const dots = this.getDots();
ctx.beginPath();
ctx.moveTo(dots.p1.x, dots.p1.y);
ctx.lineTo(dots.p2.x, dots.p2.y);
Expand All @@ -104,37 +104,37 @@ function makeRenderer () {
}
}
this.drawShadow = function(ctx) {
var dots = this.getDots();
var angles = [];
var points = [];
const dots = this.getDots();
const angles = [];
const points = [];

for (const dot in dots) {
var angle = Math.atan2(light.y - dots[dot].y, light.x - dots[dot].x);
var endX = dots[dot].x + this.shadow_length * Math.sin(-angle - Math.PI / 2);
var endY = dots[dot].y + this.shadow_length * Math.cos(-angle - Math.PI / 2);
const angle = Math.atan2(light.y - dots[dot].y, light.x - dots[dot].x);
const endX = dots[dot].x + this.shadow_length * Math.sin(-angle - Math.PI / 2);
const endY = dots[dot].y + this.shadow_length * Math.cos(-angle - Math.PI / 2);
angles.push(angle);
points.push({
endX: endX,
endY: endY,
endX,
endY,
startX: dots[dot].x,
startY: dots[dot].y
startY: dots[dot].y,
});
};

for (var i = points.length - 1; i >= 0; i--) {
var n = i == 3 ? 0 : i + 1;
for (let i = points.length - 1; i >= 0; i--) {
const n = i == 3 ? 0 : i + 1;
ctx.beginPath();
ctx.moveTo(points[i].startX, points[i].startY);
ctx.lineTo(points[n].startX, points[n].startY);
ctx.lineTo(points[n].endX, points[n].endY);
ctx.lineTo(points[i].endX, points[i].endY);
ctx.fillStyle = "#2c343f";
ctx.fillStyle = '#2c343f';
ctx.fill();
};
}
}

var boxes = [];
const boxes = [];

function draw(ctx, c, mousePos) {
makeBoxes(c)
Expand Down Expand Up @@ -168,11 +168,11 @@ function makeRenderer () {
}

function collisionDetection(b){
for (var i = boxes.length - 1; i >= 0; i--) {
for (let i = boxes.length - 1; i >= 0; i--) {
if(i != b){
var dx = (boxes[b].x + boxes[b].half_size) - (boxes[i].x + boxes[i].half_size);
var dy = (boxes[b].y + boxes[b].half_size) - (boxes[i].y + boxes[i].half_size);
var d = Math.sqrt(dx * dx + dy * dy);
const dx = (boxes[b].x + boxes[b].half_size) - (boxes[i].x + boxes[i].half_size);
const dy = (boxes[b].y + boxes[b].half_size) - (boxes[i].y + boxes[i].half_size);
const d = Math.sqrt(dx * dx + dy * dy);
if (d < boxes[b].half_size + boxes[i].half_size) {
boxes[b].half_size = boxes[b].half_size > 1 ? boxes[b].half_size-=1 : 1;
boxes[i].half_size = boxes[i].half_size > 1 ? boxes[i].half_size-=1 : 1;
Expand Down
Loading

0 comments on commit 5623e74

Please sign in to comment.