mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-04-30 09:45:35 +00:00
Basic graph rendering system
This commit is contained in:
parent
746a00a56b
commit
65a26b8e31
@ -1 +1 @@
|
|||||||
Subproject commit ceb8c02fb06b279c333e28cda731dd7f35bb0684
|
Subproject commit ffd93e5a95755b5e990d64058f171cd2f849f088
|
@ -105,6 +105,7 @@ ADDroplet::ADDroplet(DaisyPatch* m_patch,
|
|||||||
Droplet(m_patch,
|
Droplet(m_patch,
|
||||||
m_state) {
|
m_state) {
|
||||||
sample_rate = m_sample_rate;
|
sample_rate = m_sample_rate;
|
||||||
|
SetAnimationRate(20);
|
||||||
ad[0].Init(Patch(),
|
ad[0].Init(Patch(),
|
||||||
sample_rate,
|
sample_rate,
|
||||||
&m_state);
|
&m_state);
|
||||||
@ -113,6 +114,9 @@ ADDroplet::ADDroplet(DaisyPatch* m_patch,
|
|||||||
sample_rate,
|
sample_rate,
|
||||||
&m_state);
|
&m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
title_graph = new Graph(GetScreenMax()-GetScreenMin(),
|
||||||
|
GetTitleHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
ADDroplet::~ADDroplet() {}
|
ADDroplet::~ADDroplet() {}
|
||||||
@ -186,7 +190,16 @@ void ADDroplet::Draw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(NeedUpdate()) {
|
||||||
|
title_graph->Update();
|
||||||
|
}
|
||||||
|
title_graph->SetPixelPercentage(ad[0].GetSignal());
|
||||||
|
|
||||||
|
//title_graph->SetPixelPercentage(0.99f);
|
||||||
|
title_graph->Draw(Patch(), 0, 0);
|
||||||
|
|
||||||
DrawName("AD");
|
DrawName("AD");
|
||||||
|
AnimationInc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADDroplet::UpdateStateCallback() {
|
void ADDroplet::UpdateStateCallback() {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "droplet.h"
|
#include "droplet.h"
|
||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
|
#include "../graphics/graph.h"
|
||||||
|
|
||||||
using namespace daisy;
|
using namespace daisy;
|
||||||
using namespace daisysp;
|
using namespace daisysp;
|
||||||
@ -47,6 +48,7 @@ class ADDroplet: public Droplet {
|
|||||||
private:
|
private:
|
||||||
AD ad[2];
|
AD ad[2];
|
||||||
float sample_rate;
|
float sample_rate;
|
||||||
|
Graph* title_graph;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*
|
/*
|
||||||
|
66
src/graphics/graph.cpp
Normal file
66
src/graphics/graph.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "graph.h"
|
||||||
|
|
||||||
|
Graph::Graph(int m_width, int m_height) {
|
||||||
|
width = m_width;
|
||||||
|
height = m_height;
|
||||||
|
graph = new bool*[width];
|
||||||
|
for (int w = 0; w < width; w++) {
|
||||||
|
graph[w] = new bool[height];
|
||||||
|
for (int h = 0; h < height; h++) {
|
||||||
|
graph[w][h] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
active = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graph::~Graph() {
|
||||||
|
for (int w = 0; w < width; w++) {
|
||||||
|
delete[] graph[w];
|
||||||
|
}
|
||||||
|
delete[] graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Graph::GetNextActive() {
|
||||||
|
if (active == width - 1) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return active+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::Update() {
|
||||||
|
active = GetNextActive();
|
||||||
|
ClearColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::ClearColumn() {
|
||||||
|
for (int h = 0; h < height; h++) {
|
||||||
|
graph[active][h] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::SetPixel(int pos) {
|
||||||
|
SetPixel(pos, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::SetPixel(int pos, bool on) {
|
||||||
|
graph[active][pos] = on;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::SetPixelPercentage(double percentage) {
|
||||||
|
SetPixelPercentage(percentage, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::SetPixelPercentage(double percentage, bool on) {
|
||||||
|
SetPixel((int)(percentage*height), on);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::Draw(DaisyPatch* patch, int x, int y) {
|
||||||
|
for (int w = 0; w < width; w++) {
|
||||||
|
for (int h = 0; h < height; h++) {
|
||||||
|
patch->display.DrawPixel(x+w, y+h,
|
||||||
|
graph[GetShiftArray(w, active, width)]
|
||||||
|
[GetShiftArray(height-h, height-1, height)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
src/graphics/graph.h
Normal file
29
src/graphics/graph.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef DROPLETS_GRAPHICS_GRAPH_H
|
||||||
|
#define DROPLETS_GRAPHICS_GRAPH_H
|
||||||
|
|
||||||
|
#include "daisy_patch.h"
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
|
using namespace daisy;
|
||||||
|
|
||||||
|
class Graph {
|
||||||
|
private:
|
||||||
|
int width, height, active;
|
||||||
|
bool** graph;
|
||||||
|
int GetNextActive();
|
||||||
|
public:
|
||||||
|
Graph(int m_width,
|
||||||
|
int m_height);
|
||||||
|
~Graph();
|
||||||
|
void Update();
|
||||||
|
void ClearColumn();
|
||||||
|
void SetPixel(int pos);
|
||||||
|
void SetPixel(int pos, bool on);
|
||||||
|
void SetPixelPercentage(double percentage);
|
||||||
|
void SetPixelPercentage(double percentage, bool on);
|
||||||
|
void Draw(DaisyPatch* patch, int x, int y);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DROPLETS_GRAPHICS_GRAPH_H
|
@ -116,12 +116,6 @@ void Sprite::AdjustYShift(int y) {
|
|||||||
y_shift += y;
|
y_shift += y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sprite::GetShiftArray(int pos,
|
|
||||||
int shift,
|
|
||||||
int array_size) {
|
|
||||||
return (array_size + ((pos + shift) % array_size)) % array_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Sprite::GetShiftArrayX(int pos) {
|
int Sprite::GetShiftArrayX(int pos) {
|
||||||
return GetShiftArray(pos, x_shift, width);
|
return GetShiftArray(pos, x_shift, width);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef CASCADE_GRAPHICS_SPRITE_H_
|
#ifndef DROPLETS_GRAPHICS_SPRITE_H_
|
||||||
#define CASCADE_GRAPHICS_SPRITE_H_
|
#define DROPLETS_GRAPHICS_SPRITE_H_
|
||||||
|
|
||||||
#include "daisy_patch.h"
|
#include "daisy_patch.h"
|
||||||
|
#include "../util.h"
|
||||||
|
|
||||||
using namespace daisy;
|
using namespace daisy;
|
||||||
|
|
||||||
@ -14,18 +15,6 @@ class Sprite {
|
|||||||
int x_shift = 0;
|
int x_shift = 0;
|
||||||
int y_shift = 0;
|
int y_shift = 0;
|
||||||
|
|
||||||
/*
|
|
||||||
* Converts a graphic pixel location to a new one based on
|
|
||||||
* a given shift.
|
|
||||||
*
|
|
||||||
* @param pos pixel position
|
|
||||||
* @param shift shift amount
|
|
||||||
* @param array_size max length of dimension
|
|
||||||
* return new pixel position
|
|
||||||
*/
|
|
||||||
int GetShiftArray(int pos,
|
|
||||||
int shift,
|
|
||||||
int array_size);
|
|
||||||
/*
|
/*
|
||||||
* Converts a x axis position based upon the sprites shift.
|
* Converts a x axis position based upon the sprites shift.
|
||||||
*
|
*
|
||||||
@ -163,4 +152,4 @@ class Sprite {
|
|||||||
void AdjustYShift(int y);
|
void AdjustYShift(int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CASCADE_GRAPHICS_SPRITE_H_
|
#endif // DROPLETS_GRAPHICS_SPRITE_H_
|
||||||
|
@ -179,3 +179,8 @@ void DrawFourDividedRectangles(DaisyPatch* patch,
|
|||||||
rect_three_max);
|
rect_three_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GetShiftArray(int pos,
|
||||||
|
int shift,
|
||||||
|
int array_size) {
|
||||||
|
return (array_size + ((pos + shift) % array_size)) % array_size;
|
||||||
|
}
|
||||||
|
13
src/util.h
13
src/util.h
@ -197,4 +197,17 @@ void DrawFourDividedRectangles(DaisyPatch* patch,
|
|||||||
int rect_four_min,
|
int rect_four_min,
|
||||||
int rect_four_max);
|
int rect_four_max);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Converts a graphic pixel location to a new one based on
|
||||||
|
* a given shift.
|
||||||
|
*
|
||||||
|
* @param pos pixel position
|
||||||
|
* @param shift shift amount
|
||||||
|
* @param array_size max length of dimension
|
||||||
|
* return new pixel position
|
||||||
|
*/
|
||||||
|
int GetShiftArray(int pos,
|
||||||
|
int shift,
|
||||||
|
int array_size);
|
||||||
|
|
||||||
#endif // CASCADE_UTIL_H_
|
#endif // CASCADE_UTIL_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user