Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SuperCollider 3.6.5: Creates a 12-line text matrix in a 'Snellen' eye-chart configuration.
// SNELLEN by chadochan. 7/12/2015 Durham
// Creates a 12-line 'optotype' eyechart text matrix with text project, random text, and text clearing functions.
(
var font = "Rockwell";
var bold = true;
var backgroundcolor = Color.black;
var lettercolor = Color.grey(1);
var composite1, composite2, composite3, composite4, composite5, composite6, composite7, composite8, composite9, composite10, composite11, composite12;
var width = 290;
var horizontaloffset = 555;
var alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
var letterarray;
var scrambledLetterArray;
var letter1, letter2, letter3, letter4, letter5, letter6, letter7, letter8, letter9, letter10, letter11, letter12, letter13, letter14, letter15, letter16, letter17, letter18, letter19, letter20, letter21, letter22, letter23, letter24, letter25, letter26, letter27, letter28, letter29, letter30, letter31, letter32, letter33, letter34, letter35, letter36, letter37, letter38, letter39, letter40, letter41, letter42, letter43, letter44, letter45, letter46, letter47, letter48, letter49, letter50, letter51, letter52, letter53, letter54, letter55, letter56, letter57, letter58, letter59, letter60, letter61, letter62, letter63, letter64, letter65, letter66, letter67, letter68, letter69, letter70, letter71, letter72, letter73, letter74, letter75, letter76, letter77, letter78;
#letter1, letter2, letter3, letter4, letter5, letter6, letter7, letter8, letter9, letter10, letter11, letter12, letter13, letter14, letter15, letter16, letter17, letter18, letter19, letter20, letter21, letter22, letter23, letter24, letter25, letter26, letter27, letter28, letter29, letter30, letter31, letter32, letter33, letter34, letter35, letter36, letter37, letter38, letter39, letter40, letter41, letter42, letter43, letter44, letter45, letter46, letter47, letter48, letter49, letter50, letter51, letter52, letter53, letter54, letter55, letter56, letter57, letter58, letter59, letter60, letter61, letter62, letter63, letter64, letter65, letter66, letter67, letter68, letter69, letter70, letter71, letter72, letter73, letter74, letter75, letter76, letter77, letter78 = { StaticText().string_("") } ! 78;
letterarray = [ letter1, letter2, letter3, letter4, letter5, letter6, letter7, letter8, letter9, letter10, letter11, letter12, letter13, letter14, letter15, letter16, letter17, letter18, letter19, letter20, letter21, letter22, letter23, letter24, letter25, letter26, letter27, letter28, letter29, letter30, letter31, letter32, letter33, letter34, letter35, letter36, letter37, letter38, letter39, letter40, letter41, letter42, letter43, letter44, letter45, letter46, letter47, letter48, letter49, letter50, letter51, letter52, letter53, letter54, letter55, letter56, letter57, letter58, letter59, letter60, letter61, letter62, letter63, letter64, letter65, letter66, letter67, letter68, letter69, letter70, letter71, letter72, letter73, letter74, letter75, letter76, letter77, letter78];
letter1.stringColor_(lettercolor).font_(Font(font, 112, bold)).align_(\center);
2.do({ |item, i| letterarray[(1+i)].stringColor_(lettercolor).font_(Font(font, 84, bold)).align_(\center) });
3.do({ |item, i| letterarray[(3+i)].stringColor_(lettercolor).font_(Font(font, 56, bold)).align_(\center) });
4.do({ |item, i| letterarray[(6+i)].stringColor_(lettercolor).font_(Font(font, 42, bold)).align_(\center) });
5.do({ |item, i| letterarray[(10+i)].stringColor_(lettercolor).font_(Font(font, 32, bold)).align_(\center) });
6.do({ |item, i| letterarray[(15+i)].stringColor_(lettercolor).font_(Font(font, 26, bold)).align_(\center) });
7.do({ |item, i| letterarray[(21+i)].stringColor_(lettercolor).font_(Font(font, 22, bold)).align_(\center) });
8.do({ |item, i| letterarray[(28+i)].stringColor_(lettercolor).font_(Font(font, 19, bold)).align_(\center) });
9.do({ |item, i| letterarray[(36+i)].stringColor_(lettercolor).font_(Font(font, 16, bold)).align_(\center) });
10.do({ |item, i| letterarray[(45+i)].stringColor_(lettercolor).font_(Font(font, 14, bold)).align_(\center) });
11.do({ |item, i| letterarray[(55+i)].stringColor_(lettercolor).font_(Font(font, 11, bold)).align_(\center) });
12.do({ |item, i| letterarray[(66+i)].stringColor_(lettercolor).font_(Font(font, 9, bold)).align_(\center) });
scrambledLetterArray = letterarray.scramble;
// main window and composite views:
~window = QWindow(": :", Rect(15, 50, 1400, 788), border:false); // 16:9 aspect ratio
~window.view.background_(backgroundcolor);
~window.front;
~window.view.keyDownAction = { |v, char, mod, unicode, keycode, key |
if(keycode == 17, { ~letterSprinkle.reset.play });
if(keycode == 8, { ~clearAllLetters.reset.play });
//if(keycode == 1, { ~statement.reset.play });
//if(keycode == 15, { ~revstatement.reset.play });
};
CmdPeriod.doOnce({ ~window.close });
composite1 = QHLayoutView(~window, Rect(horizontaloffset, 46, width, 134)).layout_(
HLayout(letter1));
composite2 = QHLayoutView(~window, Rect(horizontaloffset, 173, width, 114)).layout_(
HLayout(letter2, letter3));
composite3 = QHLayoutView(~window, Rect(horizontaloffset, 270, width, 84)).layout_(
HLayout(letter4, letter5, letter6));
composite4 = QHLayoutView(~window, Rect(horizontaloffset, 350, width, 74)).layout_(
HLayout(letter7, letter8, letter9, letter10));
composite5 = QHLayoutView(~window, Rect(horizontaloffset, 415, width, 56)).layout_(
HLayout(letter11, letter12, letter13, letter14, letter15));
composite6 = QHLayoutView(~window, Rect(horizontaloffset, 466, width, 46)).layout_(
HLayout(letter16, letter17, letter18, letter19, letter20, letter21));
composite7 = QHLayoutView(~window, Rect(horizontaloffset, 507, width, 46)).layout_(
HLayout(letter22, letter23, letter24, letter25, letter26, letter27, letter28));
composite8 = QHLayoutView(~window, Rect(horizontaloffset, 550, width, 39)).layout_(
HLayout(letter29, letter30, letter31, letter32, letter33, letter34, letter35, letter36));
composite9 = QHLayoutView(~window, Rect(horizontaloffset, 588, width, 38)).layout_(
HLayout(letter37, letter38, letter39, letter40, letter41, letter42, letter43, letter44, letter45));
composite10 = QHLayoutView(~window, Rect(horizontaloffset, 622, width, 35)).layout_(
HLayout(letter46, letter47, letter48, letter49, letter50, letter51, letter52, letter53, letter54, letter55));
composite11 = QHLayoutView(~window, Rect(horizontaloffset, 660, width, 32)).layout_(
HLayout(letter56, letter57, letter58, letter59, letter60, letter61, letter62, letter63, letter64, letter65, letter66));
composite12 = QHLayoutView(~window, Rect(horizontaloffset, 690, width, 30)).layout_(
HLayout(letter67, letter68, letter69, letter70, letter71, letter72, letter73, letter74, letter75, letter76, letter77, letter78));
// letter functions:
~clearAllLetters = Routine({
scrambledLetterArray.do({ |item, i|
{ item.string_(""); item.stringColor_(Color.grey(1)) }.defer;
0.005.wait;
});
scrambledLetterArray = scrambledLetterArray.scramble
});
~letterSprinkle = Routine({
scrambledLetterArray.do({ |item, i|
{ item.stringColor_(Color.grey(1)); item.string_(alphabet[rand(26)]) }.defer;
0.005.wait;
});
scrambledLetterArray = scrambledLetterArray.scramble
});
~textinsert = { |text|
Routine.run({
var offset, alpha;
alpha = 0.2;
offset = 78 - text.size;
offset = rand(offset);
text.size.do({ |i|
{{ letterarray[(offset+i)].stringColor = Color.grey(alpha);
letterarray[(offset+i)].string = text[i] }.defer }.value;
0.007.wait;
})
})
};
~revtextinsert = { |text|
Routine.run({
var offset, textsize, startpoint, endpoint;
textsize = text.size;
offset = 78 - textsize;
startpoint = rand(offset);
endpoint = startpoint + textsize;
textsize.do({ |i|
{{ letterarray[(endpoint - i)].string = text[(textsize - 1) - i] }.defer }.value;
0.007.wait;
})
})
};
)
//~window.fullScreen;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment