xref: /haiku/src/add-ons/screen_savers/ifs/IFS.h (revision 98b054fe0276efc07e64d79db52574d34758a875)
1 /*
2  * Copyright (c) 1997 by Massimino Pascal <Pascal.Massimon@ens.fr>
3  * Copyright 2006-2014, Haiku, Inc. All rights reserved.
4  *
5  * Distributed under the terms of the MIT License.
6  *
7  * Authors:
8  *		Stephan Aßmus, superstippi@gmx.de
9  *		Massimino Pascal, Pascal.Massimon@ens.fr
10  *		John Scipione, jscipione@gmail.com
11  */
12 #ifndef IFS_H
13 #define IFS_H
14 
15 
16 #include <Screen.h>
17 #include <Point.h>
18 #include <Rect.h>
19 #include <Region.h>
20 #include <View.h>
21 
22 
23 #define FIX 12
24 #define UNIT   ( 1<<FIX )
25 #define MAX_SIMILITUDE  6
26 
27 // settings for a PC 120Mhz...
28 #define MAX_DEPTH_2  10
29 #define MAX_DEPTH_3  6
30 #define MAX_DEPTH_4  4
31 #define MAX_DEPTH_5  3
32 
33 
34 struct buffer_info {
35 	void*			bits;
36 	uint32			bytesPerRow;
37 	uint32			bits_per_pixel;
38 	color_space		format;
39 	clipping_rect	bounds;
40 };
41 
42 struct Point {
43 	int32		x;
44 	int32		y;
45 };
46 
47 typedef struct Similitude {
48 	float		c_x;
49 	float		c_y;
50 	float		r;
51 	float		r2;
52 	float		A;
53 	float		A2;
54 	int32		Ct;
55 	int32		St;
56 	int32		Ct2;
57 	int32		St2;
58 	int32		Cx;
59 	int32		Cy;
60 	int32		R;
61 	int32		R2;
62 } SIMILITUDE;
63 
64 typedef struct Fractal {
65 	int			SimilitudeCount;
66 	SIMILITUDE	Components[5 * MAX_SIMILITUDE];
67 	int			Depth;
68 	int			Col;
69 	int			Count;
70 	int			Speed;
71 	int			Width;
72 	int			Height;
73 	int			Lx;
74 	int			Ly;
75 	float		r_mean;
76 	float		dr_mean;
77 	float		dr2_mean;
78 	int			CurrentPoint;
79 	int			MaxPoint;
80 	Point*		buffer1;
81 	Point*		buffer2;
82 	BBitmap*	bitmap;
83 	BBitmap*	markBitmap;
84 } FRACTAL;
85 
86 
87 class IFS {
88 public:
89 								IFS(BRect bounds);
90 	virtual						~IFS();
91 
92 			void				Draw(BView* view, const buffer_info* info,
93 									 int32 frames);
94 
95 			void				SetAdditive(bool additive);
96 			void				SetSpeed(int32 speed);
97 
98 private:
99 			void				_DrawFractal(BView* view,
100 									const buffer_info* info);
101 			void				_Trace(FRACTAL* F, int32 xo, int32 yo);
102 			void				_RandomSimilitudes(FRACTAL* f, SIMILITUDE* cur,
103 									int i) const;
104 			void				_FreeBuffers(FRACTAL* f);
105 			void				_FreeIFS(FRACTAL* f);
106 
107 			FRACTAL*			fRoot;
108 			FRACTAL*			fCurrentFractal;
109 			Point*				fPointBuffer;
110 			int32				fCurrentPoint;
111 
112 			bool				fAdditive;
113 			uint8				fCurrentMarkValue;
114 };
115 
116 
117 #endif	// IFS_H
118