mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-04-30 01:35:34 +00:00
Sprite based graphics
This commit is contained in:
parent
b992bfbdaa
commit
5056158266
3
Makefile
3
Makefile
@ -5,7 +5,8 @@ CPP_SOURCES = src/main.cpp \
|
|||||||
src/menu.cpp \
|
src/menu.cpp \
|
||||||
src/droplets/droplet.cpp \
|
src/droplets/droplet.cpp \
|
||||||
src/droplets/noise_droplet.cpp \
|
src/droplets/noise_droplet.cpp \
|
||||||
src/droplets/vco_droplet.cpp
|
src/droplets/vco_droplet.cpp \
|
||||||
|
src/graphics/sprite.cpp
|
||||||
|
|
||||||
LIBDAISY_DIR = ./lib/libDaisy
|
LIBDAISY_DIR = ./lib/libDaisy
|
||||||
DAISYSP_DIR = ./lib/daisySP
|
DAISYSP_DIR = ./lib/daisySP
|
||||||
|
@ -29,6 +29,9 @@ void Droplet::AnimationInc() {
|
|||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
//animation_count = animation_count % animation_rate;
|
||||||
|
WriteCenteredString(*patch, (screen_min + screen_max) / 2, 40,
|
||||||
|
Font_6x8, std::to_string(animation_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Droplet::SetAnimationRate(int rate) {
|
void Droplet::SetAnimationRate(int rate) {
|
||||||
|
@ -46,29 +46,15 @@ void VCODroplet::Process(float** in, float** out, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VCODroplet::Draw() {
|
void VCODroplet::Draw() {
|
||||||
int sine_width = 20;
|
wave->SetBlank();
|
||||||
bool sine_wave[sine_width][Droplet::kTitleHeight];
|
|
||||||
|
|
||||||
// Set blank pattern
|
|
||||||
for (int h = 0; h < kTitleHeight; h++) {
|
|
||||||
for (int w = screen_min; w < screen_max; w++) {
|
|
||||||
sine_wave[w][h] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < sine_width; i++) {
|
for (int i = 0; i < sine_width; i++) {
|
||||||
int pixel = (int) round(std::sin(2*pi*((double)(i + animation_count%sine_width)/sine_width)) * (kTitleHeight/2) + kTitleHeight/2);
|
int pixel = (int) round(std::sin(2*pi*((double)(i + animation_count%sine_width)/sine_width)) * (kTitleHeight/2) + kTitleHeight/2);
|
||||||
sine_wave[i][pixel] = true;
|
wave->SetPixel(i, pixel, true);
|
||||||
}
|
|
||||||
|
|
||||||
for (int h = 0; h < kTitleHeight; h++) {
|
|
||||||
for (int w = screen_min; w < screen_max; w++) {
|
|
||||||
patch->display.DrawPixel(w, h, sine_wave[w%sine_width][h%kTitleHeight]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteString(*patch, 0, 54, Font_6x8,
|
WriteString(*patch, 0, 54, Font_6x8,
|
||||||
WaveToString(wavectrl.Process()));
|
WaveToString(wavectrl.Process()));
|
||||||
|
wave->DrawTile(*patch, screen_min, 0, screen_max, kTitleHeight);
|
||||||
DrawName(patch, "VCO");
|
DrawName(patch, "VCO");
|
||||||
AnimationInc();
|
AnimationInc();
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "droplet.h"
|
#include "droplet.h"
|
||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
|
#include "../graphics/sprite.h"
|
||||||
|
|
||||||
using namespace daisy;
|
using namespace daisy;
|
||||||
using namespace daisysp;
|
using namespace daisysp;
|
||||||
@ -20,6 +21,8 @@ private:
|
|||||||
Parameter freqctrl, wavectrl, ampctrl, finectrl;
|
Parameter freqctrl, wavectrl, ampctrl, finectrl;
|
||||||
std::string WaveToString(uint8_t);
|
std::string WaveToString(uint8_t);
|
||||||
const double pi = std::acos(-1);
|
const double pi = std::acos(-1);
|
||||||
|
int sine_width = 20;
|
||||||
|
Sprite* wave = new Sprite(sine_width, kTitleHeight);
|
||||||
public:
|
public:
|
||||||
VCODroplet(DaisyPatch*, DropletState, float);
|
VCODroplet(DaisyPatch*, DropletState, float);
|
||||||
void Control();
|
void Control();
|
||||||
|
64
src/graphics/sprite.cpp
Normal file
64
src/graphics/sprite.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include "sprite.h"
|
||||||
|
|
||||||
|
Sprite::Sprite(int m_width, int m_height) {
|
||||||
|
width = m_width;
|
||||||
|
height = m_height;
|
||||||
|
sprite = new bool*[width];
|
||||||
|
for (int w = 0; w < width; w++) {
|
||||||
|
sprite[w] = new bool[height];
|
||||||
|
for (int h = 0; h < height; h++) {
|
||||||
|
sprite[w][h] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sprite::SetPixel(int x, int y, bool solid) {
|
||||||
|
sprite[x][y] = solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Sprite::GetHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Sprite::GetWidth() {
|
||||||
|
return width;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sprite::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, sprite[w][h]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sprite::DrawTile(DaisyPatch patch,
|
||||||
|
int x1,
|
||||||
|
int y1,
|
||||||
|
int x2,
|
||||||
|
int y2) {
|
||||||
|
int x_min = std::min(x1, x2);
|
||||||
|
int x_max = std::max(x1, x2);
|
||||||
|
int y_min = std::min(y1, y2);
|
||||||
|
int y_max = std::max(y1, y2);
|
||||||
|
for (int w = x_min; w < x_max; w++) {
|
||||||
|
for (int h = y_min; h < y_max; h++) {
|
||||||
|
patch.display.DrawPixel(w, h, sprite[(w-x_min) % width]
|
||||||
|
[(h-y_min) % height]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool** Sprite::GetSprite() {
|
||||||
|
return sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sprite::SetBlank() {
|
||||||
|
for (int w = 0; w < width; w++) {
|
||||||
|
for (int h = 0; h < height; h++) {
|
||||||
|
sprite[w][h] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
src/graphics/sprite.h
Normal file
25
src/graphics/sprite.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef CASCADE_GRAPHICS_SPRITE_H_
|
||||||
|
#define CASCADE_GRAPHICS_SPRITE_H_
|
||||||
|
|
||||||
|
#include "daisy_patch.h"
|
||||||
|
|
||||||
|
using namespace daisy;
|
||||||
|
|
||||||
|
class Sprite {
|
||||||
|
private:
|
||||||
|
int width, height;
|
||||||
|
bool** sprite;
|
||||||
|
public:
|
||||||
|
Sprite(int, int);
|
||||||
|
void SetPixel(int, int, bool);
|
||||||
|
int GetHeight();
|
||||||
|
int GetWidth();
|
||||||
|
bool** GetSprite();
|
||||||
|
void Draw(DaisyPatch, int, int);
|
||||||
|
void DrawTile(DaisyPatch, int, int, int, int);
|
||||||
|
void SetBlank();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CASCADE_GRAPHICS_SPRITE_H_
|
Loading…
x
Reference in New Issue
Block a user