1. Linux中常用的命令都是哪些单词的缩写?
知乎回答:
https://www.zhihu.com/question/49073893
其中一个回答(开源漫游指南):
https://i.linuxtoy.org/docs/guide/ch02s02.html
2. 用javascript画出不同颜色的字~
var Fanimals = ["Rabbit", "Cat", "Dog", "Snake", "Monkey"]; var count = 0; while(count < Fanimals.length){ fill(250, 200-count*30, 0); //change the colors text(Fanimals[count], 10, (count+1)*15); //change the text and the location count++; } text("My "+Fanimals.length+" Favorite Animals!!", 10, 100);
Results:
之前没接触过,觉得很可爱呀!
还能随手点出星星(不过这里的"space/star"离开这里应该就没有了):
var xPositions = [100, 300]; var yPositions = [200, 50]; var drawStars = function() { background(9, 5, 59); imageMode(CENTER); for (var i = 0; i < yPositions.length; i++) { image(getImage("space/star"), xPositions[i], yPositions[i], 30, 30); } }; mouseClicked = function(){ xPositions.push(mouseX); yPositions.push(mouseY); drawStars(); };
还可以下雪:
var xPositions = [200]; var yPositions = [0]; for(var num =0; num<25; num++){ xPositions.push(random(10, 350)); yPositions.push(random(0, 250)); } draw = function() { background(204, 247, 255); stroke(235, 61, 235); for (var i = 0; i < xPositions.length; i++) { noStroke(); fill(250, 250-pow(-1, floor(i)%3)*10, 250); if(i%4 !== 0){ ellipse(xPositions[i], yPositions[i], 10, 10); } if(i%4 === 0){ image(getImage("avatars/leaf-orange"), xPositions[i]-10, yPositions[i], 20, 20); } //control the falling speed if(i%3 === 0) {yPositions[i] += random(2,3);} else{yPositions[i] += random(3,5);} //control the positions they restart if(yPositions[i]>400){ if(i%4 === 0){yPositions[i] = 0;} else{yPositions[i]=random(0, 50);} } } }; mouseClicked = function(){ xPositions.push(mouseX); yPositions.push(mouseY); draw(); }; mouseClicked();
附上丑图一张哈哈
做完排序(选择排序)任务之后还有个画图任务,不过对javascript不太熟,没想好怎么画比较好看,就画了个丑丑的,有空再修改!
线段是标记出元素换位的变化,每一行是每一步迭代的状态(在函数外部定义的变量是全局变量,在函数内部修改值也可以影响该变量的值):
var edgeL = 0; //for changing the leftest position var edgeU = 0; //for changing the uppest position var times = 0; //record the times plot was drawn var wid = 15; //control the distance var hei = 25; //control the distance var offset_wid = 5; // adjust the position of the lines var offset_hei_up = -20; var offset_hei_down = 2; var distance = 50; //the distance between blocks var displayArray = function(array) { textFont(createFont("monospace"), 30); }; var swap = function(array, firstIndex, secondIndex) { var temp = array[firstIndex]; array[firstIndex] = array[secondIndex]; array[secondIndex] = temp; }; var indexOfMinimum = function(array, startIndex) { var minValue = array[startIndex]; var minIndex = startIndex; for(var i = minIndex + 1; i < array.length; i++) { if(array[i] < minValue) { minIndex = i; minValue = array[i]; } } return minIndex; }; var selectionSort = function(array) { fill(237, 179, 176); rect(15+edgeL, 15+edgeU, wid*(array.length+1), hei*(array.length+1)); fill(240, 71, 53); var k =0; for(var i = 0; i < array.length; i++){ for(var j = 0; j < array.length; j++){ text(array[j], edgeL+25+wid*j, edgeU+45+hei*i); } k = indexOfMinimum(array, i); swap(array, k, i); stroke(105, 9, 24); if(i < array.length-1){ line(25+wid*k+offset_wid+edgeL, 45+hei*i+offset_hei_down+edgeU, 25+wid*i+offset_wid+edgeL, 45+hei*(i+1)+offset_hei_up+edgeU); } } times++; if(times%2 === 0) {edgeL = edgeL + distance+wid*array.length;} else {edgeU = edgeU + distance+hei*array.length;} }; fill(250, 200, 100); textSize(20); var array_1 = [3, 2, 1, 4, 6, 0]; array_1 = selectionSort(array_1); var array_2 = [1, 0, 4, 3, 7]; array_2 = selectionSort(array_2); var array_3 = [1, 2, 3, 1, 2, 3]; array_3 = selectionSort(array_3); var array_4 = [9, 9, 7, 0, 3, 1]; array_4 = selectionSort(array_4);