mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-04-30 09:45:35 +00:00
Sprite line drawing and wave drawing outline
This commit is contained in:
parent
8106e4ae70
commit
62497cade0
3
Makefile
3
Makefile
@ -6,7 +6,8 @@ CPP_SOURCES = src/main.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
|
src/graphics/sprite.cpp \
|
||||||
|
src/graphics/wave.cpp
|
||||||
|
|
||||||
LIBDAISY_DIR = ./lib/libDaisy
|
LIBDAISY_DIR = ./lib/libDaisy
|
||||||
DAISYSP_DIR = ./lib/daisySP
|
DAISYSP_DIR = ./lib/daisySP
|
||||||
|
@ -16,12 +16,6 @@ VCODroplet::VCODroplet(DaisyPatch* m_patch,
|
|||||||
num_waves, Parameter::LINEAR);
|
num_waves, Parameter::LINEAR);
|
||||||
ampctrl.Init(Patch()->controls[Patch()->CTRL_4], 0.0,
|
ampctrl.Init(Patch()->controls[Patch()->CTRL_4], 0.0,
|
||||||
0.5f, Parameter::LINEAR);
|
0.5f, Parameter::LINEAR);
|
||||||
|
|
||||||
wave->SetBlank();
|
|
||||||
for (int i = 0; i < sine_width; i++) {
|
|
||||||
int pixel = (int) round(std::sin(2*pi*((double)(i%sine_width)/sine_width)) * (GetTitleHeight()/2) + GetTitleHeight()/2);
|
|
||||||
wave->SetPixel(i, pixel, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VCODroplet::~VCODroplet() {
|
VCODroplet::~VCODroplet() {
|
||||||
@ -59,7 +53,7 @@ void VCODroplet::Draw() {
|
|||||||
WaveToString(wavectrl.Process()));
|
WaveToString(wavectrl.Process()));
|
||||||
wave->DrawTile(*Patch(), GetScreenMin(), 0, GetScreenMax(), GetTitleHeight());
|
wave->DrawTile(*Patch(), GetScreenMin(), 0, GetScreenMax(), GetTitleHeight());
|
||||||
if(NeedUpdate()) {
|
if(NeedUpdate()) {
|
||||||
wave->AdjustXShift(1);
|
//wave->AdjustXShift(1);
|
||||||
}
|
}
|
||||||
DrawName("VCO");
|
DrawName("VCO");
|
||||||
AnimationInc();
|
AnimationInc();
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "droplet.h"
|
#include "droplet.h"
|
||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
#include "../graphics/sprite.h"
|
#include "../graphics/wave.h"
|
||||||
|
|
||||||
using namespace daisy;
|
using namespace daisy;
|
||||||
using namespace daisysp;
|
using namespace daisysp;
|
||||||
@ -22,7 +22,7 @@ private:
|
|||||||
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;
|
int sine_width = 20;
|
||||||
Sprite* wave = new Sprite(sine_width, GetTitleHeight());
|
Wave* wave = new Wave(WaveShape::kTriangle, sine_width, GetTitleHeight());
|
||||||
public:
|
public:
|
||||||
VCODroplet(DaisyPatch*, DropletState, float);
|
VCODroplet(DaisyPatch*, DropletState, float);
|
||||||
~VCODroplet();
|
~VCODroplet();
|
||||||
|
@ -19,10 +19,37 @@ Sprite::~Sprite() {
|
|||||||
delete[] sprite;
|
delete[] sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::SetPixel(int x, int y, bool solid) {
|
void Sprite::AddPixel(int x, int y, bool solid) {
|
||||||
sprite[x][y] = solid;
|
sprite[x][y] = solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sprite::AddLine(int x1,
|
||||||
|
int y1,
|
||||||
|
int x2,
|
||||||
|
int y2,
|
||||||
|
bool solid) {
|
||||||
|
uint8_t deltaX = abs(x2 - x1);
|
||||||
|
uint8_t deltaY = abs(y2 - y1);
|
||||||
|
int8_t signX = ((x1 < x2) ? 1 : -1);
|
||||||
|
int8_t signY = ((y1 < y2) ? 1 : -1);
|
||||||
|
int16_t error = deltaX - deltaY;
|
||||||
|
int16_t error2;
|
||||||
|
|
||||||
|
AddPixel(x2, y2, solid);
|
||||||
|
while((x1 != x2) || (y1 != y2)) {
|
||||||
|
AddPixel(x1, y1, solid);
|
||||||
|
error2 = error * 2;
|
||||||
|
if(error2 > -deltaY) {
|
||||||
|
error -= deltaY;
|
||||||
|
x1 += signX;
|
||||||
|
}
|
||||||
|
if(error2 < deltaX) {
|
||||||
|
error += deltaX;
|
||||||
|
y1 += signY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Sprite::GetHeight() {
|
int Sprite::GetHeight() {
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@ class Sprite {
|
|||||||
public:
|
public:
|
||||||
Sprite(int, int);
|
Sprite(int, int);
|
||||||
~Sprite();
|
~Sprite();
|
||||||
void SetPixel(int, int, bool);
|
void AddPixel(int, int, bool);
|
||||||
|
void AddLine(int, int, int, int, bool);
|
||||||
int GetHeight();
|
int GetHeight();
|
||||||
int GetWidth();
|
int GetWidth();
|
||||||
bool** GetSprite();
|
bool** GetSprite();
|
||||||
|
24
src/graphics/wave.cpp
Normal file
24
src/graphics/wave.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "wave.h"
|
||||||
|
|
||||||
|
Wave::Wave(WaveShape m_wave, int width, int height) : Sprite(width, height) {
|
||||||
|
wave = m_wave;
|
||||||
|
DrawShape();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wave::DrawShape() {
|
||||||
|
SetBlank();
|
||||||
|
int mid = GetWidth()/2;
|
||||||
|
switch(wave) {
|
||||||
|
case WaveShape::kTriangle:
|
||||||
|
AddLine(0, GetHeight()+1, mid, 0, true);
|
||||||
|
AddLine(mid, 0, GetWidth()+1, GetHeight(), true);
|
||||||
|
return;
|
||||||
|
case WaveShape::kSine:
|
||||||
|
default:
|
||||||
|
for (int i = 0; i < GetWidth(); i++) {
|
||||||
|
int pixel = (int) round(std::sin(2*pi*((double)(i%GetWidth())/GetWidth())) * (GetHeight()/2) + GetHeight()/2);
|
||||||
|
AddPixel(i, pixel, true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
19
src/graphics/wave.h
Normal file
19
src/graphics/wave.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef CASCADE_GRAPHICS_WAVE_H_
|
||||||
|
#define CASCADE_GRAPHICS_WAVE_H_
|
||||||
|
|
||||||
|
#include "sprite.h"
|
||||||
|
|
||||||
|
enum class WaveShape {kSine, kTriangle, kSaw, kSquare, kRamp};
|
||||||
|
|
||||||
|
class Wave: public Sprite {
|
||||||
|
private:
|
||||||
|
WaveShape wave;
|
||||||
|
const double pi = std::acos(-1);
|
||||||
|
void DrawShape();
|
||||||
|
public:
|
||||||
|
Wave(WaveShape, int, int);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user