mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-27 21:49:13 +02:00
354 lines
13 KiB
Plaintext
354 lines
13 KiB
Plaintext
[
|
|
{"type":"Keyword","value":"import"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"LiteralStringSingle","value":"'dart:async'"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n"},
|
|
{"type":"Keyword","value":"import"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"LiteralStringSingle","value":"'dart:html'"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n"},
|
|
{"type":"Keyword","value":"import"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"LiteralStringSingle","value":"'dart:math'"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Keyword","value":"show"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"Random"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n\n"},
|
|
{"type":"CommentSingle","value":"// We changed 5 lines of code to make this sample nicer on\n// the web (so that the execution waits for animation frame,\n// the number gets updated in the DOM, and the program ends\n// after 500 iterations).\n"},
|
|
{"type":"Text","value":"\n"},
|
|
{"type":"Name","value":"main"},
|
|
{"type":"Punctuation","value":"()"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"KeywordDeclaration","value":"async"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"{"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Name","value":"print"},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"LiteralStringSingle","value":"'Compute π using the Monte Carlo method.'"},
|
|
{"type":"Punctuation","value":");"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"var"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"output"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"querySelector"},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"LiteralStringDouble","value":"\"#output\""},
|
|
{"type":"Punctuation","value":");"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"await"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Keyword","value":"for"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"KeywordDeclaration","value":"var"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"estimate"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Keyword","value":"in"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"computePi"},
|
|
{"type":"Punctuation","value":"()."},
|
|
{"type":"Name","value":"take"},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"LiteralNumber","value":"500"},
|
|
{"type":"Punctuation","value":"))"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"{"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Name","value":"print"},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"LiteralStringSingle","value":"'π ≅ "},
|
|
{"type":"LiteralStringInterpol","value":"$"},
|
|
{"type":"Name","value":"estimate"},
|
|
{"type":"LiteralStringSingle","value":"'"},
|
|
{"type":"Punctuation","value":");"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Name","value":"output"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"text"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"estimate"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"toStringAsFixed"},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"LiteralNumber","value":"5"},
|
|
{"type":"Punctuation","value":");"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"await"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"window"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"animationFrame"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Punctuation","value":"}"},
|
|
{"type":"Text","value":"\n"},
|
|
{"type":"Punctuation","value":"}"},
|
|
{"type":"Text","value":"\n\n"},
|
|
{"type":"CommentSingle","value":"/// Generates a stream of increasingly accurate estimates of π.\n"},
|
|
{"type":"Name","value":"Stream"},
|
|
{"type":"Operator","value":"\u003c"},
|
|
{"type":"KeywordType","value":"double"},
|
|
{"type":"Operator","value":"\u003e"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"computePi"},
|
|
{"type":"Punctuation","value":"({"},
|
|
{"type":"KeywordType","value":"int"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"NameLabel","value":"batch:"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"LiteralNumber","value":"100000"},
|
|
{"type":"Punctuation","value":"})"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"KeywordDeclaration","value":"async"},
|
|
{"type":"Operator","value":"*"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"{"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"var"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"total"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"LiteralNumber","value":"0"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"var"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"count"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"LiteralNumber","value":"0"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Keyword","value":"while"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"KeywordConstant","value":"true"},
|
|
{"type":"Punctuation","value":")"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"{"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"var"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"points"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"generateRandom"},
|
|
{"type":"Punctuation","value":"()."},
|
|
{"type":"Name","value":"take"},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"Name","value":"batch"},
|
|
{"type":"Punctuation","value":");"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"var"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"inside"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"points"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"where"},
|
|
{"type":"Punctuation","value":"(("},
|
|
{"type":"Name","value":"p"},
|
|
{"type":"Punctuation","value":")"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"=\u003e"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"p"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"isInsideUnitCircle"},
|
|
{"type":"Punctuation","value":");"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Name","value":"total"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"+="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"batch"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Name","value":"count"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"+="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"inside"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"length"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"var"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"ratio"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"count"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"/"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"total"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"CommentSingle","value":"// Area of a circle is A = π⋅r², therefore π = A/r².\n"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"CommentSingle","value":"// So, when given random points with x ∈ \u003c0,1\u003e,\n"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"CommentSingle","value":"// y ∈ \u003c0,1\u003e, the ratio of those inside a unit circle\n"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"CommentSingle","value":"// should approach π / 4. Therefore, the value of π\n"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"CommentSingle","value":"// should be:\n"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"KeywordDeclaration","value":"yield"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"ratio"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"*"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"LiteralNumber","value":"4"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Punctuation","value":"}"},
|
|
{"type":"Text","value":"\n"},
|
|
{"type":"Punctuation","value":"}"},
|
|
{"type":"Text","value":"\n\n"},
|
|
{"type":"Name","value":"Iterable"},
|
|
{"type":"Operator","value":"\u003c"},
|
|
{"type":"Name","value":"Point"},
|
|
{"type":"Operator","value":"\u003e"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"generateRandom"},
|
|
{"type":"Punctuation","value":"(["},
|
|
{"type":"KeywordType","value":"int"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"seed"},
|
|
{"type":"Punctuation","value":"])"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"KeywordDeclaration","value":"sync"},
|
|
{"type":"Operator","value":"*"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"{"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"final"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"random"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Keyword","value":"new"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"Random"},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"Name","value":"seed"},
|
|
{"type":"Punctuation","value":");"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Keyword","value":"while"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"KeywordConstant","value":"true"},
|
|
{"type":"Punctuation","value":")"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"{"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"yield"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Keyword","value":"new"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"Point"},
|
|
{"type":"Punctuation","value":"("},
|
|
{"type":"NameLabel","value":"x:"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"random"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"nextDouble"},
|
|
{"type":"Punctuation","value":"(),"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"NameLabel","value":"y:"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"random"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"nextDouble"},
|
|
{"type":"Punctuation","value":"());"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"Punctuation","value":"}"},
|
|
{"type":"Text","value":"\n"},
|
|
{"type":"Punctuation","value":"}"},
|
|
{"type":"Text","value":"\n\n"},
|
|
{"type":"KeywordDeclaration","value":"class"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"NameClass","value":"Point"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Punctuation","value":"{"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"final"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"KeywordType","value":"double"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"x"},
|
|
{"type":"Punctuation","value":","},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"y"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordDeclaration","value":"const"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"Point"},
|
|
{"type":"Punctuation","value":"({"},
|
|
{"type":"KeywordDeclaration","value":"required"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Keyword","value":"this"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"x"},
|
|
{"type":"Punctuation","value":","},
|
|
{"type":"Text","value":" "},
|
|
{"type":"KeywordDeclaration","value":"required"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Keyword","value":"this"},
|
|
{"type":"Punctuation","value":"."},
|
|
{"type":"Name","value":"y"},
|
|
{"type":"Punctuation","value":"});"},
|
|
{"type":"Text","value":"\n "},
|
|
{"type":"KeywordType","value":"bool"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"KeywordDeclaration","value":"get"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"isInsideUnitCircle"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"=\u003e"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"x"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"*"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"x"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"+"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"y"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"*"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Name","value":"y"},
|
|
{"type":"Text","value":" "},
|
|
{"type":"Operator","value":"\u003c="},
|
|
{"type":"Text","value":" "},
|
|
{"type":"LiteralNumber","value":"1"},
|
|
{"type":"Punctuation","value":";"},
|
|
{"type":"Text","value":"\n"},
|
|
{"type":"Punctuation","value":"}"}
|
|
]
|