Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| oliver-wang-generative [2021/06/20 18:35] – oliver.wang | oliver-wang-generative [2021/06/29 01:39] (current) – renick | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ========Oliver' | + | ========Oliver |
| + | by [[oliver-wang|Oliver]] | ||
| < | < | ||
| - | <iframe src=" | + | <iframe src=" |
| </ | </ | ||
| - | I think my dog code is very different with other, cause I want to have a good score of program dog, so I think a lot and type a lot of code. My dog is different with other is because they just use triangle, square, circle, and I use a code name is " | + | ===== about my crazyDog.js ===== |
| + | |||
| + | I think my dog code is very different with other, cause I want to have a good score of program dog, so I think a lot and type a lot of code. My dog is different with other is because they just use triangle, square, circle, and I use a code name is " | ||
| + | |||
| + | The animation code is released under the [[https:// | ||
| + | |||
| + | ===== the code for my crazyDog.js ===== | ||
| < | < | ||
| function setup() { | function setup() { | ||
| - | | + | createCanvas(1800, 780); |
| - | noLoop() | + | x = width; |
| + | y = height / 2; | ||
| } | } | ||
| + | |||
| class DogBackground{ | class DogBackground{ | ||
| constructor(y, | constructor(y, | ||
| Line 20: | Line 29: | ||
| let X = x; | let X = x; | ||
| let positionX = x; | let positionX = x; | ||
| - | let movingX = width/2 | + | let movingX = 100; |
| - | let movingY = height | + | let movingY = 100; |
| //sun | //sun | ||
| + | |||
| fill(' | fill(' | ||
| noStroke(0) | noStroke(0) | ||
| - | circle(movingX, movingY, 100) | + | circle(398, this.positionY-100, 100) |
| - | movingX = movingX + 1 | + | |
| - | movingY = movingY - 1 | + | |
| //sky | //sky | ||
| - | for(let i = 0; i < this.numberDog+10 ; i++){ | + | |
| + | | ||
| //grass | //grass | ||
| noStroke() | noStroke() | ||
| fill(103, 222, 103) | fill(103, 222, 103) | ||
| - | rect(positionX, | + | rect(positionX, |
| positionX += 200 | positionX += 200 | ||
| } | } | ||
| - | //tree | + | |
| - | for(let i = 0; i < | + | |
| + | for(let i =0; i < | ||
| x += 200 | x += 200 | ||
| fill(120, 74, 0) | fill(120, 74, 0) | ||
| Line 47: | Line 57: | ||
| x += 60 | x += 60 | ||
| } | } | ||
| + | |||
| for(let i = 0 ; i < this.numberDog+1; | for(let i = 0 ; i < this.numberDog+1; | ||
| + | |||
| fill(246, 98, 135) | fill(246, 98, 135) | ||
| circle(x-118, | circle(x-118, | ||
| Line 60: | Line 70: | ||
| x -= 290 | x -= 290 | ||
| }}} | }}} | ||
| + | |||
| class Dog { | class Dog { | ||
| constructor(x, | constructor(x, | ||
| Line 80: | Line 90: | ||
| rect(this.positionX+82, | rect(this.positionX+82, | ||
| rect(this.positionX+19, | rect(this.positionX+19, | ||
| + | |||
| //head | //head | ||
| rect(this.positionX+116, | rect(this.positionX+116, | ||
| //mouth | //mouth | ||
| rect(this.positionX+138, | rect(this.positionX+138, | ||
| + | |||
| stroke(1) | stroke(1) | ||
| noFill() | noFill() | ||
| Line 124: | Line 134: | ||
| fill(' | fill(' | ||
| //cloud | //cloud | ||
| - | ellipse(this.positionX, | + | ellipse(x+this.positionX, |
| - | rect(this.positionX-10, | + | rect(x+this.positionX-10, |
| - | rect(this.positionX-30, | + | rect(x+this.positionX-30, |
| - | ellipse(this.positionX*i, this.positionY-51, 50, 30) | + | ellipse(x+positionX+4, 49, 50, 30) |
| this.positionX = this.positionX + 200 | this.positionX = this.positionX + 200 | ||
| } | } | ||
| - | } | ||
| - | } | ||
| - | |||
| - | function backgroundArray (numberOfBackground){ | ||
| - | var dogBackgroundArray = []; | ||
| - | for(let i = 0; i < numberOfBackground; | ||
| - | dogBackgroundArray.push(new DogBackground(100, | ||
| - | } | ||
| - | return dogBackgroundArray | ||
| - | } | ||
| - | function randomArray (numberOfHi){ | ||
| - | var myColorArray = [] | ||
| - | for(let i = 0; i < numberOfHi; i++){ | ||
| - | myColorArray.push (Math.random()*255) | ||
| - | } | ||
| - | } | ||
| - | function pinkDogArray(numberOfDog){ | ||
| - | var DogsArray = [] | ||
| - | for(let i = 0; i < numberOfDog; | ||
| - | DogsArray.push(new Dog(0, 100, Math.random()*255, | ||
| - | } | ||
| - | return DogsArray | ||
| - | } | ||
| - | |||
| - | function cloudArray (n){ | ||
| - | var myCloudArray = [] | ||
| - | for(let i = 0; i < n; i++){ | ||
| - | myCloudArray.push(new Cloud(100, 100)) | ||
| - | } | ||
| - | return myCloudArray | ||
| - | } | ||
| - | let myCloudsArray = cloudArray(5) | ||
| - | console.log(myCloudsArray) | ||
| - | let myBackgroundArray = backgroundArray(5) | ||
| - | console.log(myBackgroundArray) | ||
| - | let myPinkDogArray = pinkDogArray(5) | ||
| - | console.log(myPinkDogArray) | ||
| - | |||
| - | function draw() { | ||
| - | background(163, | ||
| - | |||
| - | for(let i = 0; i < myCloudsArray.length; | ||
| - | myCloudsArray[i].draw() | ||
| - | } | ||
| - | |||
| - | for(let i = 0; i < myBackgroundArray.length; | ||
| - | myBackgroundArray[i].draw() | ||
| - | } | ||
| - | |||
| - | for(let i = 0; i < myPinkDogArray.length; | ||
| - | myPinkDogArray[i].draw() | ||
| } | } | ||
| } | } | ||
| </ | </ | ||