«Sketch Pad» by eli.fieldsteel

on 27 Aug'11 09:17 in guiartpaintdrawingsketchdoodlecolorrgbenvironment

An environment in which the user can draw using the mouse.

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
//LET'S PAINT!
//select all and compile

var point, red, green, blue, win, view, colorTask;
var redChange, greenChange, blueChange;

//rate of change of each color component
//mess around with these values for fun
//zero results in no color change
redChange = 0.01;
greenChange = 0.015;
blueChange = 0.02;

//default starting RGB values
//these values can be changed as well
//maintain range of 0≤x≤1
red=0; green=0.33; blue=0.67;

//window creation
win = Window("FANCY ARTWORK", resizable:true, border:false);
win.fullScreen;
win.onClose = {
	if( 
		colorTask.isPlaying,
		{colorTask.stop},
		{}
	);
};

//userview creation
view = UserView(win, Window.screenBounds);
view.clearOnRefresh = false;
view.background = Color.white;

//any click sets point as current mouse location
//left-click does nothing special
//right-click clears palette
view.mouseDownAction = {
	|v, x, y, mod, butNum, clkCnt|
	point = [x,y];
	if(butNum == 1,
		{
			view.drawFunc_({nil});
			view.clearDrawing;
			view.refresh},{}
	);
};

//mouse drag redefines userview drawFunc
//Pen draws line from old point to current point
//then sets old point equal to current point
view.mouseMoveAction = {
	|v, x, y, mod|
	view.drawFunc = {
		Pen.strokeColor = Color.new(
			red.fold(0,1),
			green.fold(0,1),
			blue.fold(0,1)
		);
		Pen.width = 3;
		Pen.line(point.asPoint,x@y);
		point = [x,y];
		Pen.stroke;
		};
	win.refresh;
};

//RGB values wrap through range 0≤x<2
//and are folded into 0≤x≤1 via mouseMove function
//thus RGB values oscillate linearly, out of phase with
//one another, back and forth from 0 to 1
colorTask = Task({
	{
		red = (red + redChange)%2;
		green = (green + greenChange)%2;
		blue = (blue + blueChange)%2;
		0.05.wait; //arbitrary wait time
	}.loop;
});

//comment out for no color change
colorTask.start;

win.front;
raw 1899 chars (focus & ctrl+a+c to copy)
reception
comments
rukano user 31 Aug'11 10:58

MSPaint in less than 100 lines :)

vividsnow user 31 Aug'11 12:07

going to extend )

hamoid user 24 Apr'12 16:40

Great to see this is possible! One question though: is it normal that there is a large latency? The drawing takes between one and two seconds to appear. I'm on Ubuntu with a 24" monitor and a fast computer. Is maybe the high resolution making it slow? Thanks!

vividsnow user 28 Apr'12 12:10

what is your resolution? i have 1920x1200 and no latency at all

Fredrik Olofsson user 29 Apr'12 14:46

try to set QT_GRAPHICSSYSTEM=opengl and see if that makes it draw faster. here's a thread from the developer's list... https://www.listarc.bham.ac.uk/lists/sc-dev/msg33649.html

Abe Pazos user 02 May'12 12:55

Thanks. Also on 1920x1200. Tried setting QT_GRAPHICS... but then SuperCollider would not boot at all. Maybe it's my integrated Intel graphics... But I can run OPENGL tests and they just spin fine. No idea.