Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
anna-yang-generative [2021/06/22 20:36] – howard.lee | anna-yang-generative [2021/06/29 01:27] (current) – renick | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
+ | by [[yang-anna|Anna]] | ||
+ | < | ||
+ | <iframe src=" | ||
+ | </ | ||
+ | ===== about my crazyDog.js ===== | ||
+ | |||
+ | My dog has a pair of big round eyes and a strong body. | ||
+ | He hopes to be adopted. | ||
+ | Some people say he looks like a mouse but he is actually a Chihuahua. | ||
+ | |||
+ | The animation code is released under the [[https:// | ||
+ | |||
+ | ===== the code for my crazyDog.js ===== | ||
+ | |||
+ | < | ||
+ | |||
+ | // Where is the circle | ||
+ | let x, y; | ||
+ | |||
+ | function setup() { | ||
+ | createCanvas(1800, | ||
+ | // Starts in the middle | ||
+ | x = width / 2; | ||
+ | y = height; | ||
+ | } | ||
+ | |||
+ | class Dog { | ||
+ | constructor (size, | ||
+ | { this.dogSize = size; | ||
+ | this.dogColor = dColor; | ||
+ | this.positionx=x-150; | ||
+ | this.positiony=y-0; | ||
+ | } | ||
+ | draw () { | ||
+ | fill(random(0, | ||
+ | rect(240+this.positionx, | ||
+ | // leg | ||
+ | fill(random(0, | ||
+ | ellipse(300+this.positionx, | ||
+ | // tail | ||
+ | fill(random(0, | ||
+ | rect(155+this.positionx, | ||
+ | // leg | ||
+ | fill(random(0, | ||
+ | rect(144+this.positionx, | ||
+ | // body | ||
+ | fill(random(0, | ||
+ | rect(165+this.positionx, | ||
+ | // leg | ||
+ | fill(random(0, | ||
+ | rect(250+this.positionx, | ||
+ | // leg | ||
+ | ellipseMode(RADIUS); | ||
+ | fill(random(0, | ||
+ | ellipse(100+this.positionx, | ||
+ | ellipseMode(CENTER); | ||
+ | fill(random(0, | ||
+ | ellipse(100+this.positionx, | ||
+ | |||
+ | ellipseMode(RADIUS); | ||
+ | fill(random(0, | ||
+ | ellipse(200+this.positionx, | ||
+ | ellipseMode(CENTER); | ||
+ | fill(random(0, | ||
+ | ellipse(200+this.positionx, | ||
+ | // ears | ||
+ | fill(random(0, | ||
+ | square(100+this.positionx, | ||
+ | // face | ||
+ | ellipseMode(RADIUS); | ||
+ | fill(random(0, | ||
+ | ellipse(175+this.positionx, | ||
+ | ellipseMode(CENTER); | ||
+ | fill(random(0, | ||
+ | ellipse(175+this.positionx, | ||
+ | |||
+ | ellipseMode(RADIUS); | ||
+ | fill(random(0, | ||
+ | ellipse(125+this.positionx, | ||
+ | ellipseMode(CENTER); | ||
+ | fill(random(0, | ||
+ | ellipse(125+this.positionx, | ||
+ | // eyes | ||
+ | fill(random(0, | ||
+ | circle(152.5+this.positionx, | ||
+ | // month | ||
+ | }} | ||
+ | |||
+ | class BackgroundPattern { | ||
+ | constructor (size, Color,x,y) | ||
+ | { this.backgroundSize = size; | ||
+ | this.backgroundColor = Color; | ||
+ | this.positiony=y-0; | ||
+ | this.positionx=x-150; | ||
+ | } | ||
+ | draw () { | ||
+ | ellipseMode(RADIUS); | ||
+ | fill(random(0, | ||
+ | ellipse(200+this.positionx, | ||
+ | ellipseMode(CENTER); | ||
+ | fill(random(0, | ||
+ | ellipse(200+this.positionx, | ||
+ | textSize(32); | ||
+ | fill(random(0, | ||
+ | text(' | ||
+ | fill(random(0, | ||
+ | text(' | ||
+ | fill(random(0, | ||
+ | text(' | ||
+ | }} | ||
+ | |||
+ | function dogArray (n, x, y) { | ||
+ | let outputArray = []; | ||
+ | for (let i = 0; i < n ; i++) { | ||
+ | outputArray.push(new Dog (100," | ||
+ | } | ||
+ | return outputArray | ||
+ | } | ||
+ | |||
+ | function backgroundPatternArray (number, | ||
+ | let outputArray = []; | ||
+ | for (let i = 0; i < number ; i++) { | ||
+ | outputArray.push(new BackgroundPattern (500," | ||
+ | } | ||
+ | return outputArray | ||
+ | } | ||
+ | |||
+ | function Dogs2 (startingX, startingY, numberOfArrays, | ||
+ | for(let i = 0; i < numberOfArrays ; i++){ | ||
+ | let myDogs = dogArray (arrayLength, | ||
+ | for(let i = 0; i < myDogs.length ; i++){ | ||
+ | myDogs[i].draw() | ||
+ | }}} | ||
+ | |||
+ | function Background2 (startingX, startingY, numberOfArrays, | ||
+ | for(let i = 0; i < numberOfArrays ; i++){ | ||
+ | let myBackground = backgroundPatternArray (arrayLength, | ||
+ | for(let i = 0; i < myBackground.length ; i++){ | ||
+ | myBackground[i].draw() | ||
+ | }}} | ||
+ | |||
+ | function draw() { | ||
+ | background(220); | ||
+ | //let back2 = new BackgroundPattern (100," | ||
+ | // | ||
+ | //let back1 = new BackgroundPattern (100, " | ||
+ | // | ||
+ | //let dog2 = new Dog (100, " | ||
+ | // | ||
+ | //let dog1 = new Dog (100, " | ||
+ | // | ||
+ | |||
+ | //let dog2 = new Dog (200,100, " | ||
+ | // | ||
+ | |||
+ | Background2 (100, 0, 5, 5) | ||
+ | Dogs2 (100, 0, 5, 5); | ||
+ | | ||
+ | // Draw a circle | ||
+ | stroke(50); | ||
+ | fill(100); | ||
+ | ellipse(x, y, 24, 24); | ||
+ | | ||
+ | // Jiggling randomly on the horizontal axis | ||
+ | x = x + random(-1, 1); | ||
+ | // Moving up at a constant speed | ||
+ | y = y - 1; | ||
+ | | ||
+ | // Reset to the bottom | ||
+ | if (y < 0) { | ||
+ | y = height; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ |