小编Tro*_*jan的帖子

随机颜色优先

想法:我正在尝试模拟一个商店系统.通过点击项目,用户表明他对这样的东西感兴趣,并在下次访问网站时更喜欢它.我想要实现类似的东西,只有没有东西可以买,但有颜色.你得到随机颜色.如果你喜欢'红色,你会得到随机的颜色,但比平时更红.

理论上到目前为止.实际上我用r,g和b制作了饼干,起始值为1.0.每次点击其中一种颜色时,该值上升+0.1,其他颜色下降-0.1.但是如何考虑这些数字呢?

到目前为止这是我的Javascript:

var r = getCookie("r");
var g = getCookie("g");
var b = getCookie("b");

if (r = ""){
    setCookie("r",1.0,365);
    setCookie("g",1.0,365);
    setCookie("b",1.0,365);
}
init();
function init(){


  var colorboxes =  document.getElementsByClassName("mycolorbox");

    [].forEach.call(colorboxes,function(entry){


        var sr = Math.round((Math.random() * (255 - 1) + 1));
        var sg = Math.round((Math.random() * (255 - 1) + 1));
        var sb = Math.round((Math.random() * (255 - 1) + 1));

       entry.style.backgroundColor = "rgba("+sr+","+sg+","+sb+",0.8)";
    });

}



$(document).click(function(event) {
    var clickedObj = $(event.target);

    if (clickedObj[0].className.indexOf("likebox") > -1) {

        clickedObj[0].style.Color = "red"; …
Run Code Online (Sandbox Code Playgroud)

javascript random rgb

6
推荐指数
1
解决办法
101
查看次数

在边缘的图像中放置文本

在此输入图像描述 我在Visual Basic 2010中编写的这个工具应该为图像添加作者文本.用户可以设置字体不透明度和位置.为了方便起见,我想要一些位置预设,如右下角所示.我正在使用的计算是(在这种情况下右下角:

 Dim textSize As Size = TextRenderer.MeasureText(tagString + curText, curFont)
 tmpPos = New Point(srcImg.Width - textSize.Width - 10, srcImg.Height - textSize.Height - 10)
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,这适用于此示例图片.一些文本只是剪辑出来的地方. 在此输入图像描述

第一个:1024x768 | 检测到的字体大小:680x72

第二名:1688x1125 | 检测到的字体大小:680x72

我怀疑这与图像的宽高比有关,但我不知道如何修复它.

文字是这样绘制的:

 brush = New SolidBrush(color.FromArgb(alpha, color))
        gr = Graphics.FromImage(editImg)
        gr.DrawString(tagString + text, font, brush, pos)
        HauptBild.Image = editImg
Run Code Online (Sandbox Code Playgroud)

我找到了这个http://www.codeproject.com/Articles/20923/Mouse-Position-over-Image-in-a-PictureBox,它回答了我的问题.

vb.net image composition aspect-ratio visual-studio-2010

6
推荐指数
1
解决办法
392
查看次数

用对象填充java数组

我必须在java中编写一个测验工具,我被卡住了.我只想创建一个问题并填写答案.答案应该在数组"antworten"中.

MainQuiz.java类:

import java.lang.*;
public class MainQuiz {

    public static void main(String args[]){

        QuizFrage qf = new QuizFrage ("Welche Lebensmittel sind gesund?" ,
                 new QuizAntwort ("Apfel" ,"A" , true),
                 new QuizAntwort ("Chips", "B", false),
                 new QuizAntwort ("Orange" , "C", true),
                 new QuizAntwort ("Schokolade" , "D", false));
                qf.FrageStellen();
    }
}
Run Code Online (Sandbox Code Playgroud)

QuizAntwort.java类:

public class QuizAntwort {
    protected String antwortxt;
    protected Boolean istrichtig;
    protected CharSequence antwortchr;



    public QuizAntwort(String string, String string2, boolean b) {
        // TODO Auto-generated constructor stub
    }




    public boolean checkAntwort(String …
Run Code Online (Sandbox Code Playgroud)

java arrays object

2
推荐指数
1
解决办法
217
查看次数

Vuex 命名空间存储设置两种状态

在我的项目中,我有一个相当复杂的 vuex 存储,它保存过滤器输入的值并将它们转换为我可以用来稍后查询后端的过滤器。我在两个不同的表旁边使用这些过滤器。如果我在 table1 中过滤 id = 123,我不希望 table2 中的过滤器为 id = 123。这就是我创建一个模块并尝试使用命名空间存储的原因。我的 vuex 商店 index.js 看起来像这样:

import myFilterModule from './filter.module';
    Vue.use(Vuex);
    export default new Vuex.Store({
      modules: {
        filter1: myFilterModule,
        filter2: myFilterModule,
      },
    });
Run Code Online (Sandbox Code Playgroud)

我的模块如下所示:

const state = {
  idFilter: null,
};
const actions = {};
const mutations = {
  [SET_ID_FILTER](state, id) {
    state.idFilter = id;
  },
};
const getters = {
  getFilter(state) {
    return state.idFilter;
  },
};
export default {
  namespaced: true,
  state: () => state,
  actions,
  mutations,
  getters, …
Run Code Online (Sandbox Code Playgroud)

namespaces store vue.js vuex

2
推荐指数
1
解决办法
1067
查看次数