mirror of
https://github.com/stasenso/rp_pico_display_engine.git
synced 2026-06-26 21:32:41 +03:00
Besier curve added
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 17)
|
|||||||
|
|
||||||
pico_sdk_init()
|
pico_sdk_init()
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} main.c Thread.c)
|
add_executable(${PROJECT_NAME} main.c Thread.c DrawBezier.c)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#include "DrawBezier.h"
|
||||||
|
// Установка пикселя в буфере (с проверкой границ)
|
||||||
|
void set_pixel(int x, int y, uint16_t color) {
|
||||||
|
if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT) {
|
||||||
|
frame_buffer[y * WIDTH + x] = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Функция для вычисления базисного полинома Бернштейна
|
||||||
|
float bernstein(int i, int n, float t) {
|
||||||
|
// Вычисление биномиального коэффициента C(n, i)
|
||||||
|
float binomial = 1.0f;
|
||||||
|
for (int j = 0; j < i; j++) {
|
||||||
|
binomial *= (n - j) / (float)(j + 1);
|
||||||
|
}
|
||||||
|
return binomial * powf(t, i) * powf(1.0f - t, n - i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Рисование кривой Безье
|
||||||
|
void draw_bezier(const int *points_x, const int *points_y, size_t num_points, uint16_t color) {
|
||||||
|
if (num_points < 2) {
|
||||||
|
return; // Кривая требует минимум 2 точки
|
||||||
|
}
|
||||||
|
|
||||||
|
const int steps = 1000; // Количество шагов для построения кривой
|
||||||
|
|
||||||
|
for (int step = 0; step <= steps; step++) {
|
||||||
|
float t = step / (float)steps;
|
||||||
|
float x = 0.0f;
|
||||||
|
float y = 0.0f;
|
||||||
|
|
||||||
|
// Вычисление координат точки на кривой
|
||||||
|
for (size_t i = 0; i < num_points; i++) {
|
||||||
|
float b = bernstein(i, num_points - 1, t);
|
||||||
|
x += b * points_x[i];
|
||||||
|
y += b * points_y[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Установка пикселя на экране
|
||||||
|
set_pixel((int)(x + 0.5f), (int)(y + 0.5f), color);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "Thread.h"
|
||||||
|
|
||||||
|
void set_pixel(int x, int y, uint16_t color);
|
||||||
|
float bernstein(int i, int n, float t);
|
||||||
|
void draw_bezier(const int *points_x, const int *points_y, size_t num_points, uint16_t color);
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
#include "pico/multicore.h"
|
#include "pico/multicore.h"
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
#include "DrawBezier.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
uint16_t red = 0;
|
uint16_t red = 0;
|
||||||
@@ -9,90 +10,21 @@ int main() {
|
|||||||
uint16_t blue = 0;
|
uint16_t blue = 0;
|
||||||
uint16_t summcolor=0;
|
uint16_t summcolor=0;
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
|
int points_x[] = {0,50, 150, 250, 300,320};
|
||||||
|
int points_y[] = {0,200, 50, 50, 200,240};
|
||||||
|
size_t num_points = sizeof(points_x) / sizeof(points_x[0]);
|
||||||
|
uint16_t color = reverse(0b0000011111100000);
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
multicore_launch_core1(coreEntry); //Запускаю в ядре 1 процесс вывода на экран
|
multicore_launch_core1(coreEntry); //Запускаю в ядре 1 процесс вывода на экран
|
||||||
|
|
||||||
while (red<32) //Red ++
|
|
||||||
{
|
|
||||||
|
|
||||||
data = multicore_fifo_pop_blocking();
|
data = multicore_fifo_pop_blocking();
|
||||||
summcolor=summcolor & 0b0000011111111111 | red << 11;
|
|
||||||
fillBufer(frame_buffer,reverse(summcolor));//;
|
fillBufer(frame_buffer,reverse(0x4A69));//
|
||||||
|
draw_bezier(points_x, points_y, num_points, color);
|
||||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
||||||
red+=1;
|
red+=1;
|
||||||
sleep_ms(40);
|
sleep_ms(40);
|
||||||
}
|
|
||||||
|
|
||||||
sleep_ms (1000);
|
|
||||||
while (green<64) //Red+Green
|
|
||||||
{
|
|
||||||
data = multicore_fifo_pop_blocking();
|
|
||||||
summcolor=summcolor & 0b1111100000011111 | green << 5;
|
|
||||||
fillBufer(frame_buffer,reverse(summcolor)); //
|
|
||||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
|
||||||
green+=1;
|
|
||||||
sleep_ms(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep_ms (1000);
|
|
||||||
red=32;
|
|
||||||
while (red!=0) //Green++
|
|
||||||
{
|
|
||||||
red-=1;
|
|
||||||
data = multicore_fifo_pop_blocking();
|
|
||||||
summcolor=(summcolor & 0b0000011111111111) | (red << 11);
|
|
||||||
fillBufer(frame_buffer,reverse(summcolor));//;
|
|
||||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
|
||||||
sleep_ms(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep_ms (1000);
|
|
||||||
while (blue<32) //Green+blue
|
|
||||||
{
|
|
||||||
data = multicore_fifo_pop_blocking();
|
|
||||||
summcolor=summcolor & 0b1111111111100000 | blue;
|
|
||||||
fillBufer(frame_buffer,reverse(summcolor)); //
|
|
||||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
|
||||||
blue+=1;
|
|
||||||
sleep_ms(40);
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep_ms (1000);
|
|
||||||
green=64;
|
|
||||||
while (green!=0) //blue++
|
|
||||||
{
|
|
||||||
green-=1;
|
|
||||||
data = multicore_fifo_pop_blocking();
|
|
||||||
summcolor=summcolor & 0b1111100000011111 | green << 5;
|
|
||||||
fillBufer(frame_buffer,reverse(summcolor));//;
|
|
||||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
|
||||||
sleep_ms(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep_ms (1000);
|
|
||||||
red=0;
|
|
||||||
while (red<32) //Red+Blue
|
|
||||||
{
|
|
||||||
|
|
||||||
data = multicore_fifo_pop_blocking();
|
|
||||||
summcolor=summcolor & 0b0000011111111111 | red << 11;
|
|
||||||
fillBufer(frame_buffer,reverse(summcolor));//;
|
|
||||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
|
||||||
red+=1;
|
|
||||||
sleep_ms(40);
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep_ms (1000);
|
|
||||||
green=0;
|
|
||||||
while (green<64) //Red+Green
|
|
||||||
{
|
|
||||||
data = multicore_fifo_pop_blocking();
|
|
||||||
summcolor=summcolor & 0b1111100000011111 | green << 5;
|
|
||||||
fillBufer(frame_buffer,reverse(summcolor)); //
|
|
||||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
|
||||||
green+=1;
|
|
||||||
sleep_ms(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
tight_loop_contents();
|
tight_loop_contents();
|
||||||
|
|||||||
Reference in New Issue
Block a user