ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
ClockProject.h
Go to the documentation of this file.
1#pragma once
2
3#include <TimeLib.h>
4
5#include "Animation.h"
6#include "KeyFrameTrack.h"
7#include "EasyEaseAnimator.h"
8#include "../Objects/Background.h"
9#include "../Render/Scene.h"
10#include "../Signals/FunctionGenerator.h"
11
12#include "../Materials/Animated/RainbowNoise.h"
13#include "../Materials/Animated/RainbowNoise2.h"
14#include "../Materials/Animated/RainbowSpiral.h"
15#include "../Materials/CombineMaterial.h"
16#include "../Materials/Clock.h"
17
18#include "../Materials/MaterialMask.h"
19#include "../Shapes/Circle.h"
20#include "../Shapes/Rectangle.h"
21
22#include "../Sensors/APDS9960.h"
23#include "../Filter/RunningAverageFilter.h"
24
26 return Teensy3Clock.get();
27}
28
29class ClockAnimation : public Animation<1> {
30private:
31 Background background;
32
35 Clock clock = Clock(false);
36 float brightness = 255.0f;
37
38 //Materials
51
52 Rectangle sadRect = Rectangle(Vector2D(48.0f, 48.0f), Vector2D(140.0f, 100.0f), 0.0f);
53
55
57
65
66
68
70
71 }
72
76
81
82public:
84 setSyncProvider(getTeensy3Time);
85
86 scene.AddObject(background.GetObject());
87
89
91
93
95
96 background.GetObject()->SetMaterial(&material);
97 }
98
99 void Initialize() override {
100 apds.Initialize(100);
101 }
102
104 return 0;
105 };
106
107 uint8_t GetBrightness(){
108 Serial.println(brightness);
109
110 return uint8_t(brightness);
111 };
112
113 void FadeIn(float stepRatio) override {}
114 void FadeOut(float stepRatio) override {}
115
117 return background.GetObject();
118 }
119
120 void Update(float ratio) override {
121 //float xOffset = fGenMatXMove.Update();
122 //float yOffset = fGenMatYMove.Update();
123 //float scale = fGenScale.Update();
124 //float rotate = fGenMatRot.Update();
125 float fade = fGenMatFade.Update();
126
127 uint16_t apdsBright = apds.GetBrightness();
128
129 brightness = rAF.Filter(Mathematics::Map(Mathematics::Constrain(apdsBright, uint16_t(0), uint16_t(25)), uint16_t(0), uint16_t(25), uint16_t(1), uint16_t(255)));
130
131 clock.SetDate(day(), month(), year() - 2000, weekday());
132 clock.SetTime(hour(), minute(), second());
133
134 clock.Update();
135 clock.SetPosition(Vector2D(-69.75f, 18.75f));
136 clock.SetSize(Vector2D(240.0f, 160.0f));
138
139 material.SetOpacity(1, fade);
140
141 rainbowNoise.Update(ratio);
142 rainbowNoise2.Update(ratio);
143 rainbowSpiral.Update(ratio);
144
145 }
146};
time_t getTeensy3Time()
Declares the EasyEaseAnimator template class for advanced animation easing.
Declares the KeyFrameTrack template class for managing keyframe-based animations.
A class for managing the Adafruit APDS9960 sensor.
Definition APDS9960.h:27
static uint16_t GetBrightness()
Retrieves the current brightness value.
Definition APDS9960.cpp:78
static bool Initialize(uint8_t threshold)
Initializes the APDS9960 sensor.
Definition APDS9960.cpp:14
FunctionGenerator fGenMatHue
Rectangle sadRect
SimpleMaterial greenMaterial
FunctionGenerator fGenMatYMove
SimpleMaterial pinkMaterial
void Initialize() override
SimpleMaterial redMaterial
RunningAverageFilter< 25 > rAF
RainbowSpiral rainbowSpiral
SimpleMaterial blackMaterial
SimpleMaterial blueMaterial
MaterialMask sadMaterial
SimpleMaterial yellowMaterial
void ChangeInterpolationMethods()
FunctionGenerator fGenMatPos
FunctionGenerator fGenScale
Background background
void SetMaterialLayers()
CombineMaterial< 4 > material
RainbowNoise2 rainbowNoise2
FunctionGenerator fGenRotation
FunctionGenerator fGenMatFade
SimpleMaterial orangeMaterial
void FadeIn(float stepRatio) override
void FadeOut(float stepRatio) override
RainbowNoise rainbowNoise
FunctionGenerator fGenMatXMove
SimpleMaterial purpleMaterial
void Update(float ratio) override
void LinkEasyEase()
FunctionGenerator fGenMatRot
uint8_t GetBrightness()
uint8_t GetAccentBrightness()
Object3D * GetObject()
SimpleMaterial whiteMaterial
Renders a real-time clock and date as a material.
Definition Clock.h:26
void SetRotation(float rotation)
Sets the rotation of the clock in the rendered scene.
Definition Clock.cpp:36
void SetSize(Vector2D size)
Sets the size of the clock's rendered area.
Definition Clock.cpp:28
void SetMaterial(Material *material)
Sets the material to be used for rendering the clock.
Definition Clock.cpp:11
void SetTime(uint8_t hour, uint8_t minute, uint8_t second)
Sets the current time for the clock.
Definition Clock.cpp:15
void SetDate(uint8_t day, uint8_t month, uint8_t year, uint8_t wDay)
Sets the current date for the clock.
Definition Clock.cpp:21
void Update()
Updates the clock's time and date.
Definition Clock.cpp:40
void SetPosition(Vector2D position)
Sets the position of the clock in the rendered scene.
Definition Clock.cpp:32
Combines multiple materials with specified blending methods and opacities.
void SetOpacity(uint8_t index, float opacity)
Sets the opacity for a specific material.
void AddMaterial(Method method, Material *material, float opacity)
Adds a new material to the combination.
A class to generate various waveform functions with customizable parameters.
@ Sine
Sine waveform.
@ Triangle
Triangle waveform.
float Update()
Updates and calculates the next value of the waveform.
Combines two materials using a shape as a mask.
@ Replace
Replaces the base color.
Definition Material.h:44
@ Base
The base material color.
Definition Material.h:34
static T Map(T value, T inLow, T inMax, T outMin, T outMax)
Maps a value from one range to another.
static T Constrain(T value, T minimum, T maximum)
Constrains a value between minimum and maximum.
Represents a 3D object with geometry, material, and transformation data.
Definition Object3D.h:28
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
A dynamic material that creates a rainbow effect using simplex noise with black-to-color transitions.
void Update(float ratio)
Updates the material animation based on the time ratio.
A dynamic material that creates a rainbow effect using simplex noise.
void Update(float ratio)
Updates the material animation based on the time ratio.
A dynamic material creating a colorful rainbow spiral animation.
void Update(float ratio)
Updates the material animation based on the time ratio.
Represents a rectangle in 2D space.
Definition Rectangle.h:21
Smooths data values using a weighted running average.
float Filter(float value)
Filters the input value using the running average.
A material that applies a single, solid RGB color to surfaces.
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27