begin myBitmap := TBitmap.Create; myBitmap.SetSize(800, 600); M1 := Now; for Count := 0 to 60 do begin for x := 0 to 800 do for y := 0 to 600 do begin if Random > 0.5 then myBitmap.Canvas.DrawPixel(x, y, TColorToFPColor(clWhite)) else myBitmap.Canvas.DrawPixel(x, y, TColorToFPColor(clBlack)); end; PaintBox1.Canvas.Draw(0, 0, myBitmap); //myBitmap.Free; end; M2 := Now; fps := 60 / (MilliSecondsBetween(M1, M2) / 1000); labCap := FloatToStr(fps); Label1.Caption := labCap;end;
#include "raylib.h"int main(void){ const int screenWidth = 1600; const int screenHeight = 900; InitWindow(screenWidth, screenHeight, "WhiteNoise window"); while (!WindowShouldClose()) { int x, y, rnd; BeginDrawing(); for (x = 0; x < screenWidth; x++) { for (y = 0; y < screenHeight; y++) { rnd = GetRandomValue(0, 1); if(rnd==1) DrawPixel(x, y, RAYWHITE); if(rnd==0) DrawPixel(x, y, BLACK); } } DrawFPS(0, 0); EndDrawing(); } CloseWindow(); return 0;}
Dim As Integer screenWidth, screenHeightscreenWidth = 1600screenHeight = 900Screenres screenWidth, screenHeight, 32Dim As Integer x, y, randDo If Inkey = Chr$(27) Then Exit Do For x = 0 To screenWidth For y = 0 To screenHeight rand = Rnd If rand = 1 Then Pset (x, y), Rgb(255,255,255) Else Pset (x, y), Rgb(0,0,0) End If Next y Next xLoopEnd
Dim As Integer screenWidth, screenHeightscreenWidth = 1600screenHeight = 900ScreenRes screenWidth, screenHeight, 32Dim As Integer x, y, rand, countDim image As Any Ptr = ImageCreate( screenWidth, screenHeight, RGB(0, 0, 0) )For count = 1 To 600 For x = 0 To screenWidth For y = 0 To screenHeight rand = Rnd If rand = 1 Then PSet image, (x, y), RGB(255, 255, 255) Else PSet image, (x, y), RGB(0, 0, 0) End If Next y Next x Put (0, 0), image, PSet Next countEnd
void setup() { size(1600, 900); frameRate(60); background(0); }void draw() { if (keyCode == ESC) exit(); int rnd; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { rnd = (int)random(2); if(rnd==1) set(x, y, color(255,255,255)); else set(x, y, color(0,0,0)); } } String txt = String.format("Window 1 %6.2fps", frameRate); windowTitle(txt); println(frameRate); text(frameRate,0,0);}
void setup() { size(1600, 900); frameRate(60); background(0);}void draw() { if (keyCode == ESC) exit(); loadPixels(); for (int i = 0; i < pixels.length; i++) { float rand = random(255); color c = color(rand); pixels[i] = c; } updatePixels(); println(frameRate); text(frameRate, 0, 0);}
Посмотрел, что может FreeBasic. Старый Демон плохого не посоветует же? FreeBasic: 600 циклов за ~45 секунд. ~13 к/с. FreeBasic медленный.
Привет. Вот приспичило мне обрабатывать некими алгоритмами массив точек(пикселей) области экрана. Чтобы была анимация неких генерируемых процессов в реальном(хотелось бы быстро чтобы наглядно) времени. Встал вопрос выбора подходящего инструмента - языка программирования. Подходящего для задачи и подходящего такому программисту, как я(в коде ниже возможна куча ошибок).Для теста скорости отрисовки конкретным языком(библиотекой) решил просто рисовать массив точек черного или белого цвета. Как белый шум на экране аналогового тв, когда нет сигнала. И посмотреть сколько кадров в секунду вообще возможно рисовать. Ведь я еще даже не буду обрабатывать массив точек по нужному мне алгоритму, просто рандом(белый ИЛИ черный).Попробовал Free Pascal(Lazarus). Если в лоб, то очень медленно. С разрешением поля 800х600 всего 3.5 к/с(кадров в секунду).
#include<GL/glut.h>void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 0.0); glBegin(GL_POINTS); glVertex2f(10.0, 10.0); glVertex2f(150.0, 80.0); glVertex2f(100.0, 20.0); glVertex2f(200.0, 100.0); glEnd(); glFlush();}void myinit() { glClearColor(1.0, 1.0, 1.0, 1.0); glColor3f(1.0, 0.0, 0.0); glPointSize(5.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 499.0, 0.0, 499.0);}void main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(0, 0); glutCreateWindow("Points"); glutDisplayFunc(display); myinit(); glutMainLoop();}
Не знаю, чем вы тут занимаетесь, но, мне кажется стоит посмотреть в сторону готовых графических библиотек.
Еще напишу, что хочется писать алгоритм обработки массива(вместо rand), а не длиннющие портянки кода инициализации и работы с OpenGl напрямую.
По хорошему не должно быть НИКАКИХ попиксельных записей/чтений в видеопамять. Вся индивидуальная работа с отдельными пискселями должна вестись с буфером в обычной памяти, а после всех циклов нужно выгружать этот буфер в видеопамять одной командой.
А, что массивы и циклы в опенГЛ запрещены?А каким способом желающий собирается объявлять цвет всех пикселей в двух словах?
А, я хочу без опенгл блендер, кинь мне ссылок сделать это на фрибейсике.