Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| steve-wang-generative [2021/06/20 17:58] – created steve.wang | steve-wang-generative [2021/08/18 00:47] (current) – scott.chen | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Steve' | + | ====== Steve Wang's crazyDog.js |
| + | Made by [[steve-wang|Steve]]. | ||
| < | < | ||
| - | <iframe src=" | + | <iframe src=" |
| </ | </ | ||
| + | |||
| + | ===== about my crazyDog.js ===== | ||
| + | |||
| + | I worked on this code for about a school term. I am also new to p5.js so it might not be that good. I think I have also improved in my programming skills. The first thing I made was the dog then the grenades, the clouds and the stars, and the sun. I think I have improved for every step of the way. However, it may not show because I went back to improve the older things I made. Overall, I think I did fine and I am very happy to have learnt programming. | ||
| + | |||
| + | The animation code is released under the [[https:// | ||
| + | |||
| + | ===== The code for my crazyDog.js ===== | ||
| + | |||
| + | < | ||
| + | let framen =40 | ||
| + | let flyn=0.6 | ||
| + | let mode =0 | ||
| + | |||
| + | function setup() { | ||
| + | | ||
| + | } | ||
| + | |||
| + | let starX=0 | ||
| + | let starY=0 | ||
| + | let starColor=255 | ||
| + | |||
| + | class Star { | ||
| + | constructor(starX, | ||
| + | this.starX=starX; | ||
| + | this.starY=starY | ||
| + | this.starColor=starColor | ||
| + | } | ||
| + | draw(){ | ||
| + | fill(color(this.starColor, | ||
| + | noStroke() | ||
| + | circle(28+this.starX, | ||
| + | triangle(18+this.starX, | ||
| + | triangle(18+this.starX, | ||
| + | triangle(18+this.starX, | ||
| + | triangle(38+this.starX, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | let Bigcloudx=0 | ||
| + | let Bigcloudy=0 | ||
| + | let Bigcloudcolor=0 | ||
| + | |||
| + | class BigCloud { | ||
| + | constructor(Bigcloudx, | ||
| + | this.Bigcloudx=Bigcloudx; | ||
| + | this.Bigcloudy=Bigcloudy; | ||
| + | this.Bigcloudcolor=Bigcloudcolor; | ||
| + | } | ||
| + | draw(){ | ||
| + | noStroke(); | ||
| + | | ||
| + | circle(160+this.Bigcloudx, | ||
| + | circle(235+this.Bigcloudx, | ||
| + | circle(300+this.Bigcloudx, | ||
| + | | ||
| + | | ||
| + | | ||
| + | }} | ||
| + | |||
| + | let FlatBottomCloudX =0 | ||
| + | let FlatBottomCloudY =0 | ||
| + | let FlatBottomCloudColor =0 | ||
| + | |||
| + | class FlatBottomCloud { | ||
| + | constructor(FlatBottomCloudX, | ||
| + | this.FlatBottomCloudX=FlatBottomCloudX; | ||
| + | this.FlatBottomCloudY=FlatBottomCloudY; | ||
| + | this.FlatBottomCloudColor=FlatBottomCloudColor; | ||
| + | } | ||
| + | draw() { | ||
| + | noStroke(); | ||
| + | | ||
| + | circle(160+this.FlatBottomCloudX, | ||
| + | circle(235+this.FlatBottomCloudX, | ||
| + | circle(300+this.FlatBottomCloudX, | ||
| + | | ||
| + | | ||
| + | circle(110+this.FlatBottomCloudX, | ||
| + | }} | ||
| + | |||
| + | let CloudsX=0 | ||
| + | let CloudsY=0 | ||
| + | let CloudsColor=0 | ||
| + | |||
| + | class Clouds { | ||
| + | constructor(CloudsX, | ||
| + | this.CloudsX=CloudsX; | ||
| + | this.CloudsY=CloudsY; | ||
| + | this.CloudsColor=CloudsColor; | ||
| + | } | ||
| + | draw() { | ||
| + | | ||
| + | | ||
| + | circle(140+this.CloudsX, | ||
| + | circle(205+this.CloudsX, | ||
| + | circle(270+this.CloudsX, | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | |||
| + | let GrenadesX=0 | ||
| + | let GrenadesY=0 | ||
| + | let GrenadesColors=0 | ||
| + | |||
| + | class Grenades { | ||
| + | constructor(GrenadesX, | ||
| + | this.GrenadesX=GrenadesX; | ||
| + | this.GrenadesY=GrenadesY; | ||
| + | this.GrenadesColors=GrenadesColors; | ||
| + | } | ||
| + | draw () { | ||
| + | // | ||
| + | rotate(-100 / 3.0) | ||
| + | | ||
| + | fill(" | ||
| + | rect(72.5+this.GrenadesX, | ||
| + | rect(73+this.GrenadesX, | ||
| + | | ||
| + | fill(this.GrenadesColors); | ||
| + | ellipse(80+this.GrenadesX, | ||
| + | line(60+this.GrenadesX, | ||
| + | | ||
| + | line(68+this.GrenadesX, | ||
| + | line(80+this.GrenadesX, | ||
| + | line(92+this.GrenadesX, | ||
| + | noFill(); | ||
| + | strokeWeight(1.5); | ||
| + | circle(75+this.GrenadesX, | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | |||
| + | class Dog { | ||
| + | constructor (x, | ||
| + | this.x=x; | ||
| + | this.y=y; | ||
| + | this.number=amount | ||
| + | this.sizes=sizes; | ||
| + | this.colors=colors; | ||
| + | this.i=i; | ||
| + | } | ||
| + | draw () { | ||
| + | let amountarray=[] | ||
| + | let number=0 | ||
| + | let options=0 | ||
| + | let w =0 | ||
| + | let g =0 | ||
| + | let h =0 | ||
| + | let b=0 | ||
| + | let k=0 | ||
| + | let kk=0 | ||
| + | translate(this.x, | ||
| + | rotate(100 / 3.0) | ||
| + | b=this.number+(5*this.i); | ||
| + | options=Math.floor(random(0, | ||
| + | if (options==1) {w=50; | ||
| + | else{w=20; | ||
| + | |||
| + | //legs | ||
| + | fill(this.colors) | ||
| + | rect(175, | ||
| + | | ||
| + | | ||
| + | rect(200, | ||
| + | //tail | ||
| + | g= this.sizes[b]+150 | ||
| + | |||
| + | let p1 = { x: g, y: 108 }; | ||
| + | let p2 = { x: 255, y: 108 }; | ||
| + | let p3 = { x: 255, y: 118}; | ||
| + | let p4 = { x: g, y: 118}; | ||
| + | curve(p1.x, p1.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); | ||
| + | stroke(0); | ||
| + | curve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y); | ||
| + | curve(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, p4.x, p4.y); | ||
| + | //Body | ||
| + | | ||
| + | //Face | ||
| + | |||
| + | circle(130, | ||
| + | //ears | ||
| + | ellipse(90, | ||
| + | ellipse(170, | ||
| + | //Eyes | ||
| + | circle(115, | ||
| + | | ||
| + | fill(" | ||
| + | circle(115, | ||
| + | | ||
| + | // | ||
| + | //Nose | ||
| + | fill(" | ||
| + | | ||
| + | //mouth | ||
| + | fill (" | ||
| + | rect(118, | ||
| + | drawteeth(); | ||
| + | function drawteeth () { | ||
| + | let toprow=Math.floor(random(1, | ||
| + | let bottomrow=Math.floor(random(1, | ||
| + | let toprowa=[]; | ||
| + | let bottomrowa= []; | ||
| + | for (let i = 0; i < toprow; i++) { | ||
| + | toprowa.push(Math.floor(random(0, | ||
| + | for (let i = 0; i < bottomrow; i++) { | ||
| + | bottomrowa.push(Math.floor(random(0, | ||
| + | for (let i = 0; i < toprow; i++) { | ||
| + | fill(" | ||
| + | if (toprowa[i]==0) {triangle(118+(i*4), | ||
| + | if (toprowa[i]==1) {triangle(118+(i*10), | ||
| + | } | ||
| + | for (let i = 0; i < bottomrow; i++) { | ||
| + | fill(" | ||
| + | if (bottomrowa[i]==0) { | ||
| + | triangle(114+(i*4), | ||
| + | if (bottomrowa[i]==1) { | ||
| + | triangle(114+(i*10), | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // | ||
| + | // | ||
| + | // | ||
| + | fill(this.colors) | ||
| + | |||
| + | } | ||
| + | } | ||
| + | |||
| + | function sizeArray (length) { | ||
| + | let newarray= [] | ||
| + | let amountarray=[] | ||
| + | for (let i = 0; i < length; i++) { | ||
| + | amountarray.push(0) | ||
| + | } | ||
| + | amountarray.forEach(sizeArray2) | ||
| + | return newarray | ||
| + | function sizeArray2 (x,i) { | ||
| + | newarray.push(1 + (Math.random() * 100)) | ||
| + | | ||
| + | }} | ||
| + | |||
| + | function loopedArray (n, fillItem) { | ||
| + | outputArray = []; | ||
| + | let a=0; | ||
| + | let amountarray=[] | ||
| + | for (let i = 0; i < n; i++) { | ||
| + | amountarray.push(0) | ||
| + | } | ||
| + | amountarray.forEach(loopedArray2) | ||
| + | function loopedArray2 (x,i) { | ||
| + | a=a+1; | ||
| + | if (i==0) {a=0} | ||
| + | if (a> | ||
| + | outputArray.push(fillItem[a]); | ||
| + | } | ||
| + | return outputArray | ||
| + | } | ||
| + | |||
| + | let originalnumbarray= [" | ||
| + | let colorarray= loopedArray(200, | ||
| + | let sizearray=(sizeArray(200)); | ||
| + | |||
| + | function dogObjectCreator (sizearray, | ||
| + | let doginfo=[] | ||
| + | |||
| + | for (let i = 0; i < 60; i++) { | ||
| + | dog = { | ||
| + | xq: | ||
| + | y:0, | ||
| + | //30+(20*i) | ||
| + | amount:100, | ||
| + | sizearray: | ||
| + | color: | ||
| + | }; | ||
| + | doginfo.push(dog) | ||
| + | } | ||
| + | return doginfo | ||
| + | } | ||
| + | |||
| + | let cloudarray= [] | ||
| + | let drawingarray = [] | ||
| + | let option2 = 2 | ||
| + | let mm=1500 | ||
| + | let option=0 | ||
| + | let counter2=0; | ||
| + | let counter3=0 | ||
| + | let b=0 | ||
| + | let DrawCloudX =0 | ||
| + | let DrawCloudY =[] | ||
| + | let cloudc =100 | ||
| + | let sunOut=[] | ||
| + | let rown=0 | ||
| + | let DrawCloudX2 =0 | ||
| + | let cSpeed=[] | ||
| + | let cSpeed2=[] | ||
| + | |||
| + | | ||
| + | | ||
| + | if (DrawCloudX> | ||
| + | if (option> | ||
| + | if (option==0){ let cloud= new Clouds (DrawCloudX+DrawCloudX*i, | ||
| + | cloud.draw(); | ||
| + | if (option==1) { let cloud= new BigCloud(DrawCloudX+DrawCloudX*i, | ||
| + | cloud.draw(); | ||
| + | if (option==2){ let cloud= new FlatBottomCloud (DrawCloudX+DrawCloudX*i, | ||
| + | cloud.draw(); | ||
| + | } | ||
| + | |||
| + | | ||
| + | | ||
| + | if (DrawCloudX2> | ||
| + | if (option> | ||
| + | if (option==0){ let cloud= new Clouds (DrawCloudX2+DrawCloudX2*i, | ||
| + | cloud.draw(); | ||
| + | if (option==1) { let cloud= new BigCloud(DrawCloudX2+DrawCloudX2*i, | ||
| + | cloud.draw(); | ||
| + | if (option==2){ let cloud= new FlatBottomCloud (DrawCloudX2+DrawCloudX2*i, | ||
| + | cloud.draw(); | ||
| + | } | ||
| + | |||
| + | let doginfoB=dogObjectCreator (sizearray, | ||
| + | let allDogObjects = doginfoB.map((x, | ||
| + | GrenadesY =10 | ||
| + | | ||
| + | function drawing (doginfo, | ||
| + | GrenadesY+= flyn | ||
| + | if (GrenadesY> | ||
| + | let grenade = new Grenades (doginfoB[x].xq, | ||
| + | grenade.draw(); | ||
| + | } | ||
| + | |||
| + | let xlevel=0 | ||
| + | let ylevel=780 | ||
| + | let sunOutput=0 | ||
| + | let greenb=50 | ||
| + | |||
| + | | ||
| + | | ||
| + | if (counter2< | ||
| + | xlevel+=9 | ||
| + | ylevel-=7 | ||
| + | | ||
| + | | ||
| + | | ||
| + | starArray.forEach((x, | ||
| + | if (counter2> | ||
| + | if (sunOutput==1) | ||
| + | | ||
| + | circle(xlevel, | ||
| + | if (sunOutput==1){return greenb} | ||
| + | if (sunOutput==2){return cloudc} | ||
| + | } | ||
| + | |||
| + | let starCounter=0 | ||
| + | let starXYarray=[] | ||
| + | let newStarX = Math.random()*1800; | ||
| + | let newStarX1 =Math.random()*1800; | ||
| + | let newStarX2 =Math.random()*1800; | ||
| + | let newStarX3 =Math.random()*1800; | ||
| + | let newStarY =Math.random()*500; | ||
| + | let newStarY1 =Math.random()*500; | ||
| + | let newStarY2 =Math.random()*500; | ||
| + | let newStarY3 =Math.random()*500; | ||
| + | |||
| + | |||
| + | function drawStar (x, | ||
| + | let star= new Star(newStarX, | ||
| + | star.draw(); | ||
| + | let star1= new Star(newStarX1, | ||
| + | star1.draw() | ||
| + | let star2= new Star(newStarX2, | ||
| + | star2.draw() ; | ||
| + | let star3= new Star(newStarX3, | ||
| + | star3.draw(); | ||
| + | } | ||
| + | let lengthofCInfo=0 | ||
| + | let makingCloudInfo=[] | ||
| + | |||
| + | function makeCloudInfo(lengthofCInfo){ | ||
| + | for (let c = 0; c < lengthofCInfo; | ||
| + | makingCloudInfo.push(random(0, | ||
| + | } | ||
| + | return makingCloudInfo} | ||
| + | |||
| + | let makingCloudSpeed=[] | ||
| + | |||
| + | function cloudSpeedCreator (lengthofCInfo){ | ||
| + | for (let c = 0; c < lengthofCInfo; | ||
| + | makingCloudSpeed.push(random(1, | ||
| + | } | ||
| + | return makingCloudSpeed} | ||
| + | |||
| + | let starArray=[]; | ||
| + | |||
| + | for (let v = 0; v < 20; v++) { | ||
| + | if(v==5){ starArray.push(1) | ||
| + | } | ||
| + | starArray.push(0) | ||
| + | } | ||
| + | |||
| + | for (let b = 0; b < 5; b++) { | ||
| + | cloudarray.push(0) | ||
| + | } | ||
| + | |||
| + | for (let i = 0; i < 50; i++) { | ||
| + | drawingarray.push(0) | ||
| + | } | ||
| + | |||
| + | let cloudInfo=[]; | ||
| + | let cloudInfo2 =[]; | ||
| + | let cloudSpeed =[] | ||
| + | let cloudSpeed2 =[] | ||
| + | |||
| + | |||
| + | function draw() { | ||
| + | background(color(52, | ||
| + | | ||
| + | | ||
| + | c1=Math.floor(random() * 3) | ||
| + | greenb=sun(1) | ||
| + | cloudc=sun(2) | ||
| + | cloudInfo=makeCloudInfo(cloudarray.length); | ||
| + | cloudInfo2=makeCloudInfo(cloudarray.length); | ||
| + | cloudSpeed=cloudSpeedCreator(cloudarray.length); | ||
| + | cloudSpeed2=cloudSpeedCreator(cloudarray.length); | ||
| + | |||
| + | |||
| + | cloudarray.forEach((x, | ||
| + | cloudarray.forEach((x, | ||
| + | |||
| + | if (greenb> | ||
| + | fill(" | ||
| + | rect(0, | ||
| + | |||
| + | | ||
| + | allDogObjects.forEach(x => x.draw()) | ||
| + | drawingarray.forEach((x, | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||