Vibrating rectangles: Difference between revisions

Line 294:
const vibRects = new VibRects();
vibRects.start();
}
</lang>
 
=={{header|Objeck}}==
Uses SLD2 libraries and 80's neon colors.
<lang objeck>use Game.SDL2;
use Game.Framework;
 
class Vibrating {
@framework : GameFramework;
@rec_offset : Int;
@rec_colors : Color[];
@rec_color_index : Int;
 
function : Main(args : String[]) ~ Nil {
vibrating := Vibrating->New();
vibrating->Run();
}
 
New() {
@framework := GameFramework->New(GameConsts->SCREEN_WIDTH, GameConsts->SCREEN_HEIGHT, "Vibrating Rectangles");
@framework->SetClearColor(Color->New(0, 0, 0));
@rec_colors := Color->New[5];
@rec_colors[0] := Color->New(255, 240, 1);
@rec_colors[1] := Color->New(253, 25, 153);
@rec_colors[2] := Color->New(153, 252, 32);
@rec_colors[3] := Color->New(0, 230, 254);
@rec_colors[4] := Color->New(161, 14, 236);
}
method : Run() ~ Nil {
if(@framework->IsOk()) {
e := @framework->GetEvent();
frame_count := 0;
quit := false;
while(<>quit) {
@framework->FrameStart();
# process input
while(e->Poll() <> 0) {
if(e->GetType() = EventType->SDL_QUIT) {
quit := true;
};
};
 
Render(frame_count);
 
@framework->FrameEnd();
 
frame_count += 1;
if(frame_count >= @framework->GetFps()) {
frame_count := 0;
};
};
}
else {
"--- Error Initializing Environment ---"->ErrorLine();
return;
};
 
leaving {
@framework->Quit();
};
}
 
method : Render(frame_count : Int) ~ Nil {
# rectangle offsets
if(frame_count % GameConsts->REC_REFRESH = 0) {
@rec_offset += 1;
if(@rec_offset >= GameConsts->REC_MAX) {
@rec_offset := 0;
@rec_color_index += 1;
};
};
 
# rectangle colors
first_color := @rec_colors[@rec_color_index];
second_color : Color;
if(@rec_color_index + 1 < @rec_colors->Size()) {
second_color := @rec_colors[@rec_color_index + 1];
}
else {
second_color := @rec_colors[0];
@rec_color_index := 0;
};
 
@framework->Clear();
 
for(i := 1; i < GameConsts->REC_MAX; i += 1;) {
if(i < @rec_offset) {
DrawRectangle(i, first_color);
}
else {
DrawRectangle(i, second_color);
};
};
 
@framework->Show();
}
 
method : DrawRectangle(step : Int, color : Color) ~ Nil {
x := step * GameConsts->REC_DIST; w := GameConsts->SCREEN_WIDTH - x * 2;
y := step * GameConsts->REC_DIST; h := GameConsts->SCREEN_HEIGHT - y * 2;
 
renderer := @framework->GetRenderer();
renderer->SetDrawColor(color->GetR(), color->GetG(), color->GetB(), 0);
renderer->DrawRect(Rect->New(x, y, w, h));
renderer->DrawRect(Rect->New(x + 1, y + 1, w - 2, h - 2));
renderer->DrawRect(Rect->New(x + 2, y + 2, w - 4, h - 4));
}
}
 
consts GameConsts {
SCREEN_WIDTH := 640,
SCREEN_HEIGHT := 480,
REC_DIST := 12,
REC_MAX := 20,
REC_REFRESH := 15
}
</lang>
760

edits