Professional Documents
Culture Documents
TScript Text
TScript Text
turtle.color(1,0,0);
turtle.move(50);
turtle.turn(90);
turtle.color(1,0.5,0);
turtle.move(50);
turtle.turn(90);
turtle.color(0,1,0);
turtle.move(50);
turtle.turn(90);
turtle.color(0,0,1);
turtle.move(50);
turtle.turn(90);
Variables:
var points=100;
var animal;
animal=“dog“;
For-Loops:
For var i in 0:11 do
{
var cell= 100 + 10*i;
canvas.line(cell, 100, cell, 200);
canvas.line(100, cell, 200, cell);
}
Conditions in Programming:
var s = prompt (“Please enter some text!“);
if s != null then print(s);
Loops with Conditions:
Task1:
var i = 1;
while (i^2 < 1000) do
{
print(i^2);
i += 1;
}
Task 2:
while true do
{
var e = prompt (“Please enter something!“);
if e == null then continue;
print(e);
break;
}
Task 3:
var i = 5;
while i < 10 do
{
print (i);
i += 1;
}
Functions:
Task 1:
function cube(x)
{
return x^3;
}
Task 2:
function bug(x, y)
{
canvas.setLineColor(0.3, 0.2, 0.1);
canvas.line(x-15, y, x+15, y);
canvas.line(x-14, y-8, x+14, y+8);
canvas.line(x-14, y+8, x+14, y-8);
canvas.setFillColor(0.5, 0.4, 0.3);
canvas.fillCircle(x, y, 10);
canvas.fillCircle(x, y-10, 7);
}
Task 3:
function bug(x, y, angle=0, body_r=0.5, body_g=0.4, body_b=0.3, leg_r=0.3, leg_g=0.2,
leg_b=0.1)
{
canvas.shift(x, y);
canvas.rotate(angle);
canvas.setLineColor(leg_r, leg_g, leg_b);
canvas.line(-15, 0, 15, 0);
canvas.line(-14, -8, 14, 8);
canvas.line(-14, 8, 14, -8);
canvas.setFillColor(body_r, body_g, body_b);
canvas.fillCircle(0, 0, 10);
canvas.fillCircle(0, -10, 7);
canvas.rotate(-angle);
canvas.shift(-x, -y);
}
Dictionaries:
function histogram(array)
{
var zeichenkette = {};
for var schluessel in array do
{
if zeichenkette.has(schluessel)
then zeichenkette[schluessel] += 1;
else zeichenkette[schluessel] = 1;
}
return zeichenkette;
}