File: simple.bs

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (100 lines) | stat: -rw-r--r-- 1,980 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use ui;
use graphics;
use core:io;
use core:geometry;
use lang:bs:macro;

class DrawWin extends Frame {
	init() {
		init("Window", Size(200, 200));
		painter(SimpleDraw());
		create();
	}

	Bool onKey(Bool down, Key key, Modifiers mod) {
		print("Keycode: " # down # ", " # key # ", " # mod);
		close();
		false;
	}
}

class SimpleDraw extends Painter {
	Path star;
	LinearGradient bgBrush;
	SolidBrush starColor;
	SolidBrush solid;
	SolidBrush textColor;
	Moment started;
	Text text;
	Size textSize;
	Bitmap image;

	init() {
		init() {
			bgBrush(red, green, Point(0, 0), Point(200, 200));
			// bgBrush([GradientStop(0, red), GradientStop(0.5, green), GradientStop(1, blue)], 45 deg);
			starColor(yellow);
			solid(green);
			textColor(blue);
			text = Text("Hello!", defaultFont);
			image(graphics:loadImage(resUrl / "ui_alpha.png"));
		}
		bgColor = red;

		textSize = text.size();
		text.layoutBorder(textSize);

		Int edges = 5;
		Int stops = edges * 2;
		for (Int i = 0; i < stops; i++) {
			Angle a = 360 deg / stops.float;
			a *= i.float;

			Point p = angle(a) * 20.0;
			if (i % 2 == 0)
				p *= 2.0;
			star.point(p);
		}
		star.close();
	}

	Bool render(Size size, Graphics to) {
		Moment now;
		Float time = (now - started) / 30 ms;

		to.fill(bgBrush);
		// to.transform(rotate(20 deg, Point(100, 100)));

		to.line(Point(0, 0), Point(100, 100), solid);
		to.draw(Rect(10, 10, 190, 190), solid);
		to.draw(Rect(20, 20, 180, 180), Size(50), solid);
		to.oval(Rect(40, 40, 100, 80), solid);

		to.push(Rect(0, 0, 120, 120), 0.5);
		to.transform(translate(Point(100, 100)));
		to.fill(star, starColor);

		to.push();
		to.transform(rotate(1 deg * time));
		to.fill(star, starColor);
		to.draw(text, textColor, Point() - (textSize / 2));

		to.pop();
		to.pop();

		to.transform(Transform());
		to.draw(image, Point(100, 100));

		true;
	}

}

void simple() {
	// SimpleWin win;
	DrawWin win;
	win.waitForClose();
	// sleep(2 s);
	// win.close();
	print("Bye!");
}