Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
eordano committed Feb 23, 2017
1 parent f9e0f36 commit 03bffbc
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/function/components/color-spear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {ColorUtils} from "../../utils/ColorUtils";
import {TimeTickedFunction} from "../TimeTickedFunction";

export class Func extends TimeTickedFunction {
constructor(config, leds) {
super(config, leds);
this.time = 0;
}

drawFrame(draw, done) {
this.time += this.config.speed;
const punta = this.time;
const newColors = new Array(this.numberOfLeds)

for (let i = 0; i < this.numberOfLeds; i++) {
newColors[i] = ColorUtils.HSVtoHex(
0,
0,
0
)
}
const colorTime = this.config.colorTime * 1000
for (let i = 0; i < this.config.spearLength; i++) {
newColors[(punta + i) % this.numberOfLeds] = ColorUtils.HSVtoHex(
((this.time + i * this.config.colorVariety) % colorTime) / colorTime,
1,
this.config.brillo,
)
}
draw(newColors);
}

static presets() {
return {
fastMarks: {speed: 3, sameColorLeds: 5},
}
}

// Override and extend config Schema
static configSchema() {
let config = super.configSchema();
config.speed = {type: Number, min: 5, max: 20, default: 4};
config.brillo = {type: Number, min: 0, max: 1, step: 0.01, default: 0.3};
config.colorTime = {type: Number, min: 0, max: 10, step: 0.1, default: 1};
config.spearLength = {type: Number, min: 30, max: 540, step: 1, default: 180};
config.colorVariety = {type: Number, min: 1, max: 10, step: 1, default: 2};
return config;
}
}
40 changes: 40 additions & 0 deletions src/function/components/radial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {TimeTickedFunction} from "../TimeTickedFunction";
import {ColorUtils} from "../../utils/ColorUtils";

export class Func extends TimeTickedFunction{
drawFrame(draw, done) {
const colors = new Array(this.numberOfLeds)
const elapsed = (this.timeInMs) / 1000;

this.extraTime = (this.extraTime || 0) + Math.random()*10;

const centerX = this.config.moveX
? Math.sin(this.extraTime / 1000) * 60 - 30
: this.config.centerX

for (let i = 0; i < this.numberOfLeds; i++) {
const dx = this.position.x[i] - 30 - centerX;
const dy = this.position.y[i] - 34.6 + this.config.centerY;

const distance = Math.sqrt(dx*dx + dy*dy) * 255 / (300*this.config.escala);

const v = Math.max(0, Math.sin(distance + elapsed * this.config.velocidad));
colors[i] = ColorUtils.HSVtoHex((distance/5+ this.extraTime/1000) % 1, 1, Math.pow(v, this.config.power))
}
draw(colors)
}

// Override and extend config Schema
static configSchema(){
let res = super.configSchema();
res.escala = {type: Number, min: 0.1, max: 100, step: 0.1, default: 1}
res.velocidad = {type: Number, min: -50, max: 50, step: 0.1, default: -5}
res.centerY = {type: Number, min: 0, max: 40, step: 0.1, default: 0}
res.centerX = {type: Number, min: -30, max: 30, step: 0.1, default: 0}
res.power = {type: Number, min: 0, max: 10, step: 0.1, default: 1}
res.randomEscala = {type: Boolean, default: false }
res.randomSpeed = {type: Boolean, default: false }
res.moveX = {type: Boolean, default: true }
return res;
}
}
41 changes: 41 additions & 0 deletions src/function/components/rainbow-horizontal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {ColorUtils} from "../../utils/ColorUtils";
import {TimeTickedFunction} from "../TimeTickedFunction";

export class Func extends TimeTickedFunction {
constructor(config, leds) {
super(config, leds);

this.time = 0;
}

drawFrame(draw, done) {
this.time += this.config.speed;
const elapsed = this.time;
const newColors = new Array(this.numberOfLeds)
const sameColorLeds = this.config.sameColorLeds * 10

for (let i = 0; i < this.numberOfLeds; i++) {
newColors[i] = ColorUtils.HSVtoHex(
(this.position.x[i] - elapsed % sameColorLeds + sameColorLeds) / sameColorLeds,
1,
this.config.brillo
)
}
draw(newColors);
}

static presets() {
return {
fastMarks: {speed: 3, sameColorLeds: 5},
}
}

// Override and extend config Schema
static configSchema() {
let config = super.configSchema();
config.speed = {type: Number, min: 1, max: 20, default: 1};
config.sameColorLeds = {type: Number, min: 1, max: 100, default: 30};
config.brillo = {type: Number, min: 0, max: 1, step: 0.01, default: 0.3};
return config;
}
}
46 changes: 46 additions & 0 deletions src/function/components/spear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {ColorUtils} from "../../utils/ColorUtils";
import {TimeTickedFunction} from "../TimeTickedFunction";

export class Func extends TimeTickedFunction {
constructor(config, leds) {
super(config, leds);
this.time = 0;
}

drawFrame(draw, done) {
this.time += this.config.speed;
const punta = this.time;
const newColors = new Array(this.numberOfLeds)

for (let i = 0; i < this.numberOfLeds; i++) {
newColors[i] = ColorUtils.HSVtoHex(
0,
0,
0
)
}
for (let i = 0; i < this.config.spearLength; i++) {
newColors[(punta + i) % this.numberOfLeds] = ColorUtils.HSVtoHex(
0,
0,
this.config.brillo,
)
}
draw(newColors);
}

static presets() {
return {
fastMarks: {speed: 3, sameColorLeds: 5},
}
}

// Override and extend config Schema
static configSchema() {
let config = super.configSchema();
config.speed = {type: Number, min: 5, max: 20, default: 4};
config.brillo = {type: Number, min: 0, max: 1, step: 0.01, default: 0.3};
config.spearLength = {type: Number, min: 30, max: 540, step: 1, default: 180};
return config;
}
}
12 changes: 12 additions & 0 deletions src/function/radial2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const _ = require('lodash')

import {programsByShape} from "./Transformations";

const Spear = require("./components/color-spear").Func;

// las formas que se pueden usar están definidas en Transformation
const mapping = {
"reloj": [Spear, { spearLength: 100}],
}

export const Func = programsByShape(mapping)
12 changes: 12 additions & 0 deletions src/function/rainbow-horizontal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const _ = require('lodash')

import {programsByShape} from "./Transformations";

const Rainbow = require("./components/rainbow-horizontal").Func;

// las formas que se pueden usar están definidas en Transformation
const mapping = {
"Warro": [Rainbow, { spearLength: 100}],
}

export const Func = programsByShape(mapping)
12 changes: 12 additions & 0 deletions src/function/rainbow-hourglass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const _ = require('lodash')

import {programsByShape} from "./Transformations";

const Spear = require("./components/color-spear").Func;

// las formas que se pueden usar están definidas en Transformation
const mapping = {
"reloj": [Spear, { spearLength: 100}],
}

export const Func = programsByShape(mapping)

0 comments on commit 03bffbc

Please sign in to comment.