当前位置:网站首页>[tool C] - lattice simulation test 2

[tool C] - lattice simulation test 2

2022-06-23 18:02:19A bowl of bean curd

Preface

The previous article provided a test method for testing dot matrix line drawing function, etc
【C Tools 】------ Lattice simulation test
But the disadvantages are obvious , The dot matrix with high resolution is too large in the way of printing blocks

So this time we use the method of drawing dots , The display is shown in the lower right part of the figure below :
 Please add a picture description

Use vs2019 Development , The program has been uploaded to My code cloud warehouse , Welcome interested partners to improve

Use easyx Graphics library

In fact, there are only two graphic functions required :

  1. Draw a rectangular , That is, the drawing point of the dot matrix , A dot matrix picture points to 3*3, Actual fill 2*2, This leaves a gap between the points
void draw_point(int x,int y)
{
    
	int x1, x2, y1, y2;
	x1 = (x+1) * 3 - 1;
	x2 = (x+1) * 3;
	y1 = (y + 1) * 3 - 1;
	y2 = (y + 1) * 3;
	fillrectangle(x1, y1, x2, y2);
}
  1. Clear the canvas , Nothing to say , Clear the screen
void cleardevice();

Read bin file

Lattice data for display ,

#include <iostream>
#include <fstream>
// Open the file in binary 
std::ifstream infile("./bin.bin",std::ios::binary); 
// Read the data ,256*160 Fixed resolution 
infile.read((char*)rBuf, 256*160/8);     
// File close 
infile.close();                                   

Finally, fill in the read data with dots according to the screen refresh method , Here is an example of a determinant refresh

	void run()
	{
    
		int i, j, k;		
		switch (Data_mode)
		{
    
		case MODE_1:												// Determinant refresh 
			for (i = 0; i < 20; i++)
			{
    
				for (j = 0; j < 256; j++)
				{
    
					for (k = 0; k < 8; k++)
					{
    
						if (byte_mode == 0)
						{
    
							if (reverse == 0)
							{
    
								if (!(show_buf[i * 256 + j] & (0x01 << k)))
								{
    
									draw_point(j, i * 8 + k);
								}
							}
							else if(reverse == 1)
							{
    
								if (show_buf[i * 256 + j] & (0x01 << k))
								{
    
									draw_point(j, i * 8 + k);
								}
							}
						}
						else if (byte_mode == 1)
						{
    
							if (reverse == 0)
							{
    
								if (!(show_buf[i * 256 + j] & (0x80 >> k)))
								{
    
									draw_point(j, i * 8 + k);
								}
							}
							else if(reverse == 1)
							{
    
								if (show_buf[i * 256 + j] & (0x80 >> k))
								{
    
									draw_point(j, i * 8 + k);
								}
							}
						}
					}
				}
			}
			break;
		}
	}

end...

原网站

版权声明
本文为[A bowl of bean curd]所创,转载请带上原文链接,感谢
https://chowdera.com/2022/174/202206231644309070.html

随机推荐